When can you use cos and sin outside of setup or draw

I’ve changed your post to the p5.js forum category then. :expressionless:

p5js is a diff. flavor beast. :bear:

Indeed, none of its API is available until either it finds out that setup() or draw() is in the global context (window) or we manually instantiate class p5: new p5; :cowboy_hat_face:

new p5; // prematurely instantiate class p5. ;-)

const SQRT_3 = sqrt(3); // we can access p5's sqrt() method outside functions!

function setup() {
	print(SQRT_3);
}

For cos() & sin() and similar, we can always directly rely on the class Math: :bulb:

const SQRT_3 = Math.sqrt(3); // Directly accessing JS' Math method sqrt().

function setup() {
	print(SQRT_3);
}
2 Likes