xxxxxxxxxx
49
let balls = [];
function setup() {
createCanvas(100, 100);
background("#FF69B4");
for(let i = 0;i<20;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.r = random(10,20);
this.symbol = random(["🤩","😭","😒"])
}
move(){
this.x = this.x +2;
this.y = this.y + 2;
if(this.x>width){
this.reappear();
this.r = random(10,20);
}
}
reappear(){
this.x = random(width);
this.y = random(height);
}
draw(){
textSize(this.r);
text(this.symbol,this.x,this.y);
}
}
function keyPressed(){
if(key =="s"){
saveGif("animation.gif",5);
}
}