xxxxxxxxxx
40
let bubble
function setup() {
createCanvas(400, 400);
frameRate(30)
bubble = new Bubble(width/2, height/2, 30)
}
function draw() {
background(30)
bubble.show()
bubble.shake(5)
}
class Bubble {
constructor(x, y, r) {
this.x = x
this.y = y
this.r = r
}
contains(x, y) {
return this.r > dist(x, y, this.x, this.y)
}
show() {
circle(this.x, this.y, this.r * 2)
}
shake(bound) {
this.x += random(-bound, bound)
this.y += random(-bound, bound)
}
restrict(x, y, w, h) {
this.x = constrain(this.x, x, x + w)
this.y = constrain(this.y, y, y + h)
}
}