Realistic flocking simulation requires only three local rules: separation, alignment, cohesion
Craig Reynolds’ Boids algorithm (1987) proved that convincing flocking behavior emerges from each agent following just three local rules: (1) Separation — steer to avoid immediate neighbors; (2) Alignment — steer to match the average heading of nearby neighbors; (3) Cohesion — steer toward the average position of nearby neighbors. No agent knows the shape of the flock; each only reacts to a small local neighborhood. Yet the collective behavior produces complex formations indistinguishable from real starling murmurations. Additional rules (obstacle avoidance, predator escape) can be layered on without changing the core three. This is a foundational example of emergence in generative art.
Examples
Each boid per frame: find neighbors within radius R; compute separation vector (away from average neighbor position if too close); compute alignment vector (toward average neighbor velocity); compute cohesion vector (toward average neighbor position); sum weighted vectors for new heading.
Assessment
Implement the three Boids rules conceptually for a single agent given its position (100,150), velocity (2,-1), and one neighbor at (120,160) with velocity (1,2): compute the separation, alignment, and cohesion vectors qualitatively.