xxxxxxxxxx
54
let rs = [];
function setup() {
createCanvas(400, 400);
angleMode(DEGREES);
rectMode(CENTER);
for (let y = 10; y < height; y = y + 10) {
for (let x = 10; x < width; x = x + 10) {
rs.push(new Rotator(
x, // x location
y, // y location
20, // width of rect
20, // height of rect
random(0.2, 0.4), // speed of rotation
map(x,0,width,0,255), // color
random(6)
));
}
}
}
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 = 0;
this.c = c;
this.r = r;
}
update() {
push();
translate(this.x, this.y);
rotate(this.a);
colorMode(HSB);
fill(this.c,100,100, 0.5);
rect(0, 0, this.w, this.h, this.r);
pop();
this.a = this.a + this.s;
}
}