A high-performance, interactive flocking simulation (Boids model) implemented in C# using Raylib-cs. This project visualizes flocking behavior of autonomous agents ("boids") based on alignment, cohesion, and separation rules.
The simulation starts with a welcome screen and instructions. Press Enter to start rendering the boids. You can dynamically adjust behavioral parameters using your keyboard.
-
Multithreaded update logic (custom
UpdateandParallel.Forversions) -
Adjustable parameters for flocking:
A- Max SpeedI- Min SpeedT- Turn FactorC- Centering FactorV- Avoidance FactorM- Matching Factor
-
Reset parameters with
R -
Toggle help screen with
H -
Visual boundary box and parameter overlay
Each boid updates its position and velocity based on nearby boids:
- Separation: Avoid crowding neighbors
- Alignment: Align direction with nearby boids
- Cohesion: Move toward the average position of neighbors
- Boundary avoidance: Steer away from screen edges
| Key | Action |
|---|---|
Enter |
Start the simulation |
H |
Show/hide the welcome/help screen |
A + ←/→ |
Decrease/increase max speed |
I + ←/→ |
Decrease/increase min speed |
T + ←/→ |
Decrease/increase turn factor |
C + ←/→ |
Decrease/increase centering (cohesion) factor |
V + ←/→ |
Decrease/increase avoidance (separation) factor |
M + ←/→ |
Decrease/increase matching (alignment) factor |
R |
Reset all parameters to default |
git clone https://github.com/Nedal-haltam/Boids.git
cd Boids
dotnet runTo modify the number of boids or simulation dimensions, edit these constants in Program.cs:
static int N = 5 * 1000; // Number of boids
static int f = 100;
static int w = 9 * f;
static int h = 9 * f;- Uses multi-threading for efficient updates on large boid counts.