setup()
setup() runs once when the sketch starts. Here it configures the color system (HSB), builds the reusable color palette, and establishes the maximum size a ring is allowed to reach based on the screen dimensions.
function setup() {
createCanvas(windowWidth, windowHeight);
// Use HSB for easier neon color control
colorMode(HSB, 360, 100, 100, 255);
noFill();
maxRadius = min(width, height) * 0.6;
// Neon color palette: pink, cyan, purple
palette = [
color(320, 100, 100), // neon pink
color(185, 100, 100), // cyan
color(270, 100, 100) // purple
];
background(0, 0, 0); // pure black (HSB: any hue, 0 sat, 0 bright)
}
Line-by-line explanation (6 lines)
createCanvas(windowWidth, windowHeight);- Makes the canvas fill the entire browser window.
colorMode(HSB, 360, 100, 100, 255);- Switches p5's color system to Hue-Saturation-Brightness with ranges 0-360, 0-100, 0-100, and alpha 0-255 - this makes it easy to pick vivid neon hues by just changing one number.
noFill();- Tells p5 not to fill any shapes with color, so the rings will only show as outlines (strokes).
maxRadius = min(width, height) * 0.6;- Calculates how large a ring is allowed to grow - 60% of whichever canvas dimension (width or height) is smaller, so rings never grow off-screen awkwardly.
palette = [color(320, 100, 100), color(185, 100, 100), color(270, 100, 100)];- Builds an array of three p5.Color objects representing neon pink, cyan, and purple, which will be randomly chosen for each new ring.
background(0, 0, 0);- Paints the canvas solid black once at the start, giving the animation a clean dark backdrop to begin with.