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 › delay() and the draw() method
Page Index Toggle Pages: 1
delay() and the draw() method (Read 821 times)
delay() and the draw() method
Sep 25th, 2009, 1:35pm
 
I found the page on delay()
web ref:processing.org/reference/delay_.html
but there is no info here on how to use it outside of the draw() method

What is proper way to write this program so that it draws a line every half second


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

void draw()
{
   background(0);
   for (int i = 2; i < 150; i++) {
     line(0,i*sin(i)*5, 500, i*cos(i)*3);
     stroke(160, 0, 0);
     delay(500);
   }
 
}
Re: delay() and the draw() method
Reply #1 - Sep 25th, 2009, 2:26pm
 
delay() is to be used rarely... In general, draw() heartbeat is used to count time.
Code:
int count = 2;

void setup()
{
size(500, 500);
background(0);
stroke(160, 0, 0);
frameRate(2); // Twice per second
}

void draw()
{
// background(0);
// for (int i = 2; i < 150; i++) {
if (count < 150)
{
line(0, count * sin(count) * 5, 500, count * cos(count) * 3);
count++;
}
}
Page Index Toggle Pages: 1