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 › Simple Question...I think...
Page Index Toggle Pages: 1
Simple Question...I think... (Read 230 times)
Simple Question...I think...
Nov 20th, 2008, 9:29pm
 
OK...I'm very new to Processing and have tried to apply some old programming skills to this new language and for the life of me cannot understand why this simple program does not work. What I am trying to do is simply create a white rectangular block the turns on and off every .5 seconds. Here's the code I am using:

Code:

void setup ()
}
 size (300,250);
 background (0);
 fill (255);
}

void draw ()
{
 rect (50,50,200,150);
 delay (500);
 background (0); //Isn't this like a clear screen?
 delay (500);
}

What am I missing folks? Thanks in advance for the assist. I know I'm going to kick myself when someone reveals the answer.
Re: Simple Question...I think...
Reply #1 - Nov 20th, 2008, 10:58pm
 
My answer to Stopping/drawing during a for loop might help you, I think... And no, it is not obvious... until you know it! Wink
Re: Simple Question...I think...
Reply #2 - Nov 20th, 2008, 11:03pm
 
you are missing the fact that processing only updates the screen at the end of the draw() method so you'll only ever see the blackness.

try (and this is untested)

Code:

boolean c = true;

// setup here

draw() {
background (0);
if (c) {
// draw rectangle
rect (50,50,200,150);
}
// flip
c = !c;
// wait
delay(500);
}
Re: Simple Question...I think...
Reply #3 - Nov 20th, 2008, 11:04pm
 
(foiled by philho, again...) 8)
Re: Simple Question...I think...
Reply #4 - Nov 20th, 2008, 11:54pm
 
koogy wrote on Nov 20th, 2008, 11:03pm:
you are missing the fact that processing only updates the screen at the end of the draw() method so you'll only ever see the blackness.

try (and this is untested)

Code:

boolean c = true;

// setup here

draw() {
 background (0);
 if (c) {
   // draw rectangle
   rect (50,50,200,150);
 }
 // flip
 c = !c;
 // wait
 delay(500);
}


This worked perfectly and was a very simple solution. Thanks so much. Now off to analyze the code and understand exactly why it works (btw...thanks for the remark statements).
Page Index Toggle Pages: 1