# Copying and spawning object from an array

**URL:** <https://discourse.processing.org/t/copying-and-spawning-object-from-an-array/39138>\
**Category:** Beginners\
**Created:** [October 7, 2022, 1:32pm UTC](https://discourse.processing.org/t/copying-and-spawning-object-from-an-array/39138 "2022-10-07T13:32:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shon121212](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@shon121212](https://discourse.processing.org/u/shon121212)\
**Post date:** [October 7, 2022, 1:32pm UTC](https://discourse.processing.org/t/copying-and-spawning-object-from-an-array/39138/1 "2022-10-07T13:32:09Z")

</div>

so what im trying to do is spawn a ball with some attributes and after 5 seconds i want to create spawn another one of this balls up untill 7 but im not sure how to “add” new ball to the array with the same attributes that i set up in the “setup” section ill include the part of the code:

```auto
Ellipse[] ball = new Ellipse[1];
int savedTime;
int timerTime = 5000;
void setup() {for (int i=0; i<ball.length; i++){
    ball[i] = new Ellipse();
    ball[i].radiusX=25;
    ball[i].radiusY=25;
    ball[i].x=width/2-ball[i].radiusX;
    ball[i].y=height/2-ball[i].radiusY;
    ball[i].brush=color(255, 0, 0);
    ball[i].direction=int(random(0,359));
    ball[i].brush = color(255,165,0);
    ball[i].pen = color(0,0,0);
    ball[i].penThickness = 3;
    ball[i].speed=5;
  }
}

void draw() {
int passedTime = millis() - savedTime;
for(int i =0;i<ball.length;i++){
//here im doing some actions on the ball itself i dont think it metters for that question so i wont include it 🙂 
if(passedTime>timerTime){
  ball = new Ellipse[i++];
  savedTime = millis();
  }
ball[i].draw();
}

```

---

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [October 7, 2022, 5:20pm UTC](https://discourse.processing.org/t/copying-and-spawning-object-from-an-array/39138/2 "2022-10-07T17:20:48Z")

</div>

> [@shon121212](#):
>
> Ellipse ball = new Ellipse[1];

Well, one thing is that you need to set aside 7 places in your array. Right now, you have only 1.  
Change Ellipse[1] to Ellipse[7].  
🤓
