setup()
setup() runs exactly once when the sketch starts, making it the right place to size the canvas and configure one-time drawing settings like noStroke() and frameRate().
function setup() {
// Create a canvas that fills the remaining browser window height
// We need to account for the height of the h1 and its padding/margin
createCanvas(windowWidth, windowHeight - 100); // Adjusted canvas height slightly
// Set the background color to black
background(0);
// Do not draw outlines around shapes
noStroke();
// Set the animation speed to 30 frames per second
frameRate(30);
}
Line-by-line explanation (4 lines)
createCanvas(windowWidth, windowHeight - 100);- Makes a canvas as wide as the browser window and slightly shorter than the window's height, leaving room for the page's heading.
background(0);- Fills the canvas with solid black once, so the very first frame starts on a clean dark background.
noStroke();- Turns off outlines so every shape drawn afterward (the circles) has no border, just a solid fill.
frameRate(30);- Tells p5.js to try to run draw() 30 times per second, which sets the pace of the animation.