Play n Tools

Free tools & games for everyone

Free · No sign-up · No accounts

Flocking & swarm lab

Watch a flock appear from three simple rules: separation, alignment and cohesion. Tune boids live and see order collapse with noise in the Vicsek model.

How to use

  1. Boids flock: the birds start in random directions. Each one only looks at the birds within its sight and follows three rules: keep a little space (separation), fly the same way as its neighbours (alignment) and move towards their middle (cohesion).
  2. Move the sliders while the flock flies, or pick a preset such as an insect swarm or a fish school. Press Pause and Step to watch one step at a time.
  3. The order line shows how much the birds agree on a direction: 1 means all fly the same way, near 0 means no common direction. The table counts the groups.
  4. Order and noise: the Vicsek model is even simpler: each particle copies the average heading of the particles near it, plus some random noise. Run one noise level, or press Scan to see order collapse as noise grows.
  5. The same seed always gives the same start and the same run.

Keyboard and touch

TabMove between tabs, sliders and buttons
Arrow keys on a sliderChange the value by one step (the flock reacts at once)
Enter in a boxRun the Vicsek model

Tips

  • Turn alignment down to 0 and the flock becomes a buzzing swarm: the birds stay together but stop agreeing on a direction.
  • With cohesion only, the birds fall into tight clumps; with separation only, they spread out evenly like people in a waiting room.
  • A short sight gives many small flocks; a long sight joins them into one.
  • In the Vicsek scan, order is high at low noise and drops towards about 0.1 (the level of chance for 300 particles) at high noise. Making the box smaller packs the particles closer, and order survives more noise.
  • The movement is set by the rules alone: there is no leader and no bird knows where the flock is going.

About this lab

Craig Reynolds showed in 1987 that three local steering rules are enough to make computer "boids" flock like birds; the idea is used in films and games and helps biologists think about starlings and fish. Here every bird adds three pulls to its velocity: towards the centre of the neighbours it can see (cohesion), towards their average velocity (alignment) and away from any closer than 14 pixels, more strongly the closer they are (separation). Speeds are kept between 40 % and 100 % of the top speed, and the field wraps round at the edges. All birds look first and then all move, so the order in which they are listed does not matter.

The Vicsek model (Tamás Vicsek and colleagues, 1995) is a physicist's version: particles move at a fixed speed and each step take the average heading of all particles within distance 1, plus a random turn of up to plus or minus half the noise. It shows a change from disorder to order, a phase transition, as the noise is lowered or the particles are packed closer. Both are teaching models with a seeded random number generator; real birds use more cues. Everything runs in your browser.

See you tomorrow!

A fresh daily puzzle every morning, and new tools added every month.

Browse every product