Last active
August 29, 2016 03:51
-
-
Save traviskirton/d693bab4956b6ce8eb3f06f93d20a158 to your computer and use it in GitHub Desktop.
Bees + Bombs
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
class WorkSpace: CanvasController { | |
var circles = [Circle]() | |
var wedges = [Wedge]() | |
override func setup() { | |
let d = 160.0 //radius of circle | |
canvas.backgroundColor = white | |
let container = View(frame: Rect(0,0,d,d)) | |
container.center = canvas.center | |
canvas.add(container) | |
let points = [Point(), Point(d,0), Point(d,d), Point(0,d)] | |
for i in 0...3 { | |
let circle = Circle(center: points[i], radius: d/2.0 - 5.0) | |
circle.fillColor = black | |
circle.lineWidth = 0 | |
circles.append(circle) | |
container.add(circle) | |
let wedge = Wedge(center: circle.bounds.center, radius: d/2, start: M_PI_2 * Double(i), end: M_PI_2 * (1+Double(i))) | |
wedge.fillColor = white | |
wedge.lineWidth = 0.0 | |
wedges.append(wedge) | |
circle.add(wedge) | |
} | |
let mainSquare = View(frame: container.frame) | |
mainSquare.backgroundColor = white | |
mainSquare.hidden = true | |
canvas.add(mainSquare) | |
let Θ = M_PI | |
let containerRotateForward = ViewAnimation(duration: 1.25) { | |
for circle in self.circles { | |
circle.rotation += Θ * 2.0 | |
} | |
container.rotation += Θ / 2.0 | |
} | |
containerRotateForward.delay = 0.25 | |
containerRotateForward.curve = .EaseInOut | |
let containerRotateBackward = ViewAnimation(duration: 1.25) { | |
for circle in self.circles { | |
circle.rotation -= Θ * 2.0 | |
} | |
container.rotation -= Θ / 2.0 | |
mainSquare.rotation += Θ / 2.0 | |
} | |
containerRotateBackward.delay = 0.25 | |
containerRotateBackward.curve = .EaseInOut | |
containerRotateForward.addCompletionObserver { | |
mainSquare.hidden = false | |
for wedge in self.wedges { | |
wedge.hidden = true | |
} | |
containerRotateBackward.animate() | |
} | |
containerRotateBackward.addCompletionObserver { | |
mainSquare.hidden = true | |
for wedge in self.wedges { | |
wedge.hidden = false | |
} | |
containerRotateForward.animate() | |
} | |
containerRotateForward.animate() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment