We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Here's an example sketch to explain the question:
float x1 = 0;
float y1 = 0;
void setup () {
size(400,400);
background(255);
}
void draw() {
background(255); // I want this to effect only one of the rectangles
rect(x1, 200, 10, 10);
x1 += 1;
rect(200, y1, 10, 10); // want to see the trail of each shape drawn every loop
y1 += 1;
}
How would I write this code so you the second set of rectangles being drawn every loop, but appear to remove all of the previous shapes drawn from the first rectangle? I want the first rect shape to appear to be moving across the screen while the second rect appears to be dragging a trail across the screen.
Answers
https://processing.org/reference/PGraphics.html
Thank you. Is there a good way to use PGraphics with objects? Seems like PGraphics has to be called within the object. I would like to call a few different objects within one PGraphics layer.
PGraphics is an extra canvas. We can draw in it and then use image() to stamp it in the main canvas.
I gathered that. This is what I was talking about. https://processing.org/discourse/beta/num_1257179630.html
Like that thread shows, you can just keep a reference to the PGraphics in the object, so that you can use it in the object's draw() method. Alternatively, you could pass the PGraphics to the object's draw(PGraphics pg) method. If you have a lot of objects, it is most efficient to call begin/endDraw once outside the individual objects and only draw to the PGraphics within each object (instead of also calling begin/endDraw from within each individual object).
Learn how to format code on this forum here: http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text#Item_1
Thank you.