setup()
setup() runs once when the sketch starts. Here it's used to configure the color system and build the DOM-based slider UI before any drawing happens in draw().
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100, 100);
smooth(); // ensure anti-aliased drawing
noFill();
frameRate(60);
createUI();
}
Line-by-line explanation (6 lines)
createCanvas(windowWidth, windowHeight);- Makes the canvas fill the entire browser window so the spirograph has as much room as possible to draw.
colorMode(HSB, 360, 100, 100, 100);- Switches p5's color system to Hue-Saturation-Brightness with hue ranging 0-360, which makes it easy to sweep through every color of the rainbow just by changing a single hue number.
smooth();- Turns on anti-aliasing so curved lines look smooth instead of jagged.
noFill();- Ensures no shapes get an interior fill color - since this sketch only draws lines, this avoids unwanted fill artifacts.
frameRate(60);- Caps the sketch at 60 frames per second, keeping the redraw loop smooth and consistent.
createUI();- Calls the custom helper function that builds the slider panel in the top-left corner of the page.