setup()
setup() runs exactly once when the sketch starts. It's the right place to configure canvas size, color modes, and any values (like angleStep) that don't need to be recalculated every frame.
function setup() {
// Create a canvas that fills the entire browser window
createCanvas(windowWidth, windowHeight);
// Set the color mode to HSB (Hue, Saturation, Brightness)
// Hue: 0-360 degrees (color wheel)
// Saturation, Brightness: 0-100%
colorMode(HSB, 360, 100, 100);
// Ensure line endings are rounded for a softer appearance
strokeCap(ROUND);
// Tell p5.js not to fill shapes, only draw their outlines
noFill();
// Set the initial background to a very dark grey
background(0, 0, 10);
// Calculate the angle for each symmetrical rotation step
// TWO_PI is a full circle in radians (360 degrees)
angleStep = TWO_PI / numSymmetry;
}
Line-by-line explanation (6 lines)
createCanvas(windowWidth, windowHeight);- Makes the canvas exactly as big as the browser window, so the drawing fills the whole screen.
colorMode(HSB, 360, 100, 100);- Switches p5's color system to Hue/Saturation/Brightness with hue ranging 0-360 (like a color wheel) instead of the default RGB 0-255, which makes rainbow color effects much easier to compute.
strokeCap(ROUND);- Makes the ends of each drawn line rounded instead of flat/square, giving strokes a softer, more organic look, especially at joints.
noFill();- Tells p5 not to fill any shapes with color - since this sketch only draws lines, there's nothing to fill.
background(0, 0, 10);- Paints the canvas with a very dark grey (near-black) using HSB values - hue and saturation are 0, brightness is 10%.
angleStep = TWO_PI / numSymmetry;- Precalculates how many radians to rotate for each symmetrical copy - dividing a full circle (TWO_PI) into numSymmetry equal slices.