xxxxxxxxxx
int amount = 100;
int maxSpeed = 5;
float[] dotsX = new float[amount];
float[] dotsY = new float[amount];
int[] Xspeed = new int[amount];
int[] Yspeed = new int[amount];
float diameter;
boolean shaking = false;
void setup() {
fullScreen();
smooth();
for (int i=0; i<amount; i++) {
dotsX[i] = random(width);
dotsY[i] = random(height);
Xspeed[i] = int(random(-maxSpeed, maxSpeed));
Yspeed[i] = int(random(-maxSpeed, maxSpeed));
}
stroke(255);
strokeWeight(1);
noFill();
diameter = height/100;
}
void draw() {
background(0);
if (shaking == false) {
for (int i=0; i<amount; i++) {
dotsX[i] = dotsX[i] + Xspeed[i];
dotsY[i] = dotsY[i] + Yspeed[i];
if ((dotsX[i] > width) || (dotsX[i] < 0)) {
Xspeed[i] = -Xspeed[i];
}
if ((dotsY[i] > height) || (dotsY[i] < 0)) {
Yspeed[i] = -Yspeed[i];
}
ellipse(dotsX[i], dotsY[i], diameter, diameter);
}
} else {
for (int i=0; i<amount; i++) {
Xspeed[i] = int(random(-maxSpeed, maxSpeed));
Yspeed[i] = int(random(-maxSpeed, maxSpeed));
dotsX[i] = dotsX[i] + Xspeed[i];
dotsY[i] = dotsY[i] + Yspeed[i];
ellipse(dotsX[i], dotsY[i], diameter, diameter);
}
}
}
void mousePressed() {
shaking = !shaking;
}