Last active
August 29, 2015 14:02
-
-
Save aug2uag/d2f6f07e8469afd153b8 to your computer and use it in GitHub Desktop.
Gingerbreadman fractal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// GingerBreadMan | |
// | |
// Created by Rex Fatahi on 6/22/14. | |
// Copyright (c) 2014 aug2uag. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
var xPos = 0; | |
var yPos = 0; | |
// starting position | |
var prevX = 100; | |
var prevY = 115; | |
// konstant | |
var ka = 21; | |
var kb = 3; | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
self.gingerbread() | |
} | |
func gingerbread() { | |
// points per starting position | |
for (var j = 0; j < 10000; j++) { | |
// here are the actual equations to generate next points | |
xPos = (ka * (1 + 2 * kb)) - prevY + abs(prevX - (ka * kb)) | |
yPos = prevX; | |
// random color generation | |
let randomNumR = arc4random_uniform(235) + 10; | |
let randomNumG = arc4random_uniform(235) + 10; | |
let randomNumB = arc4random_uniform(235) + 10; | |
let color = UIColor(red: Float(randomNumR)/255.0, green: Float(randomNumG)/255.0, blue: Float(randomNumB)/255.0, alpha: 1) | |
let rect = CGRectMake(Float(xPos), Float(yPos), 1.0, 1.0); | |
// set color 1 pixel box at position | |
let view : UIView = UIView(); | |
view.frame = rect; | |
view.backgroundColor = color; | |
self.view.addSubview(view); | |
// previous position is current position | |
prevX = xPos; | |
prevY = yPos; | |
} | |
// update current position | |
xPos = ( (ka*(1+2*kb)) - prevY + (abs(prevX - (kb*ka))) ); | |
yPos = prevX; | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment