xxxxxxxxxx
70
let rbs = [];
let drops = [];
p = 0;
ym = 0;
function setup() {
createCanvas(400, 400);
background(00);
angleMode(DEGREES);
background(0);
createCanvas(600, 400);
}
function draw() {
fill(0,10);
rect(0,0,width,height);
for(let i = 0; i < rbs.length; i = i + 1) {
rbs[i].update();
}
}
function mouseDragged() {
let w = random(1,5);
let h = w;
let rb = new RotatorBouncer(
mouseX, // x
mouseY, // y
w, // width
h, // height
2, // xspeed
2, // yspeed
.01 // rspeed
);
rbs.push(rb);
}
class RotatorBouncer {
constructor(x, y, w, h, xSpeed, ySpeed) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.xSpeed = xSpeed;
this.ySpeed = ySpeed;
}
update() {
push();
translate(this.x, this.y);
stroke(random(255),random(255),random(255),random(80,100));
noFill();
rect(0, 0, this.w, this.h);
pop();
this.x = this.x + this.xSpeed;
if (this.x > width - this.w / 2 || this.x < this.w / 2) {
this.xSpeed = this.xSpeed * -1;
}
if (this.y > height - this.h / 2 || this.y < this.h / 2) {
this.ySpeed = this.ySpeed * -1;
}
}
}