xxxxxxxxxx
85
let rbs = [];
let numBouncers = 10;
let niky = "hi";
function setup() {
createCanvas(800, 800);
background(255);
//background(220);
angleMode(DEGREES);
rectMode(CENTER);
// for (let i = 0; i < numBouncers; i = i + 1) {
// let w = random(30,60);
// let h = w;
// let rb = new RotatorBouncer(
// random(w,width-w), // x
// random(h,height-h), // y
// w, // width
// h, // height
// random(2,4), // xspeed
// random(2,4), // yspeed
// random(0.2,0.8) // rspeed
// );
// rbs.push(rb);
// }
}
function draw() {
for(let i = 0; i < rbs.length; i = i + 1) {
rbs[i].update();
}
}
function mouseDragged() {
let w = random(30,60);
let h = w;
let rb = new RotatorBouncer(
mouseX, // x
mouseY, // y
w, // width
h, // height
random(-2,2), // xspeed
random(-2,2), // yspeed
random(0.2,0.8) // rspeed
);
rbs.push(rb);
}
class RotatorBouncer {
constructor(x, y, w, h, xSpeed, ySpeed, rSpeed) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.xSpeed = xSpeed;
this.ySpeed = ySpeed;
this.rSpeed = rSpeed;
this.a = 0;
this.nomatter = 23; // ignored because i don't use it
}
update() {
push();
translate(this.x, this.y);
rotate(this.a);
rect(0, 0, this.w, this.h);
pop();
this.x = this.x + this.xSpeed;
this.y = this.y + this.ySpeed;
this.a = this.a + this.rSpeed;
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;
}
}
}