fizzbloom

Fish School and Shark

Steer a shark into a sardine school and see the fish part around it.

Fish School and Shark: preview of the 3D scene

How to play

  • Press and drag to steer the shark. Aim it at the school and the sardines open a hole around it.
  • Let go close to the school and the shark strikes, dashing straight through it. Far away, it goes back to patrolling.
  • Open Lab to change how many neighbours each fish follows or how strongly they stick together.
  • Right-drag to look around. Pinch or scroll to zoom.

Challenges

  1. Steer the shark right through the middle of the school
  2. Cut the school in two so that it swims on as two groups
  3. Let go next to the school to strike, and catch a sardine

Try this

  • Drive the shark slowly through the middle of the school. The fish nearest it split to either side and rejoin behind it, the escape biologists call the fountain effect.
  • Set the neighbours slider to 1. Each fish now follows only one other, and the school breaks into strings and small groups.
  • Turn cohesion right down, then right up, and watch the school spread into a loose cloud or pack into a tight ball.

Fun facts

  • In a classic 1976 experiment, a fish wearing opaque eye covers could still keep its place in a school, using its lateral line to feel the water movements made by its neighbours.
  • The lateral line is a row of pressure-sensing organs along each side of a fish’s body that detects movement and vibration in the water.
  • The silvery sides of sardines and many other open-water fish reflect light like mirrors, which helps them blend into the surrounding water.
  • Sharks can sense the weak electric fields of other animals with jelly-filled pores on their snouts called ampullae of Lorenzini.

How a school of fish moves as one

A school of sardines can turn in an instant, flash silver, and flow around a predator like water around a stone. No fish is in charge. Each one keeps reacting to the few neighbours closest to it, and the school’s behaviour emerges from those local reactions.

Three simple rules

Every fish in this simulation follows the same rules as many models of collective motion: keep a little space from the nearest fish, match their direction and speed, and stay close to them. Each fish watches its seven nearest neighbours rather than every fish within a fixed distance, so the school stays connected even when it stretches. Real fish do this with their eyes and with their lateral line, which senses the pressure waves made by neighbours swimming nearby.

Escaping together

When the shark comes close, the fish nearest to it accelerate away, and they don’t simply flee straight ahead. They move sideways out of its path, swim past it and regroup behind, so the predator ends up in an empty space that travels with it. Biologists call this the fountain effect. Under a sudden attack, fish may also burst outward in all directions in a split second, a flash expansion, before re-forming the school.

Why school at all?

Being one of many helps in several ways. A predator facing hundreds of identical, constantly moving fish finds it hard to lock onto one, the confusion effect. Many eyes spot danger sooner. And any single fish has a smaller chance of being the one caught. Schooling may also help fish find food and save a little energy by swimming in the wake of others.

For the curious

Each fish’s acceleration is the sum of separation from neighbours closer than 0.42 m, alignment toward the neighbours’ average velocity, cohesion toward their centre, a gentle pull back into its home water, and escape. The escape term pushes a fish directly away from the shark and also sideways, perpendicular to the shark’s motion, which produces the fountain. Fish swim faster while alarmed. Their tails beat at a frequency set by the Strouhal number, St = f × A / U, kept near 0.3, the efficient value that many swimming animals use: faster fish beat their tails faster. Neighbours are found with a spatial hash grid and refreshed every few frames, so the whole school runs smoothly in a browser. Sardines are drawn at twice life size so you can see them swim.

Questions people ask

Why do fish swim in schools?

Mostly for protection. A large, moving group confuses predators, gives many eyes to spot danger, and lowers each fish’s chance of being caught. Schooling may also help fish find food and save a little energy in the wake of others.

How do fish in a school avoid bumping into each other?

Each fish watches its nearest neighbours with its eyes and feels their movements in the water with its lateral line. It keeps a little space, matches their direction and speed, and stays close, so the whole school can turn without collisions.

What is the fountain effect in fish schools?

It is an escape pattern in which fish split to either side of an approaching predator, swim past it and regroup behind it. The predator ends up in an empty space that moves with it, while the school stays together.