setup()
setup() runs once when the sketch starts. It's the right place to size the canvas, configure text styles, and set up any starting state before the animation loop takes over.
function setup(){
createCanvas(windowWidth,windowHeight);
textFont('monospace');textSize(16);
nest=createVector(width*0.8,height*0.5);
reset();
}
Line-by-line explanation (4 lines)
createCanvas(windowWidth,windowHeight);- Makes the canvas fill the entire browser window so the scene scales to any screen size.
textFont('monospace');textSize(16);- Sets the font used for the delivery counter text and how big it should be drawn.
nest=createVector(width*0.8,height*0.5);- Places the nest 80% of the way across the screen and vertically centered - this is the ant's permanent goal.
reset();- Calls the reset function to build the first ant and the first set of obstacles before the draw loop starts.