xxxxxxxxxx
41
let ballA;
let ballB;
let ballC;
function setup() {
createCanvas(400, 400);
ballA = new Ball(width/2, height/2);
ballB = new Ball(width/2, height/2);
ballC = new Ball(width/2, height/2);
}
function draw() {
background(50);
ballA.move();
ballA.display();
ballB.move();
ballB.display();
ballC.move();
ballC.display();
}
class Ball {
constructor(x, y) {
this.x = x;
this.y = y;
this.dia = random(10, 30);
this.xSpd = random(-2, 2);
this.ySpd = random(-2, 2);
}
move() {
this.x += this.xSpd;
this.y += this.ySpd;
}
display() {
ellipse(this.x, this.y, this.dia, this.dia);
}
}