xxxxxxxxxx
59
let bubbles = [];
function setup() {
createCanvas(400, 400);
}
function mouseDragged() {
bubbles.push(new Rectangle(mouseX, mouseY));
}
function draw() {
background(0);
for (let i = 0; i < bubbles.length; i++) {
bubbles[i].move();
bubbles[i].transform();
bubbles[i].display();
if (bubbles.length > 20) {
bubbles.splice(0, 1);
}
}
}
class Rectangle {
constructor(xt, yt, zt) {
this.x = xt;
this.y = yt;
this.size = 24;
this.grow = false;
}
display() {
stroke(255);
fill(255, 0, 150, 50);
rect(this.x, this.y, this.x, this.y, this.size);
}
move() {
this.x = this.x + random(-1, 1);
this.y = this.y + random(-1, 1);
}
transform() {
if (this.grow) {
this.size += 10;
}
}
}
function mousePressed(){
for (let i = 0; i < bubbles.length; i++) {
bubbles[i].grow = true;
}
}
function mouseReleased(){
for (let i = 0; i < bubbles.length; i++) {
bubbles[i].grow = false;
}
}