Learning LabExplorable explanations
← All artifacts
Emergence

Boids: Flocking From Local Rules

No leader, no plan. Each boid watches only its nearby neighbors and obeys three steering rules. Dial separation, alignment, and cohesion and watch a flock cohere or fall apart.

boidsflockingemergenceagent-based
LiveInteractive · drag, toggle, run it
Emergence · Agent-Based Models

Boids: Flocking From Local Rules

A flock looks choreographed, yet nothing choreographs it. In Craig Reynolds' 1986 model every boid sees only its near neighbors and follows three steering rules. The global pattern below is genuinely emergent: it falls out of those local interactions alone, with no leader steering and no path laid down in advance.

Boids
boids
200
order param
0.000
alignment
disordered
avg speed
0.00
The three steering rules
1.5
Steer away from neighbors that crowd too close. Crank it up and the flock repels itself into open space.
1.0
Steer toward the average heading of neighbors. This is what lifts the order parameter toward 1.
1.0
Steer toward the average position of neighbors. Drop it to zero and the flock loses its center and disperses.
48 px
How far each boid can sense. The separation zone is a fraction of this. Wider perception couples more boids into one decision.
3.0
Caps how fast a boid travels. Steering forces are clamped too, so turns stay smooth rather than instant.
Reading the order parameter

The order parameter is the length of the mean unit velocity: phi = |Σ v̂i| / N. It is near 1 when every boid points the same way and near 0 when headings are random. Right now it reads 0.000 (disordered). Start from a fresh seed with alignment at zero and watch it sit low, then raise alignment and cohesion and watch it climb as a single flock takes shape.

Why a flock appears

Each boid runs the same local computation every frame: gather the neighbors inside its perception radius, then blend three steering vectors. Separation pushes away from anyone inside the tighter inner zone so bodies do not pile up. Alignment nudges its heading toward the average heading of those neighbors. Cohesion pulls it toward their average position. Each vector is normalized to the max speed, the correction is clamped to a small max force, and the result integrates into velocity and then position.

No boid can see the whole flock and none is in charge. The coherent group is a fixed point of thousands of these myopic decisions interacting: alignment lets a heading spread neighbor to neighbor until a region agrees, cohesion keeps the region from drifting apart, and separation keeps it from collapsing to a point. Click the field to drop a predator; the boids that sense it inside its radius flee, the disturbance ripples outward through purely local steering, and the flock re-forms once it passes. Click again to remove it.

Seeded with a mulberry32 PRNG so Reset reproduces the same start. After Craig W. Reynolds, "Flocks, Herds, and Schools" (1987).