xxxxxxxxxx
70
let n = 60;
let widthMult = 3;
let heightMult = 6;
let startR, startG, startB;
function setup() {
createCanvas(800, 800, WEBGL);
angleMode(DEGREES);
strokeWeight(1);
noLoop(1);
startR = random(160);
startG = random(160);
startB = random(160);
}
function draw() {
background(startR + 45, startG + 45, startB + 45, 150);
for (let x = width; x > -n * widthMult; x -= n) {
for (let y = height; y > -n * heightMult; y -= n) {
//random shape
let shape = random(1);
//fill color for each rectangle
let fillR = random(250);
let fillG = random(250);
let fillB = random(250);
//stroke color
let strokeR = (0);
let strokeG = (0);
let strokeB = (0);
push();
translate(x + n / 2, y + n / 2);
rotateX(frameCount * 0.01);
rotateY(frameCount * 0.01);
if (shape < 0.9) {
//random width and height for rectangle
let rectWidth = n * floor(random(-1, widthMult));
let rectHeight = n * floor(random(-1, heightMult));
//rectangle with random width and height
stroke(250, 250, 250);
fill(fillR, fillG, fillB, 200);
box(rectWidth, rectHeight, n);
}
pop();
}
}
}
function mouseClicked() {
for (let x = width; x > -n * widthMult; x -= n) {
for (let y = height; y > -n * heightMult; y -= n) {
let d = dist(mouseX, mouseY, x + n / 2, y + n / 2);
if (d < n / 2) {
startR = random(150);
startG = random(150);
startB = random(150);
redraw();
return;
}
}
}
}