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 › changing images after drawing them
Page Index Toggle Pages: 1
changing images after drawing them (Read 598 times)
changing images after drawing them
Jun 15th, 2006, 1:06am
 
hi,
I'm trying to use pixel arrays and PImage for the first time--I made a short test sketch to explain my question.


PImage img;
int counter = 0;

void setup() {
 size(400,400);
 img = new PImage(width,height);
 for (int i=0; i<img.pixels.length; i++) { // initialize img's pixels to white
   img.pixels[i] = color(255);
 }
}

void draw() {
 background(255);
 img.pixels[counter] = blend(img.pixels[counter],color(0,140,0),BLEND); // mix in green, one pixel per call to draw()
 if (counter>100) {
   image(img,0,counter/10);
 }
 counter++;
}


what confuses me is that it seems to ignore the updating of img.pixels once image() has been called for the first time. Why would this happen?

Or: what's the right way to make incremental changes to a pixel array behind the scenes and redraw the whole thing on every draw()?

thanks,
Neil
Re: changing images after drawing them
Reply #1 - Jun 15th, 2006, 7:24am
 
run img.updatePixels() after you've set them, that should fix your problem
Re: changing images after drawing them
Reply #2 - Jun 18th, 2006, 12:22am
 
I love questions with simple answers. Thanks!
Page Index Toggle Pages: 1