setup()
setup() runs once when the sketch starts. It's the place to configure the canvas and call any initialization helpers before the animation loop begins.
function setup() {
createCanvas(windowWidth, windowHeight);
pixelDensity(1); // keeps get(x, y) sampling simple on high-DPI screens
initCircles();
}
Line-by-line explanation (3 lines)
createCanvas(windowWidth, windowHeight);- Creates a canvas that fills the entire browser window, using p5's built-in windowWidth and windowHeight variables.
pixelDensity(1); // keeps get(x, y) sampling simple on high-DPI screens- Forces the canvas to use a 1:1 pixel density instead of the device's native (often 2x or 3x) density, so get(x, y) reads exactly the pixel you expect on Retina/high-DPI screens.
initCircles();- Calls the helper function that sets up the starting positions and sizes of the three RGB circles.