The setup() Function : At the beginning of a p5.js program, the p5.js library
automatically executes the setup()
function. The setup()
function should not be explicitly called in the sketch.
function setup() {
// Runs once at the beginning of the p5.js sketch
}
Uses of the setup() Function : The setup()
function typically contains code that defines the initial state of the sketch, such as the canvas size, background color, and initial values of global variables.
let beginSize;
// Initializing the canvas size, background color and beginlSize value
function setup() {
createCanvas(800, 600);
background(220);
beginSize = 5;
}