let n = 150;
function setup() {
c = max(600, min(windowWidth * 0.9, windowHeight * 0.9));
createCanvas(c, c);
n = int(random(50, 120));
rectMode(CENTER);
d = c / n;
stroke(20, 40, 50);
strokeWeight(0.5);
angleMode(DEGREES);
rn = int(random(10, 40));
}
function draw() {
background(10, 30, 40);
translate(c / 2, c / 2);
t = frameCount;
for (let i = 0; i <= width; i += d) {
for (let j = 0; j <= height; j += d) {
x = -c / 2 + i;
y = -c / 2 + j;
dp = dist(x, y, 0, 0);
b = atan(y / dp);
if (abs((dp % rn) * abs(cos(t / 10))) < 5) {
dp2 = 100 * sin(b + t);
} else if (int(b + rn * cos(t + b - dp)) % rn == 0) {
dp2 = -100 * sin(b + t / 2);
} else {
dp2 = 0;
}
col = map(dp, -c / 2, c / 2, 0, 255) + dp2;
fill(col / 7, col / 2, col / 1.5);
rect(x, y, d, d);
}
}
t = frameCount;
push();
border();
pop();
}
function border() {
push();
noFill();
stroke(20, 50, 60);
strokeWeight(4);
rect(0, 0, width - 20, height - 20);
pop();
}
function mousePressed() {
frameCount = 0;
setup();
draw();
}
function keyPressed() {}
function windowResized() {
setup();
draw();
}