Skip to content

Instantly share code, notes, and snippets.

@willrust
Created October 3, 2014 17:32
Show Gist options
  • Save willrust/af31fab87d82d12761ef to your computer and use it in GitHub Desktop.
Save willrust/af31fab87d82d12761ef to your computer and use it in GitHub Desktop.
Pizza Playground
import UIKit
import QuartzCore
let crustWidth:CGFloat = 25.0
let pepDiam:CGFloat = 25.0
let pepCount = 20
let pizza = UIView()
pizza.bounds = CGRect(x: 0, y: 0, width: 300, height: 300)
pizza.frame = CGRectMake(0, 0, 300, 300)
pizza.layoutIfNeeded()
let center = CGPoint (x: pizza.bounds.width/2, y: pizza.bounds.width/2)
let crustPath = UIBezierPath(ovalInRect: CGRectMake(
center.x-(pizza.bounds.width/2),
center.y-(pizza.bounds.height/2),
pizza.bounds.width,
pizza.bounds.height)
)
let crust = CAShapeLayer()
crust.path = crustPath.CGPath
crust.fillColor = UIColor(red: 0.91, green: 0.86, blue: 0.78, alpha: 1.0).CGColor
pizza.layer.addSublayer(crust)
let cheesePath = UIBezierPath(ovalInRect: CGRectMake(
center.x-((pizza.bounds.width-crustWidth)/2),
center.y-((pizza.bounds.height-crustWidth)/2),
pizza.bounds.width - crustWidth,
pizza.bounds.height - crustWidth)
)
let cheese = CAShapeLayer()
cheese.path = cheesePath.CGPath
cheese.fillColor = UIColor(red: 0.99, green: 0.95, blue: 0.85, alpha: 1.0).CGColor
pizza.layer.addSublayer(cheese)
func pepAtPoint(point: CGPoint) -> CAShapeLayer {
var pepPath = UIBezierPath(
arcCenter: point,
radius: CGFloat(12),
startAngle: CGFloat(-0.5 * M_PI),
endAngle: CGFloat(1.5 * M_PI),
clockwise: true
)
let pep = CAShapeLayer()
pep.path = pepPath.CGPath
pep.fillColor = UIColor(red: 0.65, green: 0.4, blue: 0.4, alpha: 1.0).CGColor;
return pep
}
let pep1 = pepAtPoint(CGPointMake(200, 200))
pizza.layer.addSublayer(pep1)
pizza
@nateklaiber
Copy link

🍕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment