setup()
setup() runs once when the sketch starts. It initializes the canvas, sets up color mode for easier color generation, and prepares the audio system and pads for interaction.
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100);
noStroke();
userStartAudio();
initializePads();
}
Line by Line:
createCanvas(windowWidth, windowHeight)- Creates a canvas that fills the entire browser window, making the sketch responsive to window size
colorMode(HSB, 360, 100, 100)- Switches from RGB to HSB color mode, where colors are defined by Hue (0-360), Saturation (0-100), and Brightness (0-100). This makes it easier to create a rainbow of pad colors
noStroke()- Disables stroke drawing by default, so shapes won't have outlines unless explicitly set
userStartAudio()- Unlocks the Web Audio API context, which modern browsers require for sound to play after user interaction
initializePads()- Calls the function that creates all 16 pad objects and calculates their positions on the canvas