It’s not clear why you think this would work:
illustration.shapes[0]();
Nor why you think this would be able to draw to both the main canvas and your p5.Graphics
:
function s1() {
noFill();
stroke(255);
circle(mouseX, mouseY, 50);
}
Even if you fixed the fact that illustration.shapes
is undefined by doing something like illustration.shapes = shapes;
this still wouldn’t do what you want. All of the functions referenced in the s1
function (noFill
, stroke
, and circle
) are global functions that draw to the main canvas. In order to change this you would need to make the function support specifying an explicit target:
function s1(g) {
if (!g) {
g = window;
}
g.noFill();
g.stroke(255);
g.circle(mouseX, mouseY, 50);
}
Then when you call your shape functions, specify the target as an argument:
shapes[0](illustration);