xxxxxxxxxx
36
let bubbles = [];
function setup() {
createCanvas(600, 400);
for (var i = 0; i < 4; i++) {
bubbles[i] = new Bubble(random(width), random(height));
}
}
function mousePressed() {
bubbles.push(new Bubble(mouseX, mouseY));
}
function draw() {
background(0);
for (var j = 0; j < bubbles.length; j++) {
bubbles[j].move();
bubbles[j].display();
}
}
function Bubble(x, y) {
this.x = x;
this.y = y;
this.display = function() {
stroke(255);
noFill();
strokeWeight(3);
ellipse(this.x, this.y, 30, 30);
}
this.move = function() {
this.x += random(-2, 2);
this.y += random(-2, 2);
}
}