click anywhere to create a new boid

Boids

Boids are an artificial life simulation developed by Craig Reynolds in 1986 that models the flocking behavior of birds. The name "boid" is an abbreviation of "birdoid," meaning a simulated bird-like object.

Reynolds presented his work at SIGGRAPH 1987 in a paper titled Flocks, Herds, and Schools: A Distributed Behavioral Model. His key insight was that the complex, coordinated motion of a flock doesn't require a leader or global plan. Instead, each individual follows a small set of local rules, and the group behavior emerges on its own.

The Three Rules

Each boid in the simulation above follows three steering behaviors based only on the positions and velocities of its nearby neighbors:

  1. Cohesion. Steer towards the average position of your neighbors. This is what keeps the flock together. Without it, boids would scatter and drift apart.
  2. Alignment. Match your neighbors' average velocity. This is what gives the flock its coordinated direction. Nearby boids gradually synchronize their headings, producing the smooth, sweeping turns you see above.
  3. Separation. Steer away from neighbors that are too close. This prevents boids from colliding and bunching into a single point. In this implementation, the separation force is weighted twice as strongly as the other two rules.

Emergent Behavior

What makes boids fascinating is that no single rule produces flocking on its own. Cohesion alone would collapse the group into a clump. Alignment alone would send them marching in rigid formation. Separation alone would scatter them. It's the interplay of all three, each pulling in a slightly different direction, that produces the organic, lifelike motion of a flock.

This is a textbook example of emergence: complex global behavior arising from simple local interactions. No boid knows about the flock as a whole. Each one only perceives its immediate neighbors within a small radius. Yet the group spontaneously forms coherent structures, splits around obstacles, and recombines, all without any central coordination.

How It Works

On each frame, every boid considers its neighbors (those within a fixed distance) and computes a steering vector for each of the three rules. These vectors are combined into an acceleration that adjusts the boid's velocity, which is capped at a maximum speed. The resulting motion is smooth because steering forces are also capped at a small maximum value, preventing abrupt turns.

The simulation starts with 80 boids at the center of the canvas, each with a random initial direction. Click anywhere on the canvas above to add more and watch how they're absorbed into the flock.

Beyond Birds

The same principles apply far beyond bird flocking. Reynolds' model has been used to simulate schooling fish, swarming insects, herding animals, and crowd movement. It was famously used to animate the bat swarms in Batman Returns (1992) and the wildebeest stampede in The Lion King (1994). Variations of the algorithm appear in robotics (drone swarm coordination), video games (NPC group movement), and computational art.

The deeper lesson of boids is that you don't need complicated rules to produce complicated behavior. You just need the right simple rules, applied locally, at scale.

Originally published February 19, 2014