Comp Sci A-Level • University ●●○ Intermediate ★ Free

Flocking (Boids)

Emergence in action. Complex group behavior arises from three simple rules: Separation, Alignment, and Cohesion.

Boids: 200
Visual Range:
Separation: 5
Alignment: 5
Cohesion: 5
Speed Limit: 4
Simulation running

Craig Reynolds’ Boids Algorithm (1987)

Craig Reynolds’ Boids Algorithm (1987)

Craig Reynolds discovered in 1987 that realistic flocking behaviour in birds, fish, and other social animals emerges from just three simple local rules, each agent following only what it can sense within its visual range — no central coordinator required:

  • Separation: steer away from nearby neighbours to avoid collision
  • Alignment: steer towards the average heading of nearby neighbours
  • Cohesion: steer towards the average position (centre of mass) of nearby neighbours

Reynolds called these simulated creatures “boids” (bird-oids). The paper, published at SIGGRAPH 1987, is one of the most cited in computer graphics and was the first formal model of self-organised collective motion.

The Mathematics of Flocking

Each boid updates its velocity vector each frame by combining three force components with adjustable weights:

  • Fsep = ∑j (posi − posj) / |posi − posj|² for all j within separation radius
  • Falign = mean(velj) for all j in alignment radius − veli
  • Fcohesion = mean(posj) for all j in cohesion radius − posi

The final velocity update is vnew = vold + wsFsep + waFalign + wcFcohesion, then clamped to maximum speed. Try adjusting the weights in real time to see how they affect flock behaviour.

Swarm Intelligence in Technology

The principles behind boids underpin entire fields of technology and science:

  • Drone swarms — military and commercial drone formations use boid-like coordination
  • Robotics — swarm robots for search-and-rescue, mapping unknown environments
  • Animation & VFX — Reynolds’ algorithm is standard in film and game crowd simulation
  • Ant colony optimisation — an AI metaheuristic modelled on ant foraging behaviour
  • Particle swarm optimisation — a flocking-inspired algorithm for numerical optimisation
  • Traffic modelling — collective vehicle behaviour modelled as continuous flocks

Experiments to Try

  • Maximise cohesion, minimise separation — the flock should merge into a tight cluster.
  • Maximise separation only — boids should scatter uniformly.
  • All three at medium values — observe classic murmuration-like behaviour.
  • Add many boids (200+) — observe the transition from small-group dynamics to large-flock emergent waves.
  • Narrow the visual field — simulate blind-spot biology; observe how flock cohesion degrades.

Key Equations

RuleVector UpdateNotes
SeparationFsep = ∑ (ri − rj) / |ri − rjSum over all neighbours j within separation radius
AlignmentFalign = ⟨vj⟩ − viSteer towards mean velocity of nearby neighbours
CohesionFcoh = ⟨rj⟩ − riSteer towards centre of mass of nearby neighbours
Velocity updatev′ = v + wsFsep + waFalign + wcFcohWeights w control relative strength of each rule
Speed clampingv = v × vmax / |v|Prevents unlimited acceleration; mimics biological limits
Order parameterφ = |∑ vj| / (Nvmax)φ = 0 (disorder) to 1 (perfect alignment); measures flock coherence

Curriculum Links

LevelTopics
GCSE BiologyAnimal behaviour, predator–prey dynamics, group living advantages
A-Level BiologyCollective behaviour, evolutionary advantages of flocking
A-Level ComputingAgent-based modelling, emergence, simulation design
University (Computer Science)Swarm intelligence, multi-agent systems, distributed AI
University (Physics)Statistical mechanics of active matter, non-equilibrium systems
PostgraduateActive matter physics, flocking phase transitions, Vicsek model

🔒 Unlock All 32 Simulations

Get unlimited access to all 32 interactive simulations including Flocking Boids, Evolution Simulator, Fluid Dynamics, Lorenz Attractor, and more with MySimulator Premium.

View Premium Plans

Share this simulation

Send this page to students or colleagues.

𝕏 Share πŸ”— LinkedIn πŸ“‹ Copy Link

Related simulations

Continue with similar experiments.

πŸ“– Recommended Reading

Deepen your understanding with our in-depth articles.