Boid Flocking Simulator: Emergent Collective Behavior from Simple Rules

simulator beginner ~8 min
Loading simulation...
Polarization = 0.82 — well-ordered flock

100 boids with balanced rules (S=1.5, A=1.0, C=1.0) self-organize into a coherent flock with polarization 0.82, exhibiting realistic splitting, merging, and turning dynamics.

Formula

v_sep = -Σ(x_j − x_i) / |x_j − x_i|² for neighbors within r_sep
v_align = (1/N)×Σv_j − v_i (match neighbor headings)
v_coh = (1/N)×Σx_j − x_i (steer toward center of mass)

Three Rules, Infinite Complexity

In 1986, Craig Reynolds demonstrated that the mesmerizing dynamics of bird flocks could emerge from just three local rules applied to each individual agent. Separation steers boids away from close neighbors to avoid collisions. Alignment adjusts heading to match nearby flock-mates. Cohesion pulls boids toward the local center of mass. No bird needs to know the flock's global shape or direction — the collective pattern self-organizes from purely local interactions.

Emergent Phenomena

Watch the simulation and you will see behaviors no individual rule produces alone: the flock executes sweeping coordinated turns, splits smoothly around obstacles and re-merges, forms elongated streams in narrow passages, and maintains stable density despite constant motion. These emergent phenomena arise from the nonlinear interaction of the three forces. Small parameter changes can trigger phase transitions between ordered flocking and disordered swarming.

The Perception Radius

Each boid only interacts with neighbors within its perception radius — typically 3–7 body lengths in real birds. This local interaction range determines flock structure. Small radii produce many small sub-flocks; large radii produce a single cohesive mega-flock. Research on starling murmurations shows they interact with a fixed number of nearest neighbors (6–7) rather than all birds within a distance, which produces scale-free correlations across the entire flock.

From Pixels to Robots

Reynolds' boid model was first used commercially in the 1992 film Batman Returns to animate swarms of bats and armies of penguins. Today, the same principles guide drone swarm coordination, autonomous vehicle platoons, and warehouse robot fleets. The key insight is that decentralized control is inherently robust: if one agent fails, the group adapts seamlessly. This simulation lets you experience firsthand how adjusting local rules reshapes global collective behavior.

FAQ

What are boids?

Boids (bird-oid objects) are simulated agents created by Craig Reynolds in 1986 to model flocking behavior. Each boid follows three simple rules: separation (avoid crowding neighbors), alignment (steer toward average heading of neighbors), and cohesion (steer toward average position of neighbors). No boid knows the global flock state; complex collective behavior emerges purely from local interactions.

How do three rules create realistic flocking?

Separation prevents collisions, alignment creates coordinated movement, and cohesion holds the group together. The interplay of these forces generates emergent phenomena: the flock splits around obstacles, merges after passing, executes coordinated turns, and maintains stable formations — all without any central coordinator or global communication.

What is flock polarization?

Polarization measures how aligned the flock's headings are. It is the magnitude of the average heading vector, ranging from 0 (random directions) to 1 (all boids moving in the same direction). High polarization indicates a coherent, well-ordered flock. Real bird flocks typically maintain polarization above 0.8.

Where are boid algorithms used?

Boid algorithms are used in film visual effects (the original application in Batman Returns, 1992), video game AI for crowd simulation, robotic swarm coordination, pedestrian flow modeling, and evacuation simulation. The algorithm demonstrates that complex group behavior need not require complex individual intelligence.

Sources

Embed

<iframe src="https://homo-deus.com/lab/swarm-intelligence/boid-flocking/embed" width="100%" height="400" frameborder="0"></iframe>
View source on GitHub