int N=30; float x[] = new float[N]; float y[] = new float[N]; void setup() { size(600,400); fill(0, 255, 0); for (int j=0; j < N; j++) { x[j] = random(width); y[j] = random(height); } } void draw() { background(204); for (int j=0; j < N; j++) { ellipse(x[j], y[j], 10, 10); } } void mousePressed() { // let's consider the circles ordered from "front" to "back" for (int j=N-1; j >= 0; j--) { if (dist(mouseX, mouseY, x[j], y[j]) <= 5) { x[j] = random(width); y[j] = random(height); return; // this way, we don't move any other circles } } }