xxxxxxxxxx
45
let boxes = [];
let gravity = 1.06;
function setup() {
createCanvas(400, 400);
for (i = 0; i < 10; i++) {
boxes[i] = new Box(random(width), random(height), random(25, 50));
}
}
function draw() {
background(220);
for (i = 0; i < boxes.length; i++) {
boxes[i].show();
boxes[i].fall(height);
}
}
class Box {
constructor(x, y, size) {
this.x = x;
this.y = y;
this.size = size;
}
show() {
rect(this.x, this.y, this.size, this.size);
}
fall(ground) {
this.y = this.y * gravity;
if (this.y + this.size >= ground) {
this.y = ground - this.size;
//this.x++
}
}
}
function mouseDragged(){
boxes.push(new Box(mouseX, mouseY, random(25,50)));
}