setup()
setup() runs once at the start and is the right place to configure the canvas, create DOM elements like inputs, and initialize arrays that won't change shape later - only their contents (like which color is selected) change over time.
function setup() {
createCanvas(windowWidth, windowHeight);
textAlign(CENTER, CENTER); textStyle(BOLD); noStroke();
inp = createInput("NEON"); inp.position(20, 20); inp.size(200);
cols = [color(255, 60, 200), color(0, 255, 255), color(0, 255, 120)];
}
Line-by-line explanation (4 lines)
createCanvas(windowWidth, windowHeight);- Makes the canvas fill the entire browser window.
textAlign(CENTER, CENTER); textStyle(BOLD); noStroke();- Sets text to be centered both horizontally and vertically, makes it bold for a chunkier neon look, and disables outlines so shapes only use fill color.
inp = createInput("NEON"); inp.position(20, 20); inp.size(200);- Creates an HTML text input box pre-filled with the word 'NEON', places it near the top-left corner, and sets its width to 200 pixels. This is a p5.js DOM element, not something drawn on the canvas.
cols = [color(255, 60, 200), color(0, 255, 255), color(0, 255, 120)];- Builds an array of three p5.Color objects - hot pink, cyan, and green - that the sign will cycle through when clicked.