Week 2- Pigeon Feeding Simulation

Concept:
In this assignment, I created an interactive scene where pigeons wander around a gray ground (representing something like a park or city square) searching for food. I added two trees on either side of the canvas, and when I click on them, leaves fall and disappear once they hit the ground. The pigeons move toward randomly placed food, and after one of them reaches the food, a new piece of food appears in a different spot. The goal was to simulate natural pigeon behavior and add a fun, interactive element with the falling leaves, all while using vector-based physics to bring the motion to life.

Code Highlight:
One part of the code I’m really happy with is the falling leaves interaction:

function mousePressed() {
  for (let i = 0; i < treePositions.length; i++) {
    let treePos = treePositions[i];
    // Check if the mouse click is within the tree's area
    if (dist(mouseX, mouseY, treePos.x, treePos.y) < 75) {
      // Generate falling leaves from the clicked tree
      for (let j = 0; j < 10; j++) {
        leaves.push({
          position: createVector(treePos.x + random(-20, 20), treePos.y),
          velocity: createVector(random(-1, 1), random(1, 3)) // Falling leaves
        });
      }
    }
  }
}

This part of the code is what handles the falling leaves when you click on a tree. When the user clicks near one of the trees the code checks if the click is within range using the dist() function to measure distance. If it is it triggers a loop that generates 10 leaves each with random positions and velocities so they fall in a natural way. The leaves then get added to an array so they can be drawn and moved across the screen.

I’m really proud of this because it was the part I struggled with the most. Figuring out how to create that random natural-looking motion for the leaves and getting the click interaction to work properly took some effort but it adds a lot of life to the scene!

Embedded Sketch: 


Reflection and Ideas for Future Work:
Looking back, I’m really happy with how the pigeons’ movement and the interactive leaves turned out. It’s a fun and dynamic scene, but I have a few ideas for improvements and future work:

Perlin Noise for the Ground: I want to add Perlin noise to the ground to give it texture, making it look like dirt or pavement instead of just flat gray.

More Realistic Pigeon Behavior: I’d like to implement flocking behavior so the pigeons move together in a more natural way, like real pigeons do.

Tree Sway and Better Leaves: I think it would be cool to make the trees sway slightly when the leaves fall and vary the size and speed of the leaves for more realism.

Animated Pigeons: Adding animations for the pigeons, like walking or pecking, would make them feel more alive.

Leave a Reply

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