Case study 07/08 // Creative code · Boids
Flocking Simulator
An interactive boids simulation: emergent flocking from three tiny rules, animated in real time on canvas.

The write-up
Flocking Simulator - Interactive Boids Animation
An interactive flocking simulation that demonstrates emergent group behavior through the implementation of Craig Reynolds’ classic “boids” algorithm. This project showcases computational creativity and algorithm visualization in an engaging, real-time interactive format.
Project Overview
The Flocking Simulator is a web-based interactive animation that models the flocking behavior of birds through simple computational rules. Each “boid” (bird-like object) follows three basic behavioral rules that collectively create complex, lifelike group movements. The simulation is live at flockingsimulator.netlify.app.
Key Features
- Real-time Simulation: Smooth 60 FPS animation with hundreds of interactive boids
- Emergent Behavior: Complex group patterns arising from simple individual rules
- Interactive Controls: Real-time parameter adjustment for different flocking behaviors
- Visual Customization: Multiple color schemes and visual styles
- Performance Optimization: Efficient spatial partitioning for smooth performance
- Responsive Design: Adapts to different screen sizes and device capabilities
- Educational Interface: Clear visualization of the three core flocking rules
Technology Stack
- Core: Vanilla JavaScript (ES6+)
- Graphics: HTML5 Canvas API
- Animation: RequestAnimationFrame for smooth rendering
- Math: Vector mathematics and spatial algorithms
- Deployment: Netlify with automatic deployments
- Version Control: Git with feature-based development
Algorithm Implementation
The Three Rules of Flocking
- Separation: Steer to avoid crowding local flockmates
- Alignment: Steer towards the average heading of neighbors
- Cohesion: Steer to move toward the average position of local flockmates
Performance Optimizations
- Spatial Partitioning: Grid-based neighbor detection for O(n) complexity
- Vector Pooling: Reusable vector objects to minimize garbage collection
- Adaptive Quality: Dynamic adjustment based on device performance
- Efficient Rendering: Optimized canvas operations for smooth animation
Development Highlights
- Mathematical Modeling: Implemented accurate vector mathematics for realistic movement
- Performance Engineering: Optimized algorithms to handle 500+ boids at 60 FPS
- Interactive Design: Created intuitive controls for real-time parameter adjustment
- Visual Polish: Designed appealing visual styles with smooth animations
- Cross-browser Compatibility: Ensured consistent performance across different browsers
Interactive Features
The simulation implements the classic boids algorithm with a comprehensive Boid class that manages individual agent behavior. Each boid follows the three fundamental rules of flocking: separation to avoid crowding, alignment to match neighbor headings, and cohesion to move toward the group center. The system uses vector mathematics to calculate smooth, natural movement patterns.
User Controls
- Population Size: Adjust the number of boids from 50 to 500
- Rule Weights: Fine-tune separation, alignment, and cohesion forces
- Speed Controls: Modify maximum speed and steering force
- Visual Options: Change colors, trails, and rendering styles
- Predator Mode: Add predators that boids will flee from
- Obstacle Placement: Interactive obstacle creation and placement
Educational Value
- Algorithm Visualization: Clear demonstration of emergent behavior principles
- Parameter Exploration: Interactive learning about how small changes affect group behavior
- Performance Awareness: Real-time FPS counter and performance metrics
- Code Accessibility: Clean, well-commented code for educational reference
Technical Achievements
- Smooth Performance: Maintains 60 FPS with hundreds of autonomous agents
- Realistic Movement: Natural-looking flocking behavior with smooth transitions
- Interactive Responsiveness: Real-time parameter changes without performance loss
- Visual Appeal: Engaging graphics that make complex algorithms accessible
- Mobile Optimization: Touch-friendly controls and adaptive performance
Impact & Reception
- Educational Use: Used in computer science courses for algorithm demonstration
- Portfolio Showcase: Demonstrates computational creativity and mathematical modeling skills
- Open Source: Code available for learning and educational purposes
- Performance Benchmark: Showcases JavaScript optimization techniques
- Creative Coding: Bridges the gap between art and computer science
Future Enhancements
- 3D Implementation: Extend to three-dimensional flocking behavior
- Machine Learning: AI-driven behavioral pattern learning
- WebGL Rendering: GPU-accelerated graphics for larger simulations
- Sound Integration: Audio-reactive behavior based on music input
- VR/AR Support: Immersive flocking experiences
This project demonstrates my passion for computational creativity and ability to implement complex algorithms in engaging, interactive formats. It showcases skills in mathematical modeling, performance optimization, and creating educational technology that makes abstract concepts tangible and fun to explore.

