let shapes;
function setup() {
shapes = [];
c = min(windowWidth, windowHeight) * 0.8;
createCanvas(c, c);
rectMode(CENTER);
angleMode(DEGREES);
d = random(2, c / 100);
nRot = 2 * int(random(1, 10)) + 1;
for (let i = 0; i < 200; i++) {
shapes[i] = {
type: floor(random(0, 2.999)),
x: random(width / 2.2),
theta: random(360),
size: random(0.5, 4)
};
}
}
function draw() {
background(255);
translate(width / 2, height / 2);
t = frameCount / 100;
noStroke();
for (let i = 0; i < shapes.length; i++) {
for (let j = 0; j < nRot; j++) {
push();
rotate((360 / nRot) * j);
push();
translate(
shapes[i].x * sin(shapes[i].theta + t),
shapes[i].x * cos(shapes[i].theta + t)
);
if (shapes[i].type === 0) {
fill(200, 0, 0);
rotate(t * shapes[i].size);
rect(0, 0, d * shapes[i].size, d * shapes[i].size);
} else if (shapes[i].type === 1) {
fill(255, 200, 0);
rotate(t * shapes[i].size);
triangle(
((d * shapes[i].size) / 2) * cos(0),
((d * shapes[i].size) / 2) * sin(0),
((d * shapes[i].size) / 2) * cos(120),
((d * shapes[i].size) / 2) * sin(120),
((d * shapes[i].size) / 2) * cos(240),
((d * shapes[i].size) / 2) * sin(240)
);
} else {
fill(0, 0, 200);
circle(0, 0, d * shapes[i].size);
}
pop();
pop();
}
}
border();
}
function border() {
noFill();
stroke(200, 0, 0);
strokeWeight(4);
rect(0, 0, width - 20, height - 20);
}
function mousePressed() {
frameCount = 0;
setup();
draw();
}
function keyPressed() {}
function windowResized() {
c = min(windowWidth, windowHeight) * 0.8;
resizeCanvas(c, c);
}