# Trying to loop circles and make them disappear when hovered over

**URL:** https://discourse.processing.org/t/trying-to-loop-circles-and-make-them-disappear-when-hovered-over/9612
**Category:** Coding Questions
**Created:** [March 25, 2019, 3:33pm UTC](https://discourse.processing.org/t/trying-to-loop-circles-and-make-them-disappear-when-hovered-over/9612 "2019-03-25T15:33:20Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![longhorn392](https://avatars.discourse-cdn.com/v4/letter/l/f19dbf/32.png) [@longhorn392](https://discourse.processing.org/u/longhorn392)
#### Post date: [March 25, 2019, 3:33pm UTC](https://discourse.processing.org/t/trying-to-loop-circles-and-make-them-disappear-when-hovered-over/9612/1 "2019-03-25T15:33:20Z")

</div>

Hey guys I’m new to processing and working on a project for class. I’ve made a main file and one in a new tab for my object class Circle.

```auto
Circle[] circle = new Circle[20];

void setup() {
  size(1280, 720);
  background(0,0,0);
  cursor(CROSS);
}

void draw() {
  
  drawCircles();

}

void drawCircles() {

  float x = random(1280);
  float y = random(720);

  for (int i=0; i<20; i++) {
    circle[i] = new Circle(x, y, 50);
    circle[i].update();
  }
}

-------------------------------------in the other tab---------------------------------------------------------------------------

class Circle {
  float x;
  float y;
  float radius;

  Circle(float xParam, float yParam, int newRadius) {
    x = xParam;
    y = yParam;
    radius = newRadius;
  }

  void update() {

    if (dist(mouseX, mouseY, x, y) < radius) {
      fill(0, 0, 0);
    }

    ellipse(x, y, radius*2, radius*2);
  }
}

```

What I’m trying to do is loop my circle in my main file to make it so that there is 20 of them, and when the mouse hovers over them they turn from white to black and “disappear” into the background. How do I fix this code so the circles don’t keep spawning forever and my circles disappear when hovered over.

---

<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: [March 25, 2019, 3:42pm UTC](https://discourse.processing.org/t/trying-to-loop-circles-and-make-them-disappear-when-hovered-over/9612/2 "2019-03-25T15:42:45Z")

</div>

basic would be

- make\_circles(); // called in setup
- draw\_circles(); // called in draw

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [March 27, 2019, 9:01pm UTC](https://discourse.processing.org/t/trying-to-loop-circles-and-make-them-disappear-when-hovered-over/9612/3 "2019-03-27T21:01:17Z")

</div>

call from setup:

```auto
void setupCircles() {

  float x = random(1280);
  float y = random(720);

  for (int i=0; i<20; i++) {
    circle[i] = new Circle(x, y, 50);
  }
}

```

and call from draw:

```auto
void drawCircles() {
  for (int i=0; i<20; i++) {
    circle[i].update();
  }
}

```

…also, don’t loop up to 20. Loop up to `circle.length`
