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 › basic issue reloading loop
Page Index Toggle Pages: 1
basic issue reloading loop (Read 601 times)
basic issue reloading loop
Dec 2nd, 2009, 8:25pm
 
i am used to basic arduino and wonder why this loop get stuck at red fill and doesn't restart from green:
void draw() {
   fill(green);
   rect(25, 25, 50, 50);
   delay(500);
   fill(red);
   rect(25, 25, 50, 50);
   delay(500);
}
Re: basic issue reloading loop
Reply #1 - Dec 2nd, 2009, 9:45pm
 
I mean all I need to know is having a rectangle to blink (alternating different colours)
Re: basic issue reloading loop
Reply #2 - Dec 2nd, 2009, 10:34pm
 
It doesnt work like that... just think of it as a list of commands that are executed before the final image/frame is shown to the screen.

So when you do it like you do, you draw a red over a green rectangle at the same position.

there are different ways to achieve what you want.
the easiest probably would be to use modulo http://processing.org/reference/modulo.html
where the first number is always the frames of one colorcylce and the second one the half of it (frames one color is shown, if you change it to 10 for example, red is shown 40, yellow 10 frames)


like this :

void draw() {
  fill(#ff0000);
  if(frameCount%50<=25)fill(#ffff00);
  rect(25, 25, 50, 50);  

you shouldnt use delay like you are used to use it in arduino
Re: basic issue reloading loop
Reply #3 - Dec 3rd, 2009, 3:47am
 
elegant!
Page Index Toggle Pages: 1