I want to have two PGraphics instances and create an image for each separately.
I wanted to prevent the creation of two different images due to changes in the argument contents during a long draw() execution, so I applied the same drawing method to two PGraphics instances in succession, but two different An image will be created.
In the method draws() below, the right and left halves of the image are intended to alternate between light and dark slowly, but the result is not as it should be.
PGraphics pgL,pgR;
int i = 0;
boolean f = true;
void setup()
{
size(1000, 500, P2D);
background(0);
pgL = createGraphics(500, 500, P3D);
pgR = createGraphics(500, 500, P3D);
}
void draw(){
if(f == true){
draws(i);
i++;
if(i==255) f = false;
} else {
draws(i);
i--;
if(i==0) f = true;
}
image(pgL, 0, 0);
image(pgR, 500, 0);
}
void draws(int i)
{
pgL.beginDraw();
pgR.beginDraw();
pgL.background(i);
pgR.background(i);
pgL.endDraw();
pgR.endDraw();
}
If I change the inside of the method draws() as follows, it works as intended.
void draws(int i)
{
pgL.beginDraw();
pgL.background(i);
pgL.endDraw();
pgR.beginDraw();
pgR.background(i);
pgR.endDraw();
}
If I want to execute the methods beginDraw (), endDraw () for different PGraphics instances, do I still have to execute beginDraw () after endDraw ()?
Do I need to execute a method inside a PApplet instance, for example, to successively execute beginDraw () or other drawing methods?
Where can I find a tutorial on such coding?