Home▸Biology & Life▸2D Aquarium — Flat Fish Schooling & Predator Avoidance (2D)

2D Aquarium — Flat Fish Schooling & Predator Avoidance

A flat top-down 2D fish-schooling simulation: genuine Boids flocking (separation, alignment, cohesion) via a spatial-grid neighbour search, plus predator avoidance and food-seeking. Adjust fish count, speed, cohesion and predator count; drop food and watch the school react in real time.

Biology & Life2DEasy60 FPS📱 Mobile-adapted💧 Water⇄ 3D version
2d-aquarium ↗ Open standalone

This is the flat, top-down companion to the 3D Aquarium simulator. Every fish is an independent agent that queries only its nearby neighbours through a spatial grid and combines three flocking forces — separation, alignment and cohesion — with two fish-specific behaviours: fleeing from sharks and steering toward food. Nothing is scripted at the group level; the school, the scattering when a shark charges, and the scramble toward a dropped crumb all emerge from these local per-fish rules.

⚙ Under the hood

A genuine 2D top-down companion to the 3D Aquarium simulator: real Boids flocking — separation, alignment and cohesion — computed through a uniform spatial grid so each fish only queries its actual nearby neighbours, layered with fish-specific behaviour that a decorative animation would skip: sharks that actively hunt the nearest fish, a flee force that grows sharply as a shark closes in and overrides ordinary schooling, and food-seeking where fish sense and steer toward the nearest dropped crumb. Adjust fish count, speed, cohesion strength and shark count live, or click the tank to drop food and watch the school scatter and regroup.

fish schoolingboidsflockingpredator avoidancespatial gridcanvas 2demergent behavior

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

What did you find?

Add reproduction steps (optional)