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 & HelpPrograms › Image Creating: Is this the right way
Page Index Toggle Pages: 1
Image Creating: Is this the right way? (Read 328 times)
Image Creating: Is this the right way?
Apr 6th, 2006, 6:42pm
 
I have a model which draws a lot of lines (6,400 of them).  They don't move during the draw() frames, so I thought maybe I should just capture the display after I first draw them, then use image() in the draw() routine.

After a bit of experiment, I found the attached worked.  But I didn't find a code segment showing this so am wondering if this is really the right way to do it.  Is this reasonable, or is there a better way to do it?  I did need to copy the bits, for example, but was a bit puzzled as to why.

Thanks

Quote:
void setup() {
   ...
 // stunt: capture the lines as an image
 background(128);
 for(int i = 0; i<lines.size(); i++) {
   ((Line)lines.get(i)).paint();
 }
 loadPixels();
 imgpixels = new int[pixels.length];
 arraycopy(pixels,imgpixels);
 img = new PImage(imgpixels, width, height, RGB);
}
void draw() {
 image(img,0,0);
   ...
}

Page Index Toggle Pages: 1