This is Craig Reynolds' Flocking simulation algorithm, implemented with JavaScript. The simulated objects (boids) have three property
- Separation: Each boids attempts to maintain a resonable amount of distance between itself and any nearby boids to prevent overcrowding.
- Allignment: Boids try to change their position so that it corresponds with the average alignment of other nearby boids.
- Cohesion: Every boid attempts to move towards the average position of other nearby boids.
The algorithm is further optimized using the **Quad Tree** data structure.
At each iteration the boids are inserted into the quadtree and each boid get to know about their neighbor using the quadtree in O(log(n)) time.
To see the simulation Click here.