Fish Schooling Simulator: Collective Behavior & Boid Rules

simulator intermediate ~10 min
Loading simulation...
Coordinated school of 100 fish moving in loose formation

With balanced alignment and cohesion, 100 fish form a single coordinated school. The emergent collective behavior arises from each fish following just three simple rules: align with neighbors, move toward the group center, and avoid collisions.

Formula

Alignment: v_i += w_a × mean(v_neighbors)
Cohesion: v_i += w_c × (centroid - position_i)
Separation: v_i += w_s × Σ (position_i - position_j) / |distance_ij|²

Emergence in Motion

A fish school is a stunning example of emergence — complex, coordinated group behavior arising from simple individual rules with no central control. Each fish in a school of thousands follows only local information: the positions and velocities of its nearest neighbors. Yet the collective result is a shimmering, coherent entity that flows around obstacles, evades predators, and navigates across vast ocean distances. Understanding this self-organization connects marine biology to complexity science, physics, and robotics.

The Three Rules of Schooling

Craig Reynolds' 1986 'boids' model showed that three simple rules generate realistic flocking behavior. Alignment makes each fish steer toward the average heading of nearby neighbors. Cohesion pulls each fish toward the group center. Separation prevents collisions by repelling fish that get too close. This simulation implements these three rules with adjustable weights, letting you explore how their relative strength determines whether fish form tight, polarized schools or loose, milling swarms.

Why Schools Work: Predator Defense

The primary evolutionary driver of schooling is predator defense. The 'confusion effect' — demonstrated in laboratory experiments — shows that predator attack success drops dramatically against coordinated groups because the visual system struggles to track a single target among many identical, synchronized individuals. Combined with the 'many-eyes' effect (faster predator detection) and dilution (lower individual risk), schooling reduces per-capita predation mortality by 50-90% compared to solitary fish.

From Fish to Algorithms

Fish schooling has inspired optimization algorithms (particle swarm optimization), robotic swarm coordination, and crowd simulation in films and games. The mathematics of collective motion is closely related to phase transitions in physics — as alignment strength increases, the school undergoes a transition from disordered swarm to ordered polarized motion, analogous to the paramagnetic-to-ferromagnetic transition. The polarization output in this simulation measures this order parameter, letting you observe the phase transition as you adjust alignment weight.

FAQ

How do fish schools coordinate without a leader?

Fish schools are self-organized systems with no leader or central control. Each fish follows simple local rules: align your direction with nearby neighbors, move toward the group center, and avoid collisions. These three rules, first modeled by Craig Reynolds in 1986 as 'boids,' are sufficient to generate realistic schooling behavior. Information propagates through the group as waves, allowing rapid collective responses.

Why do fish school?

Fish school for several evolutionary advantages: (1) Confusion effect — predators struggle to single out one target from a coordinated group, (2) Many-eyes effect — more individuals means faster predator detection, (3) Dilution effect — each individual's probability of being eaten decreases, (4) Hydrodynamic advantage — fish in a school can save energy through draft-swimming, similar to cyclists in a peloton.

What is the difference between a school and a shoal?

A shoal is any social group of fish that stay together. A school is a specific type of shoal where fish are polarized — swimming in the same direction in a coordinated manner. Fish often alternate between schooling (when threatened or traveling) and shoaling (when feeding or resting). The polarization metric in this simulation measures this distinction: high polarization indicates schooling, low polarization indicates shoaling.

How fast can information travel through a school?

Startle responses propagate through fish schools at 5-10 times the speed that any individual fish can swim. This is because each fish reacts to its neighbor's turning motion before the threat reaches it, creating a wave of avoidance that moves faster than the predator. Large schools of herring can execute coordinated evasive maneuvers involving thousands of fish within milliseconds.

Sources

Embed

<iframe src="https://homo-deus.com/lab/marine-biology/fish-schooling/embed" width="100%" height="400" frameborder="0"></iframe>
View source on GitHub