Created
February 7, 2016 20:54
-
-
Save drart/a80d7e9a65db68d9ec5f to your computer and use it in GitHub Desktop.
Simple animated circles. Checking out new C4 syntax.
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
| import UIKit | |
| class WorkSpace: C4CanvasController { | |
| var circles : [C4Circle]! | |
| var timer: C4Timer? | |
| var cwidth: Double = 0.0 | |
| var cheight: Double = 0.0 | |
| override func setup() { | |
| cwidth = self.canvas.width | |
| cheight = self.canvas.height | |
| circles = [C4Circle]() | |
| for var i = 0; i < 10; i++ | |
| { | |
| let x = random01() * canvas.width | |
| let y = random01() * canvas.height | |
| let p:C4Point = C4Point(x, y) | |
| let c = C4Circle(center:p, radius: 49) | |
| circles.append(c) | |
| } | |
| for circle in circles{ | |
| canvas.add(circle) | |
| } | |
| timer = C4Timer(interval: 5.0) { | |
| self.movecircle() | |
| } | |
| timer?.start() | |
| timer?.fire() | |
| } | |
| func movecircle(){ | |
| C4Log(circles[0].center.x) | |
| for circle in self.circles { | |
| let a = C4ViewAnimation(duration: 5.0) { | |
| let xx = random01() * self.cwidth | |
| let yy = random01() * self.cheight | |
| let p:C4Point = C4Point(xx, yy) | |
| circle.center = p | |
| } | |
| a.animate(); | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment