setup()
setup() runs once when the sketch starts. It's the ideal place to build lookup arrays like neonColors and calculate values that depend on canvas size, like maxRadius.
function setup() {
createCanvas(windowWidth, windowHeight); // Create a canvas that fills the window
pixelDensity(1); // Set pixel density to 1 for consistent appearance across devices
// Add the neon colors to the palette
neonColors.push(color(0, 255, 255)); // Cyan
neonColors.push(color(255, 0, 255)); // Magenta
neonColors.push(color(255, 105, 180)); // Pink
// Determine the maximum radius a ring can reach, scaling with the window size
maxRadius = max(width, height) * 0.7;
}
Line-by-line explanation (6 lines)
createCanvas(windowWidth, windowHeight);- Creates a canvas that fills the entire browser window.
pixelDensity(1);- Forces the canvas to render at 1 pixel per pixel, avoiding blurry or overly heavy rendering on high-density screens.
neonColors.push(color(0, 255, 255)); // Cyan- Creates a p5 color object for cyan and adds it to the neonColors array.
neonColors.push(color(255, 0, 255)); // Magenta- Adds magenta to the color palette array.
neonColors.push(color(255, 105, 180)); // Pink- Adds pink to the color palette array.
maxRadius = max(width, height) * 0.7;- Sets how large a ring can grow before disappearing, based on whichever of width or height is bigger, scaled down to 70%.