setup()
setup() runs once when the sketch starts, before draw() begins looping. It's the right place to configure canvas size and any drawing modes/defaults (like rectMode and textSize) that should apply for the entire sketch.
function setup(){createCanvas(windowWidth,windowHeight);rectMode(CENTER);textSize(20);}
Line-by-line explanation (3 lines)
createCanvas(windowWidth,windowHeight);- Creates a canvas that fills the entire browser window, so the scene scales to whatever screen it's viewed on.
rectMode(CENTER);- Tells p5.js to draw all future rectangles from their center point rather than their top-left corner - this makes it much easier to position and rotate the robot's body.
textSize(20);- Sets the default font size used later for the attempts counter and speech bubble text.