Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use of delay() in Processing Environment

Tags:

processing

I am using Processing language to sketch a rectangle that grows in size with time. Following code is not giving any output.

void setup()
{
    size(900,900);
}
void draw()
{
    int edge=100;
    for(int i=0;i<300;i++)
    {
        delay(100);  
        edge++;      
        rect(100,100,edge,edge);
    }
}

I suspect having wrongly used delay() function.

like image 259
dev Avatar asked Jul 14 '13 09:07

dev


1 Answers

Here is one such "roll your own" delay method which is good for most purposes. Just change the values passed into the delay method to alter the timing. This just outputs "start" and "end" roughly every 2 seconds for example.

void draw()
{
  System.out.println("start");
  delay(2000);
  System.out.println("end");
  delay(2000);
}

void delay(int delay)
{
  int time = millis();
  while(millis() - time <= delay);
}
like image 100
cditcher Avatar answered Sep 23 '22 01:09

cditcher