Flocking algorithm in JavaScript