# Repeat the same random positions of ellipses after n seconds

**URL:** <https://discourse.processing.org/t/repeat-the-same-random-positions-of-ellipses-after-n-seconds/36771>\
**Category:** p5.js\
**Created:** [May 8, 2022, 7:33pm UTC](https://discourse.processing.org/t/repeat-the-same-random-positions-of-ellipses-after-n-seconds/36771 "2022-05-08T19:33:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![celinewassmer](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@celinewassmer](https://discourse.processing.org/u/celinewassmer)\
**Post date:** [May 8, 2022, 7:33pm UTC](https://discourse.processing.org/t/repeat-the-same-random-positions-of-ellipses-after-n-seconds/36771/1 "2022-05-08T19:33:31Z")

</div>

Hi there!

I’m workiung with the following code in p5js to make an animation of ellipses (raindrops). In the end I want to loop my video (screen recording). So the positions of the ellipses have to be in the same position after 8 sec as they are in the beginning… As the position of the ellipses are random, I want to repeat those random positions after 8 seconds. I tried to work with randomSeed(), but it did not work somehow.

code:  
\</\>  
let drops = []; // group of Drop

function setup() {  
createCanvas(windowWidth, windowHeight);  
//stroke(255);  
noFill();  
}

function draw() {  
background(0, 0, 0, 20);

```
if(frameCount % 3 == 0) { //every 3th frame
	//drops.push(new Drop(mouseX, mouseY));
	drops.push(new Drop(random(width), random(height)));
}

for(d of drops) {
	d.display();
	d.grow();

}

```

}

//function mouseDragged() {  
// drops.push(new Drop(mouseX, mouseY));  
//}

class Drop {  
constructor(xPos, yPos) { //initialize class  
this.xPos = xPos;  
this.yPos = yPos;  
this.size = 0;  
this.sizeMax = random(100, 200);  
this.fc = 0; // custom framecount  
this.stroke = 255;  
}

```
display() {
	stroke(255);
	ellipse(this.xPos, this.yPos, this.size);
}

grow() {
	this.size = sin(this.fc * .015) * this.sizeMax;
	this.fc++; // grow by 1
	

	if(this.size >= this.sizeMax - 1) {
		this.remove();
	}
}

remove() {
	drops.splice(drops.indexOf(this), 1);
}

```

}  
\</\>

I’d be very thankful if someone could help me 🙂

---

<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:** [May 8, 2022, 8:19pm UTC](https://discourse.processing.org/t/repeat-the-same-random-positions-of-ellipses-after-n-seconds/36771/2 "2022-05-08T20:19:20Z")

</div>

Hello,

Please format your code as a courtesy to the community:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

This worked for me:

1. In _setup()_:

```auto
randomSeed(99); // You can change the seed to anything you want and save it to use again when you repeat!

```

1. With a key press:

```auto
function keyPressed()
  {
  drops = []; // Clears array of objects
  randomSeed(99); // sets the same initial randomSeed for next cycle
  }

```

I will leave the timer for you… lots of examples out there.

Reference:  
[https://2ality.com/2012/12/clear-array.html](https://2ality.com/2012/12/clear-array.html)  
[https://p5js.org/reference/#/p5/randomSeed](https://p5js.org/reference/#/p5/randomSeed)

`:)`
