Lecture 5 (24 Feb)
You can jump to any slide with the menu to the (bottom) left.
Did you miss a slide or want to revisit? Open the narration tab while studying to get an explanation of difficult slides.

Milestone Guidance
constrainedX to the square.constrain() that simplifies the process of constraining values.constrainedX using constrain().min() and max() functions.min() returns the smaller of two values, while max() returns the larger.constrainedX using min() and max().% can be used to wrap values around a certain range.moduloX to be between 0 and 220.map() function scales and constrains values.mappedX from 0-400 to 100-220.Class Assignment: Car


Go to the GitHub repository of the course and click on the libraries folder
Open the p5.sound.min.js file
Download the raw file
Make your (new) sound sketch and go to its folder


Go to the libraries folder in your sound sketch and put the p5.sound.min.js file there
In Processing, open up the index.html file of your sketch
Add the following to your index.html:
userStartAudio() function in a user interaction event (e.g. mousePressed()) to enable audio in our sketch.play(note, volume, delay, time) takes four arguments to specify the pitch, volume (0-1), delay before the note starts (in seconds), and duration of the note (in seconds).p5.PolySynth()Class Assignment: Melody
loadSound() function to load sound files and a play() method to play them.stop(), pause(), and loop() methods.setVolume() sets the volume of the sound, similar to how we can set the volume of a synthesizer note.preload() function to load sound files before the sketch starts.cymbal.wav if you have the file in the same folder as your sketch)loop() instead of play().pause() and play().stop() .p5.AudioIn() class to access the microphone and capture sound input.p5.AudioIn() object and call the start() method to begin capturing sound.getLevel() method of the audio input object returns the current volume level of the sound being captured by the microphone.getLevel() are typically between 0 and 1.map() function to scale the volume level from the microphone to a range that is suitable for our sketch.Class Assignment: Sound Reactive

Creative Programming 2026 Lecture 5 - Ties Robroek - IT University of Copenhagen