xxxxxxxxxx
//Exercise 7: Paige Barrett
//
let fun;
let fun1;
let fun2;
let circle = new Array(50);
function setup() {
createCanvas(windowWidth, windowHeight);
for (let i = 0; i < circle.length; i++) {
circle[i] = random(-1000, 650);
circle.push(new Ball());
}
fun = new Ball(random(windowWidth), 100, 25, 10, 10);
fun1 = new Ball(100, random(windowHeight), 25, 10, 10);
fun2 = new Ball(random(windowWidth),random(windowHeight), 25, 10, 10);
}
function draw() {
background(50, 90, 100);
fun.displayBall();
fun.moveBall();
fun1.displayBall();
fun1.moveBall();
fun2.displayBall();
fun2.moveBall();
}
class Ball {
constructor(tempX, tempY, tempRad, tempSpeedx, tempSpeedy) {
this.speedx = tempSpeedx;
this.speedy = tempSpeedy;
this.rad = tempRad;
this.x = tempX;
this.y = tempY;
}
displayBall() {
fill(random(0, 0, 255), random(0, 255, 0), random(255, 0, 0));
ellipse(this.x, this.y, this.rad, this.rad);
}
moveBall() {
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;
}
}
}