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 › What is wrong with this updatePixels() code
Page Index Toggle Pages: 1
What is wrong with this updatePixels() code? (Read 291 times)
What is wrong with this updatePixels() code?
Jul 28th, 2008, 4:11pm
 
Hello wise forum,

What's wrong with the following code?
I'm expecting the screen to get more and more red subtly,
but it starts as a black screen, stays black for a while,
and then suddenly turns into totally bright red.

I know there are better ways to do this;
I've just come across this while working on a project,
and got just curious why this doesn't work.

It seems updatePixels() doesn't work in for loops.
Is that so?

Thanks -


void setup() {
 size(400,400);
}

void draw() {
 for (int j=0;j<256;j++) {
   loadPixels();
   for (int i=0;i<width*height;i++) {
     pixels[i]=color(j,0,0);
   }
   updatePixels();
   delay(10);
 }
}
Re: What is wrong with this updatePixels() code?
Reply #1 - Jul 28th, 2008, 4:54pm
 
The screen only updates once draw() has finished, regardless of the use of updatePixels() or delay().

see http://processing.org/reference/delay_.html
Because the screen is updated only at the end of draw(), the program may appear to "freeze", because the screen will not update when the delay() method is used.
Re: What is wrong with this updatePixels() code?
Reply #2 - Jul 29th, 2008, 2:20am
 
Got it. Thanks!
Page Index Toggle Pages: 1