Lab · Experiment
Flocking
Simulations · Work in progress
Birds that only look at their neighbours still move as one flock.
Try this
Move your pointer over the canvas to chase the flock with a predator, then change the three rules and watch the behaviour shift.
Before you start
- Best with a mouse or trackpad; on a touch screen, drag to move the predator.
- With 400 birds, older phones may slow down: every bird checks every other bird each frame.

The idea, and what I learned
The question: can three local rules produce a global pattern? This is Craig Reynolds' boids model: each bird steers away from birds that are too close (separation), matches the heading of its neighbours (alignment) and drifts toward their centre (cohesion). Nobody leads.
What I learned: the balance between the rules is everything. High cohesion gives tight balls, high alignment long rivers, high separation a nervous cloud.
Still investigating: neighbours are found by checking every pair, which is fine for a few hundred birds but needs a spatial grid to scale further.
Walkthrough, without running it
- 160 birds start scattered across the canvas, heading in random directions.
- Within a few seconds, local groups line up and merge — no bird knows where the flock is, only where its neighbours are.
- Bring the pointer in and a red predator ring appears; birds within reach turn away, the flock splits around it and reforms behind.
- With alignment at zero, the birds stay together but go nowhere; with cohesion at zero, groups drift apart.
- The edges wrap around, so a flock leaving one side reappears on the other.