This project aims at understanding the phenomenon of swarming in organisms like fishes which tend to show collective behaviour. It tries to model and understand different rules that govern the local behaviour of the organisms which in turn lead to a collective behaviour on the whole.
The project is based on the Craig Reynolds' model for simulating the fish swarms and extends the model further.
The Prey fishes (boids) follows the simple five rules stated below.
- Avoid collision with other prey fishes
- Align the velocity
- Move towards the center of the neighboring fishes
- Move toward the center of the neighboring fishes of the same species(color)
- Avoid predator
The Predator boids follow the simple two rules stated below.
- Avoid collision with other predator fishes
- Move towards the center of neighboring prey fishes, i.e., locking of the prey fishes
There are 4 different JavaScript files in the js
subdirectory.
The flock.js
file contains the implementation of the Flock
class which maintains the list of prey or predator boid objects.
The boid.js
file contains the implementation of the Prey boid under the Boid
class. This class is responsible for implementing all the rules for prey boid and also for rendering a Prey boid.
The predator.js
file contains the implementation of the Predator boid under the Predator
class. This class is responsible for implementing all the rules for predator boid as discussed above and also for rendering a Predator boid.
The runner.js
file is the most important file. It is responsible for creating the GUI elements such as sliders, check box and the canvas. Using the p5.js
library, it handles the updates of the parameters and GUI.
There are two ways to start the project and analyze the model
One can either open the project online from here or can open the index2.html
file present in the current directory to open it locally. Nothing except a browser is needed if one wants to run the project locally.