//no outline noStroke(); //get direction fish is facing var angle = atan2(this.yvel, this.xvel); //transform the fish to face the right direction push(); translate(this.x, this.y); rotate(angle); //draw an orange ellipse and triangle to represent the fish fill(10, 100, 100); ellipse(0, 0, this.size * 1.25, this.size); triangle(-this.size/2, 0, -this.size, -this.size/3, -this.size, this.size/3); pop(); //end transformation
This fish chooses a random x and y velocity once every 2 seconds:
It also slows down over time after each time it moves.
First lets log frameCount to the console and you'll see this:
The p5js library counts each frame since the program began.
You should see it count 60 frames per 1 second
It's annoying that the fish swims off-screen though...