xxxxxxxxxx
33
let balls = [];
function setup() {
createCanvas(windowWidth, windowHeight);
for(let i = 0; i < 50; i++){
const newBall = new Ball(random(-50,windowWidth), random(-150,0),random(10,30),random(4));
balls.push(newBall);
}
}
class Ball {
constructor(x,y,wh,speed){
this.x = x;
this.y = y;
this.wh = wh;
this.speed = speed;
}
start() {
circle(this.x, this.y, this.wh);
}
move(){
if(this.y <windowHeight) { this.y+=this.speed}else{this.y = random(-100,0)}
}
};
function draw() {
background(220,0);
balls.map(b => {
b.start();
b.move();
})
}