xxxxxxxxxx
38
let myBall=[];
function setup() {
createCanvas(400, 400);
for (i=0;i<8;i++){
myBall.push(new Bubble())
}
}
function draw() {
background(220);
for(i=0;i<myBall.length;i++){
myBall[i].show();
myBall[i].move();}
}
class Bubble{
constructor(){
this.x=random(100,200);
this.y=200;
this.r=24;
this.s=1
}
move(){
this.x=this.x+this.s;
if(this.x>width||this.x<0){
this.s=this.s*-1;}
}
show(){
ellipse(this.x,this.y,this.r);
//text(this.num,this.x-4,this.y+4);
}
}