setup()
setup() runs exactly once when the sketch starts. It's the right place to configure things that don't need to change every frame, like canvas size and color mode - here HSB mode is chosen specifically because it makes rainbow hue-cycling effects (like this spiral) much easier to write than RGB.
function setup() {
// Create a canvas that fills the entire browser window
createCanvas(windowWidth, windowHeight);
// Set the color mode to HSB (Hue, Saturation, Brightness)
// Hue ranges from 0 to 360, Saturation and Brightness from 0 to 100, Alpha from 0 to 100
colorMode(HSB, 360, 100, 100, 100); // https://p5js.org/reference/p5/colorMode/
// Do not draw outlines around shapes
noStroke(); // https://p5js.org/reference/p5/noStroke/
// Set the background color to black
background(0); // https://p5js.org/reference/p5/background/
}
Line-by-line explanation (4 lines)
createCanvas(windowWidth, windowHeight);- Makes the drawing surface exactly as big as the browser window, so the spiral fills the whole screen.
colorMode(HSB, 360, 100, 100, 100);- Switches from the default RGB color system to HSB (hue, saturation, brightness). Hue goes from 0-360 like a color wheel, which makes cycling through rainbow colors as simple as changing one number.
noStroke();- Turns off the outline that would normally be drawn around every shape, so the dots look like soft solid circles instead of circles with borders.
background(0);- Fills the entire canvas with black once at the start, giving the spiral a dark backdrop to glow against.