Is there a way to make a graphics element global, in p5js? Right now I want to make the ellipse be global:
var bug = ellipse(0, random(height), 20, 20);
function setup() {
createCanvas(500, 500);
background(100);
}
function draw() {
}
I want to store the ellipse in a variable. But there's an error saying that "mySketch.js, line 1:Uncaught ReferenceError: ellipse is not defined". Can someone help? Thanks.
The ellipse()
function draws an ellipse, but it doesn't return anything, so you can't store the result of calling it in a variable.
I'm not totally sure what you're trying to do, but you have a couple options worth exploring:
ellipseX
, ellipseY,
and ellipseSize
.p5.Graphics
and then store that p5.Graphics
in a global variable. You can find more info about this in the reference.