Python implementation of Boids using the PyGame engine for the visualization.
Create a Python virtual environment and activate it.
python -m venv .venv
Windows virtual environment activation
.venv/Scripts/activate
Mac or Linux virtural environment activation
source .venv/bin/activate
This simulation requires the numpy and pygame packages. These can be installed via pip
andn the requirements.txt
file.
pip install -r requirements.txt
Run the script boids_sim.py
to see the Boids in action.
Adjust the parameters in the [screen]
section of config.ini
to change some general game settings:
- Screen dimensions in pixels: [width, height]
winsize = [800, 600]
- Use fullscreen mode? Will accept values of 'yes'/'no', 'on'/'off', 'true'/'false' and '1'/'0'
fullscreen = no
- Select the boundary type at the edge of the screen: either WRAP or BOUNCE
boundary_type = BOUNCE
Adjust the [boid]
parameters at in the file config.ini
to modify the boid behaviour in the simulation:
- Number of boids
num_boids = 7
- Size of the boids
size = 5
- Maximum speed of the boids
max_speed = 3
- Amount that the boids move towards the center of the flock
cohesion_factor = 0.001
- Desired separation between boids
separation = 20
- Amount that the boids move away from each other
avoid_factor = 0.01
- Amount that the boids try to match the velocity of the flock
alignment_factor = 0.01
- Radius of boids vision. Boids will not interact with other boids that exceed this radius
visual_range = 50
- Background and Update by Conrad Parker
- Conrad Parker psuedocode: Original psuedocode and explanations
- Smarter Every Day Git Repo: JavaScript version of Boids
- Wikipedia: Overview of Boids