Post

Assignment 2 Vectors

Assignment 2 Vectors

Link to Project

Dynamic Acceleration

I started by thinking of some of the ways that could interact with the ecosystem and give it dynamic acceleration

A dynamic acceleration system changes over time based on multiple factors, such as:

  • Proximity to other flies (avoidance or attraction)
  • Time-based oscillation (e.g., sine waves for smoother acceleration)
  • External influences (mouse interaction, wind force, etc.)
  • Personality-driven behavior shifts (flies adapting to surroundings)

I chose to make the mouse interaction with the movement of flies.

Effect: If the mouse gets too close, flies move away dynamically. Otherwise, they wander randomly as before.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
    let mouse = createVector(mouseX, mouseY);
    let dir = p5.Vector.sub(mouse, this.pos); // Direction to mouse
    let distance = dir.mag();
  
    if (distance < 100) 
    {  
        // If close to the mouse, react
        dir.setMag(map(distance, 0, 100, this.maxSpeed, 0)); // Stronger acceleration if closer
        this.acc = dir;
    } 
    else 
    {
        if (random(1) < this.turnChance) 
        {
            const angle = random(TWO_PI);
            this.acc = p5.Vector.fromAngle(angle).mult(0.5);
        }
    }
}
This post is licensed under CC BY 4.0 by the author.

Trending Tags