
Continuing with nested patterns, this experiment creates the sensation of an attractor. This is achieved by calculating the distance between the mouse’s location and the center of each circle, generating a pattern that is inversely proportional to the distance from the pointer’s position.
void setup() {
size(600, 400);
}
void draw() {
background(20, 40, 80);
noStroke();
fill(255, 200, 0);
int step = 15;
for (int i = 0; i < width; i += step) {
for (int j = 0; j < height; j += step) {
float d = dist(mouseX, mouseY, i, j);
float diameter = 500 / d;
ellipse(i, j, diameter, diameter);
}
}
}
