Tutor AI

Ocean Predator — Interactive Fish School Simulation

Fish: 0 FPS: 0
Move your cursor to control the shark and hunt the school of fish!

Ocean Predator Simulation using the Boids Algorithm

This interactive ocean predator simulation implements Craig Reynolds' classic boids algorithm to model realistic fish schooling behavior in a WebGL-rendered underwater environment. A shark (predator) chases a school of fish (prey) governed by three core boids rules: separation, alignment, and cohesion.

How the Boids Algorithm Works in This Ocean Simulation

Each fish in the school is an autonomous agent (boid) that steers based on its local neighbors. Separation keeps fish from crowding, alignment steers each fish to match the average heading of its neighbors, and cohesion pulls fish toward the center of the group. The ocean predator — the shark — applies an additional flee force that causes the school to scatter and reform dynamically, mimicking real predator-prey dynamics observed in open ocean ecosystems.

Technical Implementation

Built with JavaScript and WebGL via Three.js. The boids simulation runs in real-time with up to 500 fish agents. Users can tune fish count, swim speed, and toggle a debug view that visualizes the boids' perception radius and velocity vectors. The predator position is driven by mouse or touch input, making this an interactive ocean predator experience directly in the browser — no download required.