xxxxxxxxxx
51
let bubbles = [];
function setup() {
createCanvas(600, 600);
for (let i = 0; i < 100; i++) {
let colorVals = color(random(255), random(255), random(255), random(100,150));
let growth = random(1.5);
let diameter = random(10);
let timer = random(20);
let x = random(diameter, height - diameter);
let y = random(diameter, width - diameter);
bubbles.push(new Bubble(x, y, diameter, timer, growth, colorVals));
}
}
function draw() {
background(220);
for (let i = 0; i < bubbles.length; i++) {
bubbles[i].run();
}
}
class Bubble {
constructor(posX, posY, diameter, timer, growth, colorValues) {
this.color = color(colorValues);
this.size = diameter;
this.timer = timer;
this.growth = growth;
this.x = posX;
this.y = posY;
}
run() {
this.draw();
this.update();
}
draw() {
fill(this.color);
noStroke();
circle(this.x, this.y, this.size);
}
update() {
this.size += this.growth;
}
}