Boids Flocking Simulator
Steer a flock of digital birds with Craig Reynolds' three rules: separation, alignment and cohesion. Tune each weight in real time, attract or repel the swarm with your cursor, and watch coordinated flight emerge from local decisions.
Mouse interaction
Hold the canvas to attract boids.
Craig Reynolds' three rules
In 1987 computer scientist Craig Reynolds modelled bird flocks with three local rules. Every bird (he called them bird-oids, or boids) looks only at neighbours within a small visual range and steers based on what they're doing. No leader, no central plan — yet the global pattern looks remarkably like a real flock or fish school.
- Separation: steer away from neighbours that are too close (avoid collisions).
- Alignment: steer toward the average heading of neighbours (match the herd).
- Cohesion: steer toward the average position of neighbours (stay together).
Each rule is just a small nudge to the velocity vector. Their sum and the limit on maximum speed produce all the swirling, splitting, regrouping behaviour you see in the canvas.
Tune one knob at a time
| Setting | Effect at extreme |
|---|---|
| Separation = 0 | Boids stack into single points. |
| Alignment = 0 | Every boid drifts on its own course. |
| Cohesion = 0 | No flock — boids ignore where the others are. |
| Visual range small | Many tiny flocks instead of one big one. |
| Visual range large | Globally synchronized motion, less chaotic. |
Why emergence matters
The boids algorithm is the textbook example of emergent behaviour: simple local rules producing complex global outcomes that no single agent "knows" about. It started as a graphics demo and is now used in crowd simulation for film, swarm robotics, traffic flow modelling, and decentralised network routing.
The lesson it teaches engineers is general: when central control is fragile, replace it with many copies of a tiny rule and let the system organise itself.
Things to try
- Attract the flock with the cursor and watch them orbit; switch to repel to scatter and re-form.
- Crank cohesion high and separation low — boids collapse into a black hole.
- Trail fade near 1% reveals long trajectory paths and the shape of any vortices forming.
- Push count to 400 for dense schools; drop to 20 to study individual decisions.