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 › pixel color offscreen with shape functions
Page Index Toggle Pages: 1
pixel color offscreen with shape functions (Read 344 times)
pixel color offscreen with shape functions
Jun 8th, 2008, 6:24pm
 
I might be missing something obvious, but I'm having trouble getting pixel colors out of the pixel array of an offscreen instance.

Quote:


PGraphics b;
color[]cols;

void setup() {
 size(400,400);
 loadPixels();
 b = createGraphics(400,400,P3D);
 b.loadPixels();
 b.fill(255, 0, 0);
 b.rect(0,0,400,400);
 b.updatePixels();
}

void draw() {
 /*
 for(int x=0; x<width; x++) {
   for(int y=0; y<height; y++) {
     b.pixels[y*width+x] = color((int)random(255),(int)random(255),(int)random(255));
   }
 }
 */
 arraycopy(b.pixels, pixels);
 updatePixels();
 int ran = (int)random(b.pixels.length);
 println(red(b.pixels[ran]) + " : " + green(b.pixels[ran]) + " : " + green(b.pixels[ran]));
}



Shouldn't it give me a red pixel? It works if you set the pixels directly (the commented section).
Re: pixel color offscreen with shape functions
Reply #1 - Jun 8th, 2008, 8:13pm
 
Instead of calling b.loadPixels() and b.updatePixels() in your setup, you have to call b.beginDraw() and b.endDraw().
Re: pixel color offscreen with shape functions
Reply #2 - Jun 9th, 2008, 3:43am
 
Right, I forgot about that. Thanks. I feel pretty stupid.
Page Index Toggle Pages: 1