# Draw ellipse after 2 sec

**URL:** <https://discourse.processing.org/t/draw-ellipse-after-2-sec/27792>\
**Category:** Coding Questions\
**Created:** [February 13, 2021, 2:18pm UTC](https://discourse.processing.org/t/draw-ellipse-after-2-sec/27792 "2021-02-13T14:18:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vestergaard12](https://avatars.discourse-cdn.com/v4/letter/v/c67d28/32.png) [@vestergaard12](https://discourse.processing.org/u/vestergaard12)\
**Post date:** [February 13, 2021, 2:18pm UTC](https://discourse.processing.org/t/draw-ellipse-after-2-sec/27792/1 "2021-02-13T14:18:15Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [February 13, 2021, 2:27pm UTC](https://discourse.processing.org/t/draw-ellipse-after-2-sec/27792/2 "2021-02-13T14:27:43Z")

</div>

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

Then you can use `background()` still

---

<div class="post-metadata">

**Author:** ![vestergaard12](https://avatars.discourse-cdn.com/v4/letter/v/c67d28/32.png) [@vestergaard12](https://discourse.processing.org/u/vestergaard12)\
**Post date:** [February 13, 2021, 3:35pm UTC](https://discourse.processing.org/t/draw-ellipse-after-2-sec/27792/5 "2021-02-13T15:35:20Z")

</div>

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