Back to Portfolio

Boids Flocking Simulation

Emergent Flocking Behavior

Watch 900 boids create complex flocking patterns from three simple rules

Number of Boids 900
Total number of agents in the simulation
Separation Radius 20
Personal space distance to avoid crowding
Alignment Radius 30
Range to match velocity with neighbors
Cohesion Radius 20
Range to steer toward group center
Quadtree Capacity 3
Max points per quadtree node before subdivision
Trail Opacity 80
Higher values = shorter trails, lower = longer trails
Boid Speed 4
Maximum speed of individual boids
FPS: --

About This Simulation

This simulation recreates the flocking behavior of birds (murmurations) using an algorithm called "Boids," developed by Craig Reynolds in 1986. Despite the complexity of the patterns that emerge, each individual boid follows just three simple rules:

The Three Rules of Flocking

Quadtree Optimization

To efficiently handle 900+ boids, this simulation uses a quadtree data structure. Instead of checking every boid against every other boid (which would require hundreds of thousands of calculations per frame), the quadtree spatially organizes the boids into regions.

Each boid only checks for neighbors within its perception radius by querying the quadtree, dramatically reducing the computational load. You can toggle the quadtree visualization to see how the space is recursively subdivided.

Performance tip: The simulation runs at 60 FPS with 900 boids thanks to quadtree optimization. Without it, checking all pairs would require ~400,000 distance calculations per frame!

What This Demonstrates

This simulation embodies a key principle in complex systems: sophisticated collective behavior can emerge from simple individual rules. No boid has knowledge of the overall flock pattern, yet together they create the mesmerizing swirling formations we see in nature.

This same principle applies across nature—from ant colonies to neural networks to slime molds. Intelligence and coordination don't always require central control; they can arise from local interactions.