A code sample for a simple "boids" simulator.
As a code sample, this repo showcases:
- OOP Design (Inheritance, Polymorphism, etc.)
- Documentation
- A basic, Makefile-based build system
- Familiarity with Unix-based systems
Boids are a simple example of emergent phenomenon. They were developed by Craig Reynolds in 1986 to simulate the flocking behavior of birds. The classical boid follows three rules:
- Try not hit the other boids (Separation)
- Try to match other boids direction (Alignment)
- Try to stay with the flock (Cohesion)
From these few rules, you get emergent flocking phenomenon.
run make all to create the executable bin/boids
run make clean to clean out these exectables
bin/boids takes six parameters:
| parameter | description |
|---|---|
| width | the width of the space |
| height | the height of the space |
| population size | the number of boids to generate |
| local radius | the radius that boids will consider "local" |
| seed | a seed for a random number generator |
| timesteps | the number of time steps to run the simulator |
example:
UNIX> ./bin/boids
Usage: ./boids [width] [height] [population size] [local radius] [seed] [timesteps]
Too few arguments
UNIX> ./bin/boids 100 100 100 5 0 300
The bin/boids executable generates a series of one-line, JSON-parseable arrays describing the positions of each Boid within the Arena space.
Boid behavior is best seen on a large scale - not through numbers. There exists a very basic visualization tool built with the LöVE2D graphics framework. LöVE2D can be installed here.
To run this viz tool, simply pipe the output of bin/boids to the viz tool.
example:
./bin/boids 100 100 100 5 0 300 | love ./love
As this is a code sample, there are smaller details that have not been touched. As it stands currently, Boids determine direction based on a simple average of the three properties described above. This can cause issues like a Boid "deciding" to hit another Boid because it would rather face the center point. For large population sizes and large radius sizes, the efficiency of this program drops drastically. However, as this is a code sample, these issues are not drastic. If you find any other major issues, I invite you to bring them to my attention.