Inspiration:
This project aims to simulate a dynamic flocking system where agents (boids) exhibit cohesive, aligning, and separating behaviors within a visual environment. Inspired by nature and emergent patterns found in flocks of birds or schools of fish, this project integrates code with artistic composition to create an evolving narrative through visual and behavioral changes.
Description:
The project utilizes the p5.js library in JavaScript to implement a flocking simulation. Boids, represented as small circular shapes, demonstrate collective behavior influenced by separation, alignment, and cohesion. These behaviors are controlled by specific rules that affect how boids interact with their neighbors within a defined radius.
The code initializes a canvas and generates a flock consisting of individual boids. Each boid possesses properties such as position, velocity, and acceleration. Through the flock() function, boids respond to nearby neighbors within certain radii (separation, alignment, and cohesion) and adjust their behavior accordingly.
The separate(), align(), and cohere() functions within the Boid class determine how each boid interacts with others. Separation ensures that boids maintain a minimum distance from neighbors, alignment aims to match velocities with nearby boids, and cohesion encourages boids to move towards the average position of neighboring boids.
The update() function governs the boid’s movement, calculating its new position based on velocity and acceleration. The display() function visually represents each boid as a small white circle on the canvas.
The project also allows for potential narrative development or visual changes over time. For instance, altering the background or introducing new behaviors at specific frame counts could represent the evolving story or tension and release dynamics within the simulation.
// Flocking behaviors (separation, alignment, cohesion)
flock(others) {
let separationForce = this.separate(others);
let alignmentForce = this.align(others);
let cohesionForce = this.cohere(others);
separationForce.mult(1.5);
alignmentForce.mult(1.0);
cohesionForce.mult(1.0);
this.acceleration.add(separationForce);
this.acceleration.add(alignmentForce);
this.acceleration.add(cohesionForce);
}