Skip to the content.

P5

From my stack overflow answer:

In P5, the setup function is called automatically one time when your program starts. This is a function that you should create so that your program is initialized correctly. Here are some important facts found in the docs:

[setup is] used to define initial environment properties such as screen size and background color and to load media such as images and fonts as the program starts. There can only be one setup() function for each program and it shouldn’t be called again after its initial execution.

Here are the P5 docs and reference for setup

Example:

function setup() {
    console.log('setup is called');
    createCanvas(400, 400);
}

You will probably also want to read the documentation for the draw function.

Here is a list of all the structure functions as found on the main reference index for the docs: