Step 24

//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

`drawSelf()`

functionCheck Your Work

Step 29
Planning

Step 30
This fish chooses a random x and y velocity **once every 2 seconds**:

It also **slows down over time** after each time it moves.

Information

Step 31
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

Check Your Work

Step 35
Check Your Work

Step 37
It's annoying that the fish swims off-screen though...

Check Your Work

Step 45
Evolving Fish Pond 1: Making your Fish class Info

For Teachers and Schools

Teach coding to your students with MVCode Teach

MVCode offers an integrated product designed to teach coding to students.