xxxxxxxxxx
//Settings
int squares = 50; //Total number of squares (minimum = 1)
int speed = 0.5; //Speed multiplier of the squares (minimum = 1)
int maxSize = 300; //Max size that a square can be before shrinking (suggested = ~150)
int[] x = new int[squares];
int[] y = new int[squares];
int[] s = new int[squares];
int[] xDir = new int[squares];
int[] yDir = new int[squares];
int[] sDiff = new int[squares];
void setup() {
size(screenWidth, screenHeight);
for (int i = 0; i < squares; i++){
x[i] = random(30, screenWidth - 30);
y[i] = random(30, screenHeight - 30);
s[i] = random(10, maxSize - 10);
sDiff[i] = 1;
xDir[i] = random(-3, 3) * speed;
yDir[i] = random(-3, 3) * speed;
if (xDir[i] == 0){
xDir[i] += 1;
}
if (yDir[i] == 0){
yDir[i] += 1;
}
if (x[i] + s[i] > screenWidth){
x[i] = screenWidth / 2;
}
if (y[i] + s[i] > screenHeight){
y[i] = screenHeight / 2;
}
}
background(100);
}
void draw() {
smooth();
noStroke();
background(100);
for (int i = 0; i < x.length; i++){
s[i] += sDiff[i];
if(x[i] + s[i] >= screenWidth || x[i] >= screenWidth){
xDir[i] *= -1;
sDiff[i] *= -1;
}
if(x[i] <= 0 || x[i] + s[i] <= 0){
xDir[i] *= -1;
sDiff[i] *= -1;
}
if(y[i] + s[i] >= screenHeight || y[i] >= screenHeight){
yDir[i] *= -1;
sDiff[i] *= -1;
}
if(y[i] <= 0 || y[i] + s[i] <= 0){
yDir[i] *= -1;
sDiff[i] *= -1;
}
if (s[i] > maxSize || (s[i] * -1) > maxSize){
sDiff[i] *= -1;
}
x[i] += xDir[i];
y[i] += yDir[i];
if ((i % 3) == 2){
fill(225, 0, 0)
}
if ((i % 3) == 1){
fill(75)
}
if ((i % 3) == 0){
fill(3)
}
rect(x[i], y[i], s[i], s[i]);
}
}