By · Updated

Boids Simulation

Watch Birds Flock in Your Browser

No ratings yet

Press Play to start

OneTask is free, with no sign-up, and built by one person.
If this tool saved you time, a coffee helps keep new ones coming.

How the Boids Simulation works

This boids simulation shows flocking from three simple rules. Press Play and a few hundred birds flock across the screen following three rules and nothing else. Slide the vision radius up and the flock tightens into one body; turn cohesion off and it scatters into pairs; push separation to zero and it collapses into a knot. Fullscreen makes it a screensaver, and Save PNG keeps a frame.

Boids simulation: what to know first

Boids is Craig Reynolds' 1986 model of flocking, and it remains the standard demonstration that complicated group behaviour does not need a leader or a plan. Each bird looks only at the neighbours within its vision radius and applies three steering rules: separation, which pushes it away from any neighbour that is too close; alignment, which nudges its heading toward the average heading of the group; and cohesion, which pulls it toward the centre of the group. Every bird runs the same tiny rulebook, and the flock is what those rules look like from a distance.

What the sliders do. Birds sets the flock size; the simulation is quadratic in bird count, so six hundred is the practical ceiling on an ordinary laptop. Speed is how far each bird moves per frame — the direction can change but the pace is constant, which is what keeps the motion looking like flight rather than a swarm of particles. Vision radius is how far a bird can see; a small radius gives many small flocks that ignore each other, a large one gives a single shoal. The three rule sliders scale how strongly each rule acts. The defaults are balanced; the interesting behaviour is at the extremes.

Things to try. Set alignment to zero and watch the flock stop flying anywhere in particular, milling as a cloud. Set cohesion to zero and alignment high and you get lines of birds streaming in parallel, like a migration. Turn separation to zero and birds pile onto the same point, which is what real birds avoid at all costs. Raise the speed with a small radius and the flock becomes a set of fast comets that occasionally merge.

Why it matters. The same three rules, or close variants, drive crowd simulation in films, schooling fish in games, and drone swarm control in robotics. It is also the standard first example of emergence — behaviour that belongs to the group and cannot be found in any member of it. Nobody tells the flock to turn; each bird only reacts to the birds beside it, and the turn propagates through the flock the way it does in a real starling murmuration.

How it is drawn. The canvas is redrawn every frame with each bird as a small triangle pointing along its velocity. The edges wrap, so a bird leaving the right side reappears on the left; this keeps the flock on screen without adding a fourth rule for walls. Fullscreen resizes the canvas to the display and the birds carry on in the larger space.

FAQ

Is this the original boids algorithm?

It is the three-rule model from Reynolds' paper, with the rules weighted by sliders rather than fixed. The original also limits each bird's field of view to a cone in front of it; this version uses a full circle, which flocks slightly more readily and is easier to reason about with a single radius slider.

Why does it slow down with many birds?

Every bird checks every other bird each frame, so doubling the count quadruples the work. Up to a few hundred is smooth on most machines; if the frame rate drops, reduce the count or the vision radius, since a smaller radius does not reduce the checks but does make the flock less coupled.

Can I make the birds avoid the mouse or obstacles?

Not in this version. The tool is deliberately the pure three-rule model so the sliders map directly onto the rules. Obstacle avoidance is usually added as a fourth rule that steers away from a point, and it changes the character of the flock quite a lot.

Does it run on a phone?

Yes, though with fewer birds. The canvas fills the width of the page and fullscreen works on Android; iOS Safari does not allow arbitrary elements to go fullscreen, so on an iPhone the button does nothing and the simulation stays in the page.

See also: all Simulations & Screensavers tools, Images, Audio, Video & Screen, PDF, SVG, Generative Art, Chart Makers, 3D Model Viewers, Drawing Pads, Mockups & 3D Making, Diagram Makers, 3D Science, Tracker Music.

Related tools