xxxxxxxxxx
34
/* the current sketch draws bubbles on the screen using an array of objects. help adding a feature so that when mouse click on a circle the object would be removed from the array using JavaScript splice() */
let bubbles = [];
let d;
function setup() {
createCanvas(400, 400);
for (let i = 0; i < 5; i++) {
bubbles[i] = new Bubble();
}
}
function draw() {
background(220);
for (let i = 0; i < bubbles.length; i++) {
bubbles[i].show();
}
}
class Bubble {
constructor() {
this.x = random(width);
this.y = random(height);
}
show() {
ellipse(this.x, this.y, 20, 20);
}
}