Skip to content

A Rust implementation of Craig Reynolds' Boids algorithm, simulating emergent flocking behavior with real-time parameter controls.

License

Notifications You must be signed in to change notification settings

IAmFarrokhnejad/Boids

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Boids 🐦

A Rust implementation of Craig Reynolds' Boids algorithm demonstrating emergent flocking behavior, with real-time parameter controls using the Piston window library.

Features ✨

  • 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

Installation ⚙️

Prerequisites

  • Rust (1.58+)
  • Cargo (included with Rust)

Steps

  1. Clone repository:
    git clone https://github.com/iamfarrokhnejad/Boids.git
    cd boids-simulation
  2. Add a font file:
  3. Run simulation:
    cargo run --release

Controls 🎮

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

Dependencies 📦

Configuration ⚙️

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

License 📄

MIT License - see LICENSE file

Acknowledgments 🙏

Troubleshooting 🔧

Font Error: Ensure:

  1. Font file exists in project root
  2. Filame matches FiraSans-Regular.ttf
  3. File is not corrupted

Performance Issues:

  • Run with --release flag
  • Reduce NUM_BOIDS constant