setup()
setup() runs once when the sketch starts and is the ideal place to configure drawing modes and defaults (like text alignment and size) that will apply throughout the whole sketch.
function setup(){
createCanvas(windowWidth,windowHeight);
textAlign(CENTER,CENTER);
textSize(32);
rectMode(CENTER);
}
Line-by-line explanation (4 lines)
createCanvas(windowWidth,windowHeight);- Creates a canvas that fills the entire browser window, using windowWidth and windowHeight so it adapts to any screen size.
textAlign(CENTER,CENTER);- Makes all future text() calls center their text both horizontally and vertically around the given x,y coordinate - handy for centered titles.
textSize(32);- Sets the default font size in pixels for all text drawn afterward, like the countdown number and excuses.
rectMode(CENTER);- Changes rect() so its x,y arguments describe the shape's CENTER instead of its top-left corner, which makes positioning the rocket's body and pad much easier.