setup()
setup() runs once when the sketch starts, making it the right place to configure the canvas, color mode, and initial state before animation begins.
function setup() {
createCanvas(windowWidth, windowHeight);
colorMode(HSB, 360, 100, 100, 100); // easier colorful gradients
noStroke();
centerX = width / 2;
centerY = height / 2;
initOrbs();
background(0); // start with a clean black background
}
Line-by-line explanation (7 lines)
createCanvas(windowWidth, windowHeight);- Makes the canvas fill the entire browser window.
colorMode(HSB, 360, 100, 100, 100);- Switches color mode to Hue-Saturation-Brightness with ranges 0-360 for hue and 0-100 for saturation, brightness, and alpha, which makes rainbow color cycling much easier than RGB.
noStroke();- Disables outlines on shapes so only filled circles are drawn, keeping the orbs soft and clean.
centerX = width / 2;- Initializes the orbit center's x position to the middle of the canvas.
centerY = height / 2;- Initializes the orbit center's y position to the middle of the canvas.
initOrbs();- Calls the helper function that creates all 160 orb objects with random properties.
background(0);- Paints the canvas solid black once at the start so there's a clean base for the trail effect to build on.