xxxxxxxxxx
let bubbles;
function setup() {
createCanvas(windowWidth, windowHeight);
bubbles = createBubbles();
}
function draw() {
background("#00948e");
drawBubbles();
moveBubbles();
}
function createBubbles() {
let bubbleArray = [];
for (let i = 0; i < 30; i++) {
let bubble = {
x: random(0, width),
y: random(0, height)
}
bubbleArray.push(bubble)
}
console.log(bubbleArray)
return bubbleArray
}
function drawBubbles() {
for (let bubble of bubbles) {
strokeWeight(5)
fill("#00a8a1")
stroke("#00a8a1")
circle(bubble.x, bubble.y, 20)
}
}
function moveBubbles() {
for (let bubble of bubbles) {
let step = 2
bubble.x += random(-step, step);
bubble.y += random(-step);
if (bubble.y < 0) {
bubble.y = height
}
}
}