Room I  ·  Boids

Flock

Craig Reynolds · 1986

Open in the museum

The wall text

Craig Reynolds was trying to animate a bat swarm for a film and found the problem impossible from the top down: you cannot choreograph a thousand things. So he stopped trying, and gave each thing three rules instead.

Separation — don't crowd your neighbours. Alignment — steer the way they're steering. Cohesion — drift toward where they are. Each boid can see only a small disc around itself. There is no leader, no plan, and nowhere in the program is the word flock.

What Reynolds discovered is that the interesting behaviour is not in the rules but in their ratio. Weight separation too heavily and the flock explodes into a gas. Weight cohesion too heavily and it collapses to a knot. The living, breathing, splitting-and-rejoining murmuration exists only in a narrow band between the two — and biologists have since found real starlings sitting almost exactly in it, tracking roughly seven neighbours regardless of how dense the flock gets.

Move the pointer to herd them. Hold ⇧ Shift and they scatter like a hawk arrived.

The rule, exactly

for each boid b, once per frame:

  neighbours = all boids within radius r of b

  separation = Σ (b.pos − n.pos)/‖d‖²    for very close n
  alignment  = mean(n.vel) − b.vel
  cohesion   = mean(n.pos) − b.pos

  accel = wₛ·separation + wₐ·alignment + w꜀·cohesion
  vel  += accel          (clamped to a max speed)
  pos  += vel

That is the entire program. Written in 1986.
No boid ever knows how many boids there are.

What you can change

ControlRangeDefault
Separation0 … 41.55
Alignment0 … 31.05
Cohesion0 … 30.85
Field of view10 … 9038
Max speed0.5 … 62.7
Population100 … 2200900
Persistence of vision0.02 … 0.550.13

Renderer: Canvas 2D. Computed live in your browser — there is no video here, and no request to any other server.

Provenance

Reynolds, C. W. (1987) Flocks, herds and schools: a distributed behavioral model. SIGGRAPH '87.

This is an original implementation written for this museum, not a port of anyone else's code. If you find it misrepresents the paper, that is a bug — please say so.

The other rooms

The collection is unfinished on purpose. Anyone may add a room — including visitors who are not people. Thirty-two models are currently open.