From fb005ee63a1dae4d7f4218d6480a511d2cef6d73 Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Tue, 11 Mar 2014 19:22:16 +0100 Subject: [PATCH] Optimise WineGums example. --- examples/Animated/WineGums.html | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/examples/Animated/WineGums.html b/examples/Animated/WineGums.html index 82e82c18..e9619c81 100644 --- a/examples/Animated/WineGums.html +++ b/examples/Animated/WineGums.html @@ -30,7 +30,6 @@ this.boundOffsetBuff.push(this.radius); this.path.add(new Point()); } - this.path.add(new Point()); } @@ -51,20 +50,14 @@ } Ball.prototype.updateShape = function() { - var points = []; + var segments = this.path.segments; for (var i = 0; i < this.numSegment; i ++) { - points.push(this.point + { + segments[i].point = this.point + { angle: 360 / this.numSegment * i, length: this.boundOffset[i] - }); + }; } - for (var i = 0; i < this.path.segments.length; i ++) { - var next = points[(i + 1) % this.numSegment]; - var point = (points[i % this.numSegment] + next) / 2; - var vector = (next - point) / 4; - this.path.segments[i].point = point + vector; - } this.path.smooth(); for (var i = 0; i < this.numSegment; i ++) { if (this.boundOffset[i] < this.radius / 4) { @@ -128,8 +121,11 @@ var balls = []; var numBalls = 18; for (var i = 0; i < numBalls; i++) { - var position = Point.random() * view.size , - vector = (Point.random() - [0.5, 0]) * [5, 10], + var position = Point.random() * view.size, + vector = new Point({ + angle: 360 * Math.random(), + length: Math.random() * 10 + }), ball = new Ball(Math.random() * 60 + 60, position, vector); balls.push(ball); }