git.iko.soy/metal-metaballs
on master help sign in
Added animating function.
commit519f4dc215aca42c83c59e82db27b9fa27b92fa3 authorvinivendra <vinivendra@gmail.com> dateFri 12 Feb 2016, 00:26 (11 years ago) parentf3f797d
1 file changed+25
PixelImage/ViewController.swift+25
PixelImage/ViewController.swift+25
@@ -43,6 +43,31 @@ class ViewController: UIViewController, MetaballDataSource {
4343 metaballView.addSubview(metaball)
4444 }
4545
46+ let parameters = EdgeAnimationParameters(startDate: NSDate(), duration: 3, fadeIn: true, i: 0, j: 2)
47+ NSTimer.scheduledTimerWithTimeInterval(1.0/60.0, target: self, selector: "animateEdgeWithTimer:", userInfo: parameters, repeats: true)
48+
49+ renderer.state = .Running
50+ }
51+
52+ func animateEdge(withTimer timer: NSTimer) {
53+ let (animationStart, duration, fadeIn, i, j) = (timer.userInfo as! EdgeAnimationParameters).unpack()
54+
55+ let now = NSDate()
56+ var timeElapsed = Float(now.timeIntervalSinceDate(animationStart))
57+
58+ if timeElapsed > duration {
59+ timer.invalidate()
60+ timeElapsed = duration
61+ }
62+
63+ let interpolee = timeElapsed / duration
64+ let interpolated = interpolee ^ 3
65+
66+ let newValue = fadeIn ? interpolated : (1 - interpolated)
67+
68+ metaballGraph.adjacencyMatrix.set(i, j, value: newValue)
69+ metaballGraph.adjacencyMatrix.set(j, i, value: newValue)
70+
4671 renderer.state = .Running
4772 }
4873