setup()
setup() runs once when the sketch starts. It's where you initialize your canvas, set up colors, and prepare any data structures you'll use throughout the sketch. Using HSB color mode here makes it much easier to work with vibrant neon colors.
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)
}
π§ Subcomponents:
createCanvas(windowWidth, windowHeight)
Creates a canvas that fills the entire browser window
colorMode(HSB, 360, 100, 100, 255)
Switches to HSB (Hue, Saturation, Brightness) color mode for easier neon color control, with hue 0-360, saturation 0-100, brightness 0-100, and alpha 0-255
maxRadius = min(width, height) * 0.6
Sets the maximum radius to 60% of the smaller dimension, ensuring rings fit within the canvas
palette = [color(320, 100, 100), color(185, 100, 100), color(270, 100, 100)]
Creates an array of three vibrant neon colors: pink, cyan, and purple for random selection
Line by Line:
createCanvas(windowWidth, windowHeight)- Creates a canvas that fills the entire browser window. windowWidth and windowHeight are p5.js variables that automatically get the window dimensions
colorMode(HSB, 360, 100, 100, 255)- Switches from RGB to HSB color mode. HSB makes it easier to create neon effects because you control hue (color), saturation (intensity), and brightness separately
noFill()- Disables fill for all shapes, so only the stroke (outline) will be drawn. This is essential for creating ring outlines
maxRadius = min(width, height) * 0.6- Calculates the maximum radius rings can grow to. It uses the smaller of width or height, then multiplies by 0.6 so rings don't exceed canvas boundaries
palette = [color(320, 100, 100), color(185, 100, 100), color(270, 100, 100)]- Creates an array of three neon colors: hue 320 (pink), hue 185 (cyan), and hue 270 (purple). All have maximum saturation and brightness for that neon glow
background(0, 0, 0)- Sets the initial background to pure black. In HSB mode, this means hue 0, saturation 0, brightness 0