# How to add to an ArrayList every x seconds?

**URL:** https://discourse.processing.org/t/how-to-add-to-an-arraylist-every-x-seconds/31609
**Category:** Coding Questions
**Created:** [August 7, 2021, 10:01am UTC](https://discourse.processing.org/t/how-to-add-to-an-arraylist-every-x-seconds/31609 "2021-08-07T10:01:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![chaotic.rabbit](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chaotic.rabbit/32/14034_2.png) [@chaotic.rabbit](https://discourse.processing.org/u/chaotic.rabbit)
#### Post date: [August 7, 2021, 10:01am UTC](https://discourse.processing.org/t/how-to-add-to-an-arraylist-every-x-seconds/31609/1 "2021-08-07T10:01:20Z")

</div>

void setup(){  
jellies = new ArrayList();  
for(int i=0; i\<=5; i++){  
jellies.add(new Jellyfish(random(0, 800), random(height), random(-40, 40), random(0.05, 0.35)));  
}

for(int i = jellies.size()-1; i\>=0; i–){  
Jellyfish jellyfish = jellies.get(i);  
jellyfish.display();

}

if(millis()-timer\>=2000){  
jellies.add(new Jellyfish(random(0, 800), 850, random(-40, 40), random(0.05, 0.35)));  
timer=millis();  
}

The above is just part of the code. I would like to display a new jellyfish coming from the bottom of the screen every 5 seconds. At first it works but after a while they start popping in the middle of the screen and stop completely.

Thanks!!

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [August 7, 2021, 11:29am UTC](https://discourse.processing.org/t/how-to-add-to-an-arraylist-every-x-seconds/31609/2 "2021-08-07T11:29:14Z")

</div>

Hello,

A good place to start:

> **Click here for resources**
>
> I encourage you to look at the resources available here:
> 
> **Beginner**
> 
> - The Processing website has _references_ , _examples_ , _tutorials_ , etc.  
> [https://processing.org/](https://processing.org/)
> - The Processing PDE (IDE) has lots to offer!  
> An exploration of the menu items will reveal what is available!  
> You will find _libraries_ , _tools_ , _examples_ and more!  
> For example:  
> ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/d1f59b878cb30a4047dbfd8407702c77bc49bca6.png)
> - The Coding Train  
> [https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1\_aw](https://www.youtube.com/channel/UCvjgXvBlbQiydffZU7m1_aw)  
> [https://thecodingtrain.com/](https://thecodingtrain.com/)
> - Happy Coding  
> [https://happycoding.io/tutorials/processing/](https://happycoding.io/tutorials/processing/)
> 
> **Advanced**
> 
> - The source code can give insight if you are adventurous:  
> [GitHub - processing/processing: Source code for the Processing Core and Development Environment (PDE)](https://github.com/processing/processing)  
> Many of the Processing functions are here:  
> [https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java](https://github.com/processing/processing/blob/master/core/src/processing/core/PApplet.java)
> - And the Internet.

_ **Please** _ format your code:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

You need to understand some basic elements before you begin:

- [Variable Scope / Examples / Processing.org](https://processing.org/examples/variablescope.html)
- [setup() / Reference / Processing.org](https://processing.org/reference/setup_.html)
- [draw() / Reference / Processing.org](https://processing.org/reference/draw_.html)

Check out out the tutorials, examples and references and there you will find what you need.

Get a basic timer working first and then use that to add to the [ArrayList](https://processing.org/reference/ArrayList.html).

`:)`
