← All tools · 한국어

Boids

No leader, no plan. Each bird looks at a few neighbours and follows three rules — and a flock appears. Your mouse is the hawk.

Three rules make a flock: don't crowd, fly the way your neighbours fly, drift toward the middle of them. Move your mouse — you're the hawk. Push cohesion to zero and the flock dissolves; push alignment to zero and it becomes a swarm. Click to drop a rock; the flock flows around it.

The three rules

  • Separation — steer away from birds that are too close.
  • Alignment — match the average heading of neighbours.
  • Cohesion — steer toward the average position of neighbours.

Set cohesion to 0 and the flock dissolves into pairs; set alignment to 0 and it becomes a bubbling swarm; set separation to 0 and they pile into a line. Reynolds published this in 1987; the same code animated the bats in Batman Returns.

Things to try

  • Be the hawk. Move the mouse into the flock: birds within about 150 px flee, and the flock splits and re-forms behind you — the same "flash expansion" real starlings do around a falcon.
  • Drop rocks. Click to place up to twelve; the flock flows around them like water around stones. Rocks near the middle make the most interesting rivers.
  • Change the sight. Small sight gives many little gangs; large sight makes one huge, slow-turning flock.
  • Crowd it. Push the bird count to 300 and watch lanes form.

Why so few rules are enough

No bird knows where the flock is going. Each one only looks at neighbours inside its sight radius and nudges its own heading a little. Studies of real starling flocks found something similar — each bird tracks roughly its six or seven nearest neighbours — which is why a flock of thousands can turn as one without a leader. Order from purely local rules is called emergence, and boids are the classic demonstration of it.

Questions

Why does it slow down with many birds? Every bird checks every other bird, so the work grows with the square of the count; 300 is the cap that stays smooth on phones.

Do the birds ever leave the screen? No. Near the edges they get a gentle push back inward, which is why the flock tends to circle.