MATLAB implementation of Boids simulation, as part of school project
Boids is an artificial life program that simulates the flocking behavior of birds.
The movement of boids is governed by three principles:
- separation: each boid steers away from all other neighborin boids to not collide.
- alignment: each boid steers towards the average directions of other neighboring boids.
- cohesion: each boid steers towards the center position of the neighboring boids.
The three principles give rise to the emergent behavior of boids flocking with each other, resembling that of birds.
This implementation also includes predators that chase the boids. Boids try to run away from the predators when they are within a certain distance.
Run Boids.m to produce the simulation in avi format.
Boids.m contains the parameters that determine:
- number of boids
- number of predators
- height & width of the world
- simulation length
- maximum speed of boids and predators
Play around with the settings.
The initial positions and velocities of boids and predators are always random, so each simulation will produce a unique outcome.