xxxxxxxxxx
44
var bubbles;
function setup() {
createCanvas(400, 400);
bubbles = [];
var count = 500;
for(var i = 0; i < count; i++) {
bubbles.push(new Bubble(random(width), height + 32 + random(height), 4 + random(16)));
}
}
function draw() {
background(200);
for(var i = 0; i < bubbles.length; i++) {
var bubble = bubbles[i];
bubble.update();
bubble.draw();
}
}
function Bubble(x, y, radius) {
this.x = x;
this.y = y;
this.vx = 0;
this.vy = (1 + random(2)) * -1;
this.radius = radius;
this.elapsed = 0;
}
Bubble.prototype.update = function() {
//this.elapsed += 1/60;
//this.vx = sin(this.elapsed);
//this.x += this.vx;
this.y += this.vy;
if(this.y < 0) {
this.y = height + 32 + random(height);
}
}
Bubble.prototype.draw = function() {
fill(255, 255, 255, 100);
noStroke();
ellipse(this.x - this.radius, this.y - this.radius, this.radius, this.radius);
}