xxxxxxxxxx
44
let balls = [];
function setup() {
createCanvas(200, 200);
background("#FD562A");
for (let i = 0; i < 30; i++) {
balls.push(new Ball(random(width), random(height)));
}
}
function draw() {
for (let i = 0; i < balls.length; i++) {
balls[i].move();
balls[i].draw();
}
}
class Ball {
constructor(x, y) {
this.x = x;
this.y = y;
this.d = random(2, 10);
}
move() {
this.y += 2;
if (this.y > height) {
this.reappear();
}
}
reappear() {
this.x = random(width);
this.y = random(height);
this.d = random(10, 40);
}
draw() {
textSize(this.d)
text(random(["🐤","🐵","😶🌫️"]),this.x,this.y);
}
}
function keyPressed() {
if (key == "s") {
saveGif("object-array", 5);
}
}