setup()
setup() runs exactly once when the sketch starts. It's the right place to configure things that don't change afterward, like canvas size and fonts.
function setup() {
// Full-window canvas: https://p5js.org/reference/#/p5/createCanvas
createCanvas(windowWidth, windowHeight);
textFont('sans-serif');
}
Line-by-line explanation (2 lines)
createCanvas(windowWidth, windowHeight);- Creates a canvas that exactly matches the browser window's current width and height, so the game fills the whole screen.
textFont('sans-serif');- Sets the default font for all text() calls in the sketch to a clean sans-serif typeface.