p5 variables such as width and height, and p5 functions such as rect() and fill() can be used outside setup() and draw() as long as they’re in a function that is called from within either setup() or draw()
right?
For example:
function setup() {
createCanvas(600, 600);
background(30);
}
function draw() {
myRectangle();
}
function myRectangle() {
fill(150);
rect(width / 2, height / 2, 200, 200);
}
I mean I can see it works when I test it, and have done it all the time, but I’m wondering if there are any gotchas or situations in which it should be avoided or that we should be careful.
One thing I do know is that createCanvas() needs to be called first. But that’s true even when using the p5 variables and functions directly inside setup().