xxxxxxxxxx
55
let rs = [];
function setup() {
createCanvas(400, 400);
angleMode(DEGREES);
for (let y = 20; y < height; y = y + 50) {
for (let x = 20; x < width; x = x + 50) {
rs.push(new Rotator(
random(400), // x location
random(400), // y location
70, // width of rect
random (20,75), // height of rect
random(2, 10), // speed of rotation
random(x,0,width,0,255), // color
random(20) //roundness
));
}
}
}
function draw() {
// background(220);
for (let i = 0; i < rs.length; i = i + 1) {
rs[i].update();
}
}
class Rotator {
constructor(x, y, w, h, s, c, r) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.s = s;
this.a = 10;
this.c = c;
this.r = r;
}
update() {
push();
translate(this.x, this.y);
rotate(this.a);
colorMode(HSB);
fill(this.c,200,200, 0.5);
rect(0, 0, this.w, this.h, this.r);
pop();
this.a = this.a + this.s;
}
}