setup()
setup() runs once when the sketch starts. Use it to initialize your canvas size, color modes, and any starting values. Here it prepares HSB mode so the draw() loop can cycle through hues smoothly.
function setup() {
createCanvas(windowWidth, windowHeight);
// Use HSB so we can easily cycle through hues
colorMode(HSB, 360, 100, 100, 100);
background(0, 0, 0, 100); // start with solid black
}
Line-by-line explanation (3 lines)
🔧 Subcomponents:
createCanvas(windowWidth, windowHeight);
Creates a canvas that fills the entire browser window
colorMode(HSB, 360, 100, 100, 100);
Switches from RGB to HSB (Hue, Saturation, Brightness) so colors cycle smoothly through the spectrum
createCanvas(windowWidth, windowHeight);- Creates a canvas that matches your browser window size so the kaleidoscope fills the entire screen
colorMode(HSB, 360, 100, 100, 100);- Switches to HSB color mode where hue ranges 0-360 (red→orange→yellow→...→red), and saturation/brightness each range 0-100. This makes it easy to cycle through all rainbow colors by incrementing a single number.
background(0, 0, 0, 100);- Draws a fully opaque black background to start with a clean canvas (the 100 is full alpha, no transparency)