xxxxxxxxxx
61
let bubbles = [];
function setup() {
createCanvas(600, 400);
}
function mousePressed() {
let r = random(10, 40);
let b = new Bubble(mouseX, mouseY, r);
bubbles.push(b);
}
function draw() {
background(51);
for (let circle of bubbles) {
circle.move();
circle.show();
bubble.randomCol();
}
// for ( let i = 0; i < bubbles.length;i++){
// bubbles[i].show();
// bubbles[i].move();
// bubbles[i].randomCol();
// }
}
class Bubble {
constructor(tempX, tempY, tempR) {
this.x = tempX;
this.y = tempY;
this.r = tempR;
}
move() {
this.x = this.x + random(-5, 5);
this.y = this.y + random(-5, 5);
}
show() {
stroke(255);
strokeWeight(4);
//noFill();
this.ellipse = ellipse(this.x, this.y, this.r * 2);
}
col() {
fill(255, 255, 0);
}
randomCol() {
fill(random(255), random(255), random(255));
}
}