xxxxxxxxxx
32
class Bubble {
constructor(x, y, r = 50) {
this.x = x
this.y = y
this.r = r
this.red = 255;
this.green = 255;
this.blue = 255;
}
changeColor(red, green, blue) {
this.red = red;
this.green = green;
this.blue = blue;
}
overlaps(other) {
let d = dist(this.x, this.y, other.x, other.y);
return (d < this.r / 2 + other.r / 2);
}
move() {
this.x += random(-1, 1);
this.y += random(-1, 1);
}
position() {
stroke(0);
fill(this.red, this.green, this.blue, 100);
ellipse(this.x, this.y, this.r);
}
}