This is a Boids simulation implemented in Zig using Raylib. The Boids algorithm models flocking behavior of birds, where each agent (boid) follows three primary rules:
- Separation: Avoid crowding nearby boids.
- Alignment: Align velocity with neighboring boids.
- Cohesion: Move towards the average position of nearby boids.
- Realistic flocking behavior using vector mathematics.
- Smooth movement and interactions between boids.
- Configurable parameters for behavior tuning.
- Efficient rendering using Raylib.
Ensure you have the following installed:
- Clone this repository:
git clone [https://github.com/yourusername/boids-zig.git](https://github.com/lazycodebaker/biods.git) cd boids-zig - Build the project:
zig build
- Run the simulation:
zig-out/bin/boids
- Close Window: Press
ESCor click the close button.
Modify these parameters in main.zig to tweak boid behavior:
const avoidance_factor = 0.05; // Influence of avoiding close boids
const matching_factor = 0.05; // Influence of velocity alignment
const centering_factor = 0.0005; // Influence of moving towards nearby boids
const min_speed = 1.5;
const max_speed = 3;
const turn_padding = 100; // Screen edge avoidance buffer
const turn_factor = 0.2; // Steering force at screen edgesThis project is released under the MIT License.
