Skip to content

Instantly share code, notes, and snippets.

@traviskirton
Created August 29, 2016 08:42
Show Gist options
  • Save traviskirton/76000617a2a4a9f8f23fba6bfa5807b8 to your computer and use it in GitHub Desktop.
Save traviskirton/76000617a2a4a9f8f23fba6bfa5807b8 to your computer and use it in GitHub Desktop.
Bees + Bombs Mask
//
// WorkSpace.swift
// BeesBombs
//
// Created by travis on 2016-08-27.
// Copyright © 2016 C4. All rights reserved.
//
import UIKit
class WorkSpace: CanvasController {
var circles = [Wedge]()
var wedges = [Wedge]()
override func setup() {
let i = Image("chop")!
i.center = canvas.center
canvas.add(i)
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 = Wedge(center: points[i], radius:d/2-5, start: M_PI_2 * (1+Double(i)), end: M_PI_2*3 + M_PI_2 * (1+Double(i)))
circle.fillColor = black
circle.lineWidth = 0
circles.append(circle)
container.add(circle)
let wedge = Wedge(center: circle.bounds.center, radius: d/2-5, start: M_PI_2 * Double(i), end: M_PI_2 * (1+Double(i)))
wedge.fillColor = black
wedge.lineWidth = 0
wedge.hidden = true
wedges.append(wedge)
circle.add(wedge)
}
let mainSquare = View(frame: Rect(0,0,d+d+d,d+d+d))
mainSquare.backgroundColor = clear
mainSquare.border.width = d
mainSquare.border.color = C4Blue
mainSquare.center = container.bounds.center
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 += Θ
}
containerRotateBackward.delay = 0.25
containerRotateBackward.curve = .EaseInOut
containerRotateForward.addCompletionObserver {
container.mask = mainSquare
for wedge in self.wedges {
wedge.hidden = false
}
containerRotateBackward.animate()
}
containerRotateBackward.addCompletionObserver {
container.mask = nil
for wedge in self.wedges {
wedge.hidden = true
}
containerRotateForward.animate()
}
containerRotateForward.animate()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment