Draw ellipse after 2 sec

Hello Processing foundation
I want my code to create new random (x,y) ellipses with an interval of 2 seconds.
So when you start the code it will after two seconds draw an ellipse (at a random(x,y)), and then after another 2 seconds it will draw another ellipse (at a random(x,y)) but without deleting the previously drawn ellipse.

This is my code so far:

int startTime;
final int DISPLAY_DURATION = 2000; 

void setup(){
  size(600, 400);
  startTime = millis();
}
 
void draw(){
 background(180);
 if (millis() - startTime > DISPLAY_DURATION) {
     fill(random(0,255),random(0,255),random(0,255));
      ellipse(random(0,600),random(0,400),20,20);
      startTime = millis();
    }
}

This code works if you just remove the background(180) at draw() and put it into setup() but this is not the way I want to do it.

In theory you would store all ellipses in an arraylist (every 2 seconds) and
display the arraylist

Then you can use background() still

Thank you very much
I have now figured out how to do this :slight_smile:

2 Likes