Chapter 05 · Emergence

No bird is
in charge.

Watch a starling murmuration and it looks choreographed — thousands of birds folding and swirling like one animal. There is no leader, no plan, no signal. Every bird follows three tiny rules about its neighbors — and the flock emerges. That's the whole trick, and you can build it in an afternoon.

press play — 90 seconds ↓
▶ watch rgbguy's original — Flock Simulation! Boids!
The lesson · a 90-second movie you can touch

Press play. It explains itself.

Plays like the video — one caption at a time, the picture animating under it — and it pauses when it's your turn. Skip around with the dots or arrow keys. The full lab comes after.

1.2
skip the lesson ↓
90 seconds · it pauses when it's your turn
Step 1 · The whole algorithm

One weighted sum

Craig Reynolds figured this out in 1986 and called his birds boids. Each boid looks at the neighbors it can see, feels three separate urges, and blends them. "Blend" here means exactly what it meant in chapter 02 — a weighted sum. Weighted averages, all the way down:

Combined Steering Force
F = wseparation·Fseparation  + walignment·Falignment  + wcohesion·Fcohesion
three forces, three sliders — that's the whole algorithm
Step 2 · The three rules

What one boid feels

In every demo below, the green boid is "you", the yellow circle is how far you can see, and the white triangles are the neighbors inside it. Each rule turns those neighbors into one force vector — nothing more.

1. Separation
Don't crowd me. Push away from anyone too close — harder the closer they are (that's the 1/d² doing personal-space math).
F_sep = −Σ (n−p)/d²
2. Alignment
Fly like everyone else. Average the neighbors' headings (dashed ghost arrow) and steer toward it.
F_align = avg(v_n) − v
3. Cohesion
Don't get left behind. Aim for the center of the neighbors — their centroid, marked +.
F_coh = centroid − p
Step 3 · The flock lab

140 boids, three sliders

Every frame, every boid finds its neighbors, computes the three forces, blends them with your weights, and moves. That's it — the schooling, the splitting, the swirling are not programmed anywhere. Click any boid to x-ray it: its perception circle, its neighbors, and its three live force vectors (red = separation, violet = alignment, yellow = cohesion).

click a boid to x-ray it

Weights

1.0
2.2
1.6

Flock

60
3.0

Presets

flock average
F = 1.0·sep + 2.2·align + 1.6·coh
neighbors:
w·|F_sep| =
w·|F_align| =
w·|F_coh| =
speed:
click a boid for its own numbers ↖
Step 4 · Spot it in the wild
where these three rules already run —
  • Movies. Finding Nemo's fish schools are exactly this algorithm; Reynolds' boids first hit the screen with the bat swarms in Batman Returns (1992). Nobody animated any individual fish.
  • Game crowds. Herds, zombie hordes, wingman squadrons, RTS unit clumping — most crowd movement is boids with a few extra forces (obstacle avoidance is just one more weighted term in the sum).
  • Drone light shows. Thousands of drones keeping spacing while flowing between shapes: separation keeps them from colliding, cohesion pulls them to their targets.
each boid computes alone, from what it sees, every frame — perfectly parallel. chapter 04 says hi 👋
See it in 3D · orbit it like Blender

The fish school, in real 3D

The video's underwater shots are this exact sim — the same three rules, running in a 3D volume. One fish is highlighted green with its perception bubble. Orbit through the school like a diver.

drag to orbit · scroll to zoom

Weights

1.2
1.0
F = w₁·sep + w₂·align + w₃·coh
same math as above — one extra axis
The source · rgbguy's original

Watch the video, jump by section

Click any moment on the right — it takes you straight there (in place when this site is served over http, on YouTube when opened as a local file).