A high-performance, real-time swarm intelligence simulation built with TypeScript and WebGPU. This project implements Reynolds' Boids algorithm with advanced ecosystem features, environmental forces, and various optimizations for simulating thousands of agents.
- Advanced Flocking Algorithm: Implementation of Alignment, Cohesion, and Separation rules.
- Ecosystem Interactions:
- Predators: Multiple predator types (Hawk, Falcon, Eagle, Owl, Shark, etc.) with unique hunting behaviors.
- Food Sources: Dynamic food spawning and gathering mechanics.
- Mating System: Complex mating behaviors including searching, courting, and cooldowns.
- Environmental Forces:
- Wind: Global wind system with turbulence.
- Attractors/Repulsors: User-interactive force sources (Click/Right-click).
- High Performance:
- WebGPU Acceleration: Utilizes GPU for rendering and computation.
- Spatial Partitioning: O(n*k) neighbor lookup using a Spatial Grid.
- Zero-Allocation Strategy: Optimized memory usage in hot loops to prevent GC spikes.
- Fixed Timestep Physics: Deterministic simulation regardless of frame rate.
- Interactive Control:
- Real-time Configuration: Tweakpane-powered UI for adjusting all simulation parameters.
- Creature Presets: 12+ built-in presets (Starlings, Insects, Fish, Bats, etc.).
- Custom Presets: Save, load, export, and import your own configurations.
- Statistics: Real-time performance and population metrics.
- Language: TypeScript
- Build Tool: Vite
- Rendering/Compute: flux-gpu (WebGPU)
- UI: Tweakpane
- Math: Custom 2D Vector library with object pooling
- Node.js (Latest LTS recommended)
- A browser with WebGPU support (Chrome 113+, Edge 113+)
-
Clone the repository:
git clone <repository-url> cd swarm-intelligence-2
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
Build for production:
npm run build
- Left Click: Spawn an Attractor (pulls birds).
- Right Click: Spawn a Repulsor (pushes birds).
- Shift + Click: Spawn a Food Source (if enabled).
- Control Panel: Use the sidebar to switch between creature presets or manually adjust behaviors, environment, and rendering settings.
Detailed documentation is available in the docs/ directory:
- Simulation Engine: Details on the Boids algorithm, physics, and spatial optimization.
- Ecosystem Systems: Deep dive into Predators, Food, Mating, and Energy systems.
- Development & Architecture: Technical overview, project structure, and performance optimizations.
Additional technical notes can be found in the distillations/ folder.
MIT