xxxxxxxxxx
// Variable for number of total circles so we can change it easily
int numCircs = 100;
// Arrays for randomising the location of the circles
float[] circX = new float[numCircs];
float[] circY = new float[numCircs];
float[] circD = new float[numCircs];
// Array for randomising the color of the circle using the color datatype - like int, String etc.
color[] circColor = new color[numCircs];
void setup() {
size(500, 800);
// noStroke();
// Create all these circles at random places all over the screen!
for (int i = 0; i<numCircs; i = i+1) {
circX[i] = random(width);
circY[i] = random(height);
circD[i] = random(40);
circColor[i] = color( random(255), random(255), random(255));
}
}
void draw() {
//background(#09366C);
background(#51549B);
// Change the colour of each circle on mouse hover
for (int i = 0; i<numCircs; i++) {
if (dist(mouseX, mouseY, circX[i], circY[i]) < circD[i]*.5) {
fill(circColor[i]);
} else {
fill(255);
}
// draw the cirlces based our Arrays "circX, circY, circD"
// we apply the index counter to each part of the ellipse to randomize size, location etx.
ellipse(circX[i], circY[i], circD[i], circD[i]);
}
}
void keyPressed() {
// when you press "R" reset all the locations of the circles
if (key == 'r') {
for (int i = 0; i<numCircs; i++) {
circX[i] = random(width);
circY[i] = random(height);
circD[i] = random(40) + 10;
// Color of each ellipse is random
circColor[i] = color( random(255), random(255), random(255));
}
}
}