setup()
setup() runs exactly once when the sketch first loads. It is the perfect place to initialize your canvas size, load images, and set starting values for variables. After setup() completes, the draw() function begins running.
function setup() {
createCanvas(windowWidth, windowHeight);
// Tip: Use windowWidth/windowHeight for responsive canvas
}
Line-by-line explanation (1 lines)
🔧 Subcomponents:
createCanvas(windowWidth, windowHeight);
Creates a canvas whose width and height match the current browser window dimensions
createCanvas(windowWidth, windowHeight);- Creates a canvas that spans the exact width and height of the browser window - windowWidth and windowHeight are special p5.js variables that always hold the current window size