Week 9: School of Fish

Concept:

For this week’s assignment, my dynamic flocking system is a school of fish. I added some oscillation to their weights by using sin(). I also randomized their maxSpeed and maxForce to make it seem more natural.

.

Code Snippet & Challenges:

function mousePressed() {
  let attractionPoint = createVector(mouseX, mouseY);
  for (let boid of flock.boids) {
    let attraction = p5.Vector.sub(attractionPoint, boid.position);
    attraction.setMag(0.6);
    boid.applyForce(attraction);
  }
  
  for (let i = 0; i < 20; i++) {
    particles.push(new Particle(mouseX, mouseY));
  }
}

In this part of the code, I added a mousePressed() function in which the fish get attracted to wherever the mouse is at the time when it is clicked on the canvas. I also added some food particles for the fish, which is what they attracted to. I would say the most challenging part was figuring out what the formula is for the attraction part.

Future Improvements:

  • I would definitely add a more colorful background and some sounds, for now I wanted to focus on more of the technical aspect of the school of fish.

Leave a Reply

Your email address will not be published. Required fields are marked *