Optimise WineGums example.

This commit is contained in:
Jonathan Puckey 2014-03-11 19:22:16 +01:00
parent c5ee8ffb73
commit fb005ee63a

View file

@ -30,7 +30,6 @@
this.boundOffsetBuff.push(this.radius); this.boundOffsetBuff.push(this.radius);
this.path.add(new Point()); this.path.add(new Point());
} }
this.path.add(new Point());
} }
@ -51,20 +50,14 @@
} }
Ball.prototype.updateShape = function() { Ball.prototype.updateShape = function() {
var points = []; var segments = this.path.segments;
for (var i = 0; i < this.numSegment; i ++) { for (var i = 0; i < this.numSegment; i ++) {
points.push(this.point + { segments[i].point = this.point + {
angle: 360 / this.numSegment * i, angle: 360 / this.numSegment * i,
length: this.boundOffset[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(); this.path.smooth();
for (var i = 0; i < this.numSegment; i ++) { for (var i = 0; i < this.numSegment; i ++) {
if (this.boundOffset[i] < this.radius / 4) { if (this.boundOffset[i] < this.radius / 4) {
@ -128,8 +121,11 @@
var balls = []; var balls = [];
var numBalls = 18; var numBalls = 18;
for (var i = 0; i < numBalls; i++) { for (var i = 0; i < numBalls; i++) {
var position = Point.random() * view.size , var position = Point.random() * view.size,
vector = (Point.random() - [0.5, 0]) * [5, 10], vector = new Point({
angle: 360 * Math.random(),
length: Math.random() * 10
}),
ball = new Ball(Math.random() * 60 + 60, position, vector); ball = new Ball(Math.random() * 60 + 60, position, vector);
balls.push(ball); balls.push(ball);
} }