We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › How to use multiple PGraphics objects
Page Index Toggle Pages: 1
How to use multiple PGraphics objects (Read 365 times)
How to use multiple PGraphics objects
Apr 5th, 2008, 3:04pm
 
Hello

Is there a way to draw on multiple PGraphics canvases simultaneously?

If I define a single PGraphics canvas as follows:

PGraphics canvas = createGraphics(80, 80, P3D);

can I define canvas somehow as an array or list of objects, so that ideally I could use commands such as:

canvas[0].beginDraw();
canvas[0].rect(0,0,2,2);
...
canvas[1].beginDraw();
canvas[1].ellipse(0,0,2,2);
...

If this is possible, then how must I define or initialize canvas?

Also, if one then has several canvases, is there a quick way to copy the contents of one to another?

Thank you very much for your help!

Michael







Re: How to use multiple PGraphics objects
Reply #1 - Apr 5th, 2008, 9:42pm
 
You can simple create an PGraphics array where you initialize your PGraphics objects in a for loop:

Code:

void setup(){
size(800,80);
PGraphics[] canvas = new PGraphics[10];
for(int i=0;i<canvas.length; i++){
canvas[i]=createGraphics(80, 80, P3D);
}
for(int i=0;i<canvas.length; i++){
canvas[i].beginDraw();
canvas[i].rect(0,0,2,2);
canvas[i].endDraw();
image(canvas[i], 80*i, 0);
}
}
Re: How to use multiple PGraphics objects
Reply #2 - Apr 6th, 2008, 9:19am
 
great! it works! thank you so much....
Page Index Toggle Pages: 1