xxxxxxxxxx
// Exercise 8 Melanie Mitchell
// Blowing Bubbles!
//
let bubbles = new Array(70);
function setup() {
createCanvas(500, 900);
for (let i = 0; i < bubbles.length; i++) {
bubbles[i] = new Bubble(40, 860, i * 10, random(5, 20), random(0.04, 0.2), random(-0.09,-0.2));
}
}
function draw() {
background (149, 208, 219);
stroke(20, 33, 82);
noFill();
ellipse (40, 860, 40, 40);
line (40, 880, 40, 900);
for (let i = 0; i < bubbles.length; i++) {
bubbles[i].displayBubble();
bubbles[i].moveBubble();
}
}
class Bubble {
constructor(tempX, tempY, tempColour, tempRad, tempSpeedx, tempSpeedy) {
this.x = tempX;
this.y = tempY;
this.color = tempColour;
this.rad = tempRad;
this.speedx = tempSpeedx;
this.speedy = tempSpeedy;
}
displayBubble() {
stroke(255);
noFill();
ellipse(this.x, this.y, this.rad * 2, this.rad * 2);
this.x += this.speedx;
this.y += this.speedy;
if (this.x < 0 + this.rad || this.x > width - this.rad) {
this.speedx = this.speedx * -1;
}
if (this.y < 0 + this.rad || this.y > height - this.rad) {
this.speedy = this.speedy * -1;
}
}
moveBubble() {
this.x += this.speedx;
this.y += this.speedy;
}
}