Fix tadpoles example.

This commit is contained in:
Jonathan Puckey 2013-03-11 00:14:16 +01:00
parent 03d98ecc09
commit b60080d8e9

View file

@ -15,7 +15,7 @@
this.acceleration = new Point();
this.vector = Point.random() * 2 - 1;
this.position = position.clone();
this.radius = 50;
this.radius = 30;
this.maxSpeed = maxSpeed + strength;
this.maxForce = maxForce + strength;
this.points = [];
@ -131,10 +131,15 @@
var size = view.size;
if (position.x < -radius) vector.x = size.width + radius;
if (position.y < -radius) vector.y = size.height + radius;
if (position.x > size.width + radius) vector.x = -radius;
if (position.y > size.height + radius) vector.y = -radius;
if (!vector.isZero())
if (position.x > size.width + radius) vector.x = -size.width -radius;
if (position.y > size.height + radius) vector.y = -size.height -radius;
if (!vector.isZero()) {
this.position += vector;
var points = this.points;
for (var i = 0, l = points.length; i < l; i++) {
points[i] += vector;
}
}
},
// A method that calculates a steering vector towards a target