SimulatorEducationEntertainmentDeveloper

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.

Separation0.050
Alignment0.050
Cohesion0.0050
Visual range60px
Max speed3.5px/f
Trail fade10.0%
Boid count180

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

SettingEffect at extreme
Separation = 0Boids stack into single points.
Alignment = 0Every boid drifts on its own course.
Cohesion = 0No flock — boids ignore where the others are.
Visual range smallMany tiny flocks instead of one big one.
Visual range largeGlobally 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.