Condition and Loop

code: https://editor.p5js.org/Annaoh/sketches/HJdtzcFY7

ollaborated with Anna Oh, so much fun coding.

Concept

This is a music DJ set that makes an animal chorus. Players can decide how they want to compose the animals. The four buttons on the bottom left each has an animal sound. By clicking the button, a row of animals will appear to sing.

It was a lot of fun to code with someone. In our first meeting, Anna had an idea to create something like a DJ turntable, and my idea was to create some game like thing. We combined the two ideas, and this DJ controller in animal version is what we came up with.

Coding

Few challenges we met:

  • how to have infinite images loop around a row?

    • Solution: Through for loops, we can create a bunch of dog images. Through if statement, when the dog reaches to the right edge, come back to the left.

  • how to press the button and keep the sound looping until press again?

    • Solution: Use mouse pressed function outside of draw(). The function would only be triggered when the event happens. We also used buttonstate = !buttonstate to toggle whether the mouse is pressed or not pressed.

We learned the most from them these two most difficult challenges in this project.

download.png