An implementation of Craig Reynolds' Boids algorithm, demonstrating emergent flocking behavior through simple steering rules.
- Separation: Avoid crowding neighbors
- Alignment: Steer towards average heading of local flock
- Cohesion: Move towards average position of neighbors
- QuadTree Optimization: O(n log n) neighbor queries for 1000+ agents at 60 FPS
- Line-of-Sight Vision: Realistic forward-facing perception cones
- Force Fields: Attractive goals and repulsive obstacles
- Live Controls: Real-time parameter adjustment via sliders
- Debug Mode: Visualize perception cones and spatial partitioning
- Modular Architecture: Clean ES6 modules with MVC pattern
boids/
βββ index.html # Entry point with ES6 module loading
βββ src/
β βββ main.js # p5.js lifecycle coordinator
β βββ config/
β β βββ SimulationConfig.js # Centralized configuration
β βββ entities/
β β βββ Agent.js # Boid with flocking behaviors
β β βββ ForceField.js # Obstacles and goals
β βββ controllers/
β β βββ SimulationController.js # Simulation state management
β β βββ UIController.js # UI interactions and HUD
β βββ spatial/
β β βββ QuadTree.js # Spatial partitioning
β βββ utils/
β βββ VectorUtils.js # Math and vector operations
βββ README.md
-
Clone the repository:
git clone https://github.com/hugoassisj/boids.git cd boids -
Open in browser: That's it! The simulation loads p5.js from CDN automatically.
- Craig Reynolds - Original Boids algorithm
- Daniel Shiffman - Nature of Code and educational resources
- p5.js Community - Amazing creative coding library and support

