Last active
August 29, 2015 14:16
-
-
Save maxwellimpact/37d2673b41b0d0f1bbbf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Playground - noun: a place where people can play | |
import UIKit | |
import XCPlayground | |
class randomCirclesView: UIView { | |
override func drawRect(rect: CGRect) { | |
drawCircles() | |
} | |
func drawCircles(){ | |
for x in 1...100 { | |
let color = randomUIColor() | |
let circle = randomCircle(30...70) | |
// set the fill | |
color.setFill() | |
circle.fill() | |
var alpha:CGFloat = 0 | |
var white:CGFloat = 0 | |
// set the stroke from the alpha channel | |
color.getWhite(&white, alpha: &alpha) | |
UIColor(white: 1, alpha: alpha).setStroke() | |
circle.stroke() | |
} | |
} | |
func randomCircle(radiusRange: Range<Int>) -> UIBezierPath { | |
let pointx = CGFloat(arc4random_uniform(UInt32(self.frame.size.width))) | |
let pointy = CGFloat(arc4random_uniform(UInt32(self.frame.size.height))) | |
let circle = UIBezierPath( | |
arcCenter: CGPoint(x: pointx, y: pointy), | |
radius: CGFloat(arc4random_uniform(UInt32(radiusRange.endIndex - radiusRange.startIndex)) + radiusRange.startIndex), | |
startAngle: 0.0, | |
endAngle: CGFloat(2 * M_PI), | |
clockwise: false | |
) | |
return circle | |
} | |
func randomUIColor() -> UIColor { | |
let color = UIColor( | |
red: CGFloat(arc4random_uniform(255 - 100) + 100) / 255, | |
green: CGFloat(arc4random_uniform(255 - 100)) / 255, | |
blue: CGFloat(arc4random_uniform(255 - 100)) / 255, | |
alpha: CGFloat(arc4random_uniform(255 - 100)) / 255 | |
) | |
return color | |
} | |
} | |
let view = randomCirclesView() | |
view.frame = CGRectMake(0,0,500,500) | |
view.backgroundColor = UIColor.darkGrayColor() | |
XCPShowView("Main View", view) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment