Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jwt2706/boids
Simulates the flocking behavior of birds using the Boids algorithm [s!]
https://github.com/jwt2706/boids
boids-algorithm boids-simulation p5
Last synced: about 2 months ago
JSON representation
Simulates the flocking behavior of birds using the Boids algorithm [s!]
- Host: GitHub
- URL: https://github.com/jwt2706/boids
- Owner: jwt2706
- License: mit
- Created: 2024-03-26T01:21:55.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-03-30T00:06:38.000Z (9 months ago)
- Last Synced: 2024-03-30T02:40:54.315Z (9 months ago)
- Topics: boids-algorithm, boids-simulation, p5
- Language: JavaScript
- Homepage: https://jwt2706.ca/Boids
- Size: 1.18 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Boids Simulation
This project simulates the flocking behavior of birds using an implementation of the [Boids algorithm](https://en.wikipedia.org/wiki/Boids).
See the simulation for yourself [here](https://jwt2706.github.io/Boids)!
## Overview
The Boids algorithm models the behavior of an individual bird within a flock through three simple rules:
1. **Separation**: Avoid crowding neighbors (short range repulsion)
2. **Alignment**: Steer towards the average heading of neighbors
3. **Cohesion**: Steer towards the average position of neighbors (long range attraction)Each boid in the simulation follows these rules, resulting in complex but really cool looking behaviors.
## Implementation
The simulation is implemented in JavaScript using the p5.js library for rendering. The main logic is contained in the `Boid` class, which represents an individual boid in the simulation. The `Boid` class has methods for calculating the separation, alignment, and cohesion forces, updating the boid's position and velocity, and rendering the boid.
The simulation is initialized and run in the `sim` function, which uses the p5.js `setup` and `draw` functions to create the boids and update the simulation each frame.
## Configuration
The number of boids in the simulation can be configured by changing the `NUMBER_OF_BOIDS` constant at the top of `boids.js`.
The behavior of the boids can be tweaked by adjusting the `maxForce` and `maxSpeed` properties of the `Boid` class, and the `perceptionRadius` variable in the `align`, `cohesion`, and `separation` methods. Although, the current values seemed to be the ones that work the best for me.