Skip to content

hugoassisj/boids

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

22 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🐦 Boids β€” Flocking Simulation

p5.js License Status

An implementation of Craig Reynolds' Boids algorithm, demonstrating emergent flocking behavior through simple steering rules.

alt text alt text

✨ Features

Core Behaviors

  • Separation: Avoid crowding neighbors
  • Alignment: Steer towards average heading of local flock
  • Cohesion: Move towards average position of neighbors

Highlights

  • 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

πŸ“ Project Structure

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

πŸš€ Getting Started

Quick Start

  1. Clone the repository:

    git clone https://github.com/hugoassisj/boids.git
    cd boids
  2. Open in browser: That's it! The simulation loads p5.js from CDN automatically.

πŸ™ Acknowledgments

  • Craig Reynolds - Original Boids algorithm
  • Daniel Shiffman - Nature of Code and educational resources
  • p5.js Community - Amazing creative coding library and support

About

Implementation of Boids Algorithm

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published