# Random circles using arrays

**URL:** https://discourse.processing.org/t/random-circles-using-arrays/6536
**Category:** Coding Questions
**Created:** [December 12, 2018, 12:26pm UTC](https://discourse.processing.org/t/random-circles-using-arrays/6536 "2018-12-12T12:26:10Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Jrekz](https://avatars.discourse-cdn.com/v4/letter/j/ed655f/32.png) [@Jrekz](https://discourse.processing.org/u/Jrekz)
#### Post date: [December 12, 2018, 12:26pm UTC](https://discourse.processing.org/t/random-circles-using-arrays/6536/1 "2018-12-12T12:26:10Z")

</div>

Hello,

So I have these tasks: 1. When the sketch starts, a circle with a random size, position and border color is  
displayed in the window and a first circle with a radius of 10 pixels on the mouse  
position.  
2. Every two seconds a new circle with a random border color (no white!) and  
random radius (between 10 and 50) will appear at a random position in the  
window.

So far, I have this:

```auto
int counter=120;
int numCircles = 50;
int x, y;
int[] myArr = new int[numCircles];

void setup() {
  size(500, 500);
  initializeArray(myArr);
}

void initializeArray(int[] someArr) {
  for (int i=1; i < someArr.length; i++) {
    someArr[0] = 10;
    someArr[i] = (int)random(10, 50);
  }
  printArray(someArr);
}

void draw() {
  background(255); 
  //ellipse(mouseX, mouseY, 10, 10);
  generateCircles(myArr);
}

void generateCircles(int[] someArr) {
  x = (int)random(width);
  y = (int)random(height);
  for (int i=1; i < someArr.length; i++) {
    drawCircle(x, y, someArr[i]);
  }
}

void drawCircle(int x, int y, int radius) {
  for (int i=0; i <= counter; i++) {
    stroke((int)random(255));
    ellipse(x, y, radius, radius);
  }
}

```

The issues I’m currently facing are those: 1. Framerate seems to be 240fps instead of default 60, although I haven’t changed it neither in the code nor settings.  
2. When I try to draw an ellipse in the mouse position, it updates at the same time as the other circles (these are updating using counter), it doesn’t matter where I put the command.  
3. Circles with random position are drawn on top of each other 2-3 times and then moves all together instead of drawing one every 2 seconds.

Any advice?

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [December 12, 2018, 1:13pm UTC](https://discourse.processing.org/t/random-circles-using-arrays/6536/2 "2018-12-12T13:13:39Z")

</div>

> [@Jrekz](#):
>
> 1. Framerate seems to be 240fps instead of default 60, although I haven’t changed it neither in the code nor settings.

try

```auto
void draw() {
  background(255);
  fill(0);
  text(nf(frameRate,1,1),width-100,20);
  noFill();
  generateCircles(myArr);
}

```

to see your actual frame rate.  
and

```auto
  frameRate(0.5);

```

in setup to change it.

1. drawing a circle on mouseclick would be

```auto
void mousePressed() {
 ellipse(mouseX, mouseY, 10, 10); 
}

```

could be a idea, but just for 1/60 sec  
as the background erases it / anyhow not the job ? at start?? mouse position

1. yes,

- you draw many circles at the same position with generateCircles
- you draw these 60 times per second so it looks like they are jumping around  
but if you disable background you see 60 times this concentric circles add up per second…

so over all you add 2 \* 60 \* ?50? circles  
instead 1  
every 2 secs
