# Create random circles in a grid

**URL:** <https://discourse.processing.org/t/create-random-circles-in-a-grid/14976>\
**Category:** Coding Questions\
**Created:** [October 27, 2019, 11:07pm UTC](https://discourse.processing.org/t/create-random-circles-in-a-grid/14976 "2019-10-27T23:07:21Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [October 28, 2019, 1:55am UTC](https://discourse.processing.org/t/create-random-circles-in-a-grid/14976/3 "2019-10-28T01:55:02Z")

</div>

for knowing where you set a circle need some memory,

- minimal boolean[][] array,
- max a class.

and the grid position [cols][rows] to set  
could find by the random function.

```auto
int cols = 60, rows = 40, scale = 18;
boolean[][] setc = new boolean[cols][rows];

void setup() {
  size (1200, 800);
  ellipseMode(CORNER);
  preset();
  setrandom();
}

void draw() {
  drawgrid();
}

void preset() {
  for (int i = 0; i < cols; i++)
    for (int j = 0; j < rows; j++)
      setc[i][j] = false;
}

void setrandom() {
  int i = (int)random(cols);
  int j = (int)random(rows);
  setc[i][j] = true;
}

void drawgrid() {
  for (int i = 0; i < cols; i++) {
    for (int j = 0; j < rows; j++) {
      int x = i * scale;
      int y = j * scale;
      fill(#add8e6);
      stroke(0);
      rect(x, y, scale, scale);
      fill(200, 0, 0);
      noStroke();
      if ( setc[i][j] ) circle(x, y, scale);
    }
  }
}

```

here a different approach:  
[Creating Snake Game](https://discourse.processing.org/t/creating-snake-game/14954/4) ,

---

_[View the full topic](https://discourse.processing.org/t/create-random-circles-in-a-grid/14976)._
