setup()
setup() runs exactly once when the sketch starts. It's the right place to configure canvas size and any settings (like fonts or alignment) that should apply for the whole sketch.
function setup() {
createCanvas(windowWidth, windowHeight);
textAlign(CENTER, CENTER);
textFont('monospace');
}
Line-by-line explanation (3 lines)
createCanvas(windowWidth, windowHeight);- Creates a canvas that fills the entire browser window, so the stopwatch always uses the full available space.
textAlign(CENTER, CENTER);- Tells p5 to center text both horizontally and vertically around the x,y coordinates you give text(), which makes positioning the clock and button labels much easier.
textFont('monospace');- Switches to a monospace font so digits are all the same width - this prevents the clock display from jittering side to side as numbers change.