Home▸Animals & Their World▸Flocking Lab (2D)

Flocking Lab (2D)

A 2D boids model: each agent follows three local rules — steer toward nearby flockmates, steer away from ones that are too close, and match their average heading — and coordinated flocking emerges with no leader and no global plan.

Animals & Their World2DModerate60 FPS📱 Mobile-adapted⇄ 3D version
2d-flocking-lab ↗ Open standalone

This 2D companion runs the same boids model as the 3D version on a flat canvas, which makes the underlying rules easier to read: every agent only looks at flockmates within its local vision radius, then blends three steering impulses — cohere toward their average position, separate from ones that get too close, and align its heading with their average velocity. Slide cohesion and alignment up and a scattered cloud of agents pulls into a single moving school within a few seconds; push separation up instead and the flock spreads out into a looser, more spaced formation.

⚙ Under the hood

Classic Reynolds boids: for each agent, cohesion steers toward the centroid of neighbours inside the vision radius, alignment steers toward their average velocity, and separation applies an inverse-square repulsion from neighbours inside a tighter radius. All three steering terms are summed, speed is clamped to a min/max range, and a soft margin force turns agents back from the canvas edges.

flockingboidsemergencecollective behaviorswarm dynamics

2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)