the code as following
let pg, div;
function setup() {
createCanvas(400,400);
pg = createGraphics(400,400);
div = createDiv();
}
function draw() {
pg.rect(50,50,50,50);
pg.fill("red");
pg.noStroke();
image(pg, 0, 0); // it works, the rect appears
div.size(400,400);
div.position(0, 0);
div.style("background","yellow"); // it works, the div appears
div.rect(40,40,40,40); // Error: div.rect is not a function
I am very confused about the instances pg
and div
, what is the difference between them. In my opinion, the pg
just like the Layer in Photoshop, we can draw something on it, and if we have a serval of pg
s, they are in order, but it seems that the pg
has to be rendered every time we draw somthing on it, in other words, if we have called image(pg, 0, 0)
(the only way to render the pg
?), the pg can’t update automatically even though we draw on it again unless we call image(pg, 0, 0)
again manually. So it is impossible or difficult for me to ceate dynamic design with pg
. And for div
, how can we draw something on it, or it is just like pg
?
Looking forward you guys reply, thanks so much !
PS: Why not give us learners the complete properties and methods for each Object, the [Reference] (reference | p5.js) is just something scattered, not systematic.