Sketch · 2026-05-25
Boids, three rules.
Two hundred boids live on a wrapping square. Each one looks at neighbours inside a small radius and steers by three weighted rules: stay apart, match heading, drift toward the local centre. No leader, no plan, no global view. Move the cursor through them and they part around it.
The three rules
Craig Reynolds described the model in 1987 in a paper called "Flocks, Herds and Schools: A Distributed Behavioral Model". Each boid considers only the boids inside its perception radius. Separation steers away from neighbours that are too close. Alignment steers toward the average heading of those neighbours. Cohesion steers toward their average position. Three local rules; the global shape of the flock is whatever falls out.
What changes when you slide
Drop separation to zero and the boids collapse into clumps that orbit their centre of mass. Drop alignment and the flock still forms, but every member chooses its own heading; the shape jitters. Drop cohesion and the boids ignore each other's position entirely — they end up in parallel lanes pointing in whatever direction the alignment rule has settled on. The useful range for each weight is roughly 0.5 to 2; outside that one rule swamps the others.
Implementation notes
Naive pairwise comparison at 200 boids costs forty thousand distance checks per frame, comfortable for the browser. The world wraps as a torus, so neighbour distance is the minimum across the eight image copies of each boid. Velocity is clamped to a maximum speed each step, which is what stops the forces from blowing up. The cursor acts as an extra repulsion centre with a larger radius than a single boid.