Clever Quest Lab ← Labs

Flocking Simulator

Every boid sees only its nearby neighbours; move the sliders, watch the Order figure rise or fall, and scare the flock with the pointer or block it with obstacles.

0Boids
0FPS
0%Order

Presets

Runs on your device. Nothing you type or record is uploaded. Keeps working without a connection while the page is open. Works with touch. Saves your settings and the flock with its obstacles on this device, so the simulation resumes where you left it.

Added

Steer the flock

The flock starts moving on its own. Pick a preset to see very different behaviour, then drag the sliders and watch what changes. Move your pointer across the canvas to scare the birds (or pull them towards you), and click or tap to drop round obstacles that they must steer around. Tap an obstacle again to remove it.

How the simulation works

Every bird, called a boid, follows the same three simple steering rules and looks only at its nearby neighbours. Nobody leads the flock and nobody sees the whole picture, yet a coordinated group emerges. Craig Reynolds published the model in 1987 as a way to animate flocks of birds in computer graphics.

Each rule produces a steering force. The forces are multiplied by your weights, added up and limited by a maximum force, so a boid turns smoothly instead of snapping around. Speed is capped between a small minimum and the maximum speed. A boid only counts neighbours inside its perception radius and inside its field of view, the angle it can see around its heading. Very close neighbours are always avoided, even behind the boid.

The Order figure shows how aligned the flock is. It is the length of the average of all boid direction vectors, as a percentage: 100% means everyone flies in exactly the same direction, and a value near 0% means headings are random. To keep 1,000 or more boids smooth, the world is split into a grid so each boid only checks the few cells around it instead of every other boid.

Controls

Things to try

Frequently asked questions

Is this how real birds flock?

It is a simplified model. Real flocks use more cues, but local rules like these reproduce the look of flocks, schools and herds surprisingly well.

Why do the boids never collide with obstacles?

They are steered away from obstacles, and the simulation also pushes any boid that touches an obstacle back to its edge, so none can pass through.

How many boids can my device handle?

Most desktop computers handle 1,000 boids comfortably. On a phone, try a few hundred. The FPS box shows the current frame rate, and lowering the count or perception radius speeds things up.

Why do boids reappear on the opposite side?

That is the wrap-around edge mode. The world behaves like the surface of a doughnut. Switch to soft bounce to make the edges gently turn the boids back.

Sources