setup()
setup() runs once when the sketch starts. It's where you prepare your canvas, define color modes, and set initial values. Using HSB mode here makes the rainbow-cycling effect in draw() feel natural—a single hue value creates colors across the full spectrum.
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100, 100);
background(0, 0, 95);
brushColor = color(0, 80, 90);
}
Line-by-line explanation (4 lines)
createCanvas(windowWidth, windowHeight);- Creates a canvas that fills the entire browser window, so you have maximum space to paint
colorMode(HSB, 360, 100, 100, 100);- Switches to HSB (Hue, Saturation, Brightness) color mode where hue ranges 0–360 (the rainbow), saturation and brightness each 0–100, and alpha (transparency) 0–100
background(0, 0, 95);- Fills the canvas with a near-white background (hue 0, saturation 0, brightness 95)
brushColor = color(0, 80, 90);- Sets the initial brush color to a red hue (0) with high saturation (80) and brightness (90)