A Rust implementation of Craig Reynolds' Boids algorithm demonstrating emergent flocking behavior, with real-time parameter controls using the Piston window library.
- Flocking Behaviors:
- Cohesion: Boids move toward group center
- Alignment: Boids align direction with neighbors
- Separation: Boids maintain personal space
- Real-time parameter adjustments
- Interactive GUI with on-screen parameter display
- Wrap-around window boundaries
- Color-coded boids for visual distinction
- Rust (1.58+)
- Cargo (included with Rust)
- Clone repository:
git clone https://github.com/iamfarrokhnejad/Boids.git cd boids-simulation
- Add a font file:
- Place
FiraSans-Regular.ttf
in the project root - Download font
- Place
- Run simulation:
cargo run --release
Key | Action | Range |
---|---|---|
1 | Increase visual range (+5) | 0-100 |
2 | Decrease visual range (-5) | 0-100 |
3 | Increase cohesion (+0.01) | 0-0.5 |
4 | Decrease cohesion (-0.01) | 0-0.5 |
5 | Increase alignment (+0.01) | 0-0.5 |
6 | Decrease alignment (-0.01) | 0-0.5 |
7 | Increase separation (+0.01) | 0-0.5 |
8 | Decrease separation (-0.01) | 0-0.5 |
ESC | Exit simulation |
- piston_window 0.131.0
- rand 0.8.5
Adjust constants in src/main.rs
:
const WIDTH: f64 = 800.0; // Window width
const HEIGHT: f64 = 600.0; // Window height
const NUM_BOIDS: usize = 100; // Number of boids
const MAX_SPEED: f64 = 2.0; // Maximum boid speed
MIT License - see LICENSE file
- Based on Craig Reynolds' Boids
- Built with Piston graphics engine
- Inspired by emergent behavior in nature
Font Error: Ensure:
- Font file exists in project root
- Filame matches
FiraSans-Regular.ttf
- File is not corrupted
Performance Issues:
- Run with
--release
flag - Reduce
NUM_BOIDS
constant