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 › quick qn about for loop..
Page Index Toggle Pages: 1
quick qn about for loop.. (Read 731 times)
quick qn about for loop..
Aug 30th, 2009, 4:42am
 
hi.. i want to draw some circles using a class.. but i cant seem to draw them with a time delay between each one using the for loop..
the code below starts with one circle then nothing happens for a while and the rest of the circles appear altogether suddenly..
how do i control the time delay so that they will appear one by one slowly?

Code:

CIRCLES circles = new CIRCLES();

void setup()
{
 size(500,500);
 background(0);
}

void draw()
{
 circles.drawcircles();
}

class CIRCLES
{
 void drawcircles()
 {
   int x = width/10;
   for(int i=0;i<=x;i++)
   {
      ellipse( x*i,height/2, 50,50);
      delay(50);
   }
 }
}
Re: quick qn about for loop..
Reply #1 - Aug 30th, 2009, 6:31am
 
Classical problem with delay(): draw() will show something on screen only after all the code inside (including loops and delays...) is finished. At it will display all the resulting drawings at once!

Classical workaround: check time (or frame count), after a given time (current time - start time > given time), increment a counter and display the nth circle (and those before, if you use background()).
Page Index Toggle Pages: 1