I’m finding that some everyday p5.js methods are not bound to a p5 canvas in the way that I expected. But they are all bound ok to a
p5.Graphics created with
So, if I create a canvas, with
let canvas1 = createCanvas(500,500, P2D);
I expected that the following lines would work equivalently …
colorMode(RGB); canvas1.colorMode(RGB); let tgt = canvas1; tgt.colorMode(RGB);
but in fact only the first bare “colorMode()” works, the next two fail with …
Uncaught TypeError: canvas.colorMode is not a function
Here’s a sketch showing the problem.
You can comment/uncomment the calls annotated ??? to see the issue.
The context is, I want to render a version of a scene on-screen, in a canvas say 1200 x 900, and render a much higher-resolution in an offscreen p5.Graphics buffer, say 12000 x 9000, and then save the high-def buffer to a file with
saveCanvas(). The offscreen rendering and saving all works fine, but it would be convenient to use the same rendering sequence and just change the render “target”, as shown, ie .
tgt = canvas; renderScene(tgt); tgt = buffer; renderScene(tgt);
My impression is that this is an intended functionality of p5.js, it seems to be shown at points in the examples and tutorials, but its implementation seems to be inconsistent.
canvas.colorMode() and the others think they’re doing.
Thanks for any comments.
Regards, Greg E.