xxxxxxxxxx
39
let bubbles = [];
function setup() {
createCanvas(windowWidth, windowHeight);
for (let i=0; i <= 20; i++) {
spawnBubble();
}
window.setInterval(spawnBubble, 500);
}
function draw() {
background(255);
for (let thisBubble of bubbles) {
noStroke();
fill(thisBubble.color);
circle(thisBubble.x, thisBubble.y, thisBubble.diameter);
thisBubble.x = noise(thisBubble.noiseX) * width;
thisBubble.y = noise(thisBubble.noiseY) * height;
thisBubble.noiseX += 0.01;
thisBubble.noiseY += 0.01;
}
}
function spawnBubble() {
let bubble = {
x: -200,
y: -200,
diameter: random(5, 20),
color: color(random(255), random(255), random(255), random(255)),
noiseX: random(0, 1000),
noiseY: random(0, 1000)
};
bubbles.push(bubble);
}