xxxxxxxxxx
50
let balls = [];
function setup() {
createCanvas(200, 200);
background("black");
for (let i = 0; i < 20; i++) {
balls.push(new Ball(random(width), random(height)));
}
}
function draw() {
background("#ffdfdf")//有这行无轨迹
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(15, 20);
this.color = random(["#fffd8d", "#c4ff8d", "#8dffdd"]);
//this.symbol=random("","","")emoji
}
move() {
this.y += 1;
if (this.y > height) {
this.reappear();
}
}
reappear() {
this.x = random(width);
this.y = random(height);
this.d = random(53, 10);
}
draw() {
fill(this.color);
stroke("white");
circle(this.x, this.y, this.d);
//text(this.x,this.y,this.d);
}
}
function keyPressed() {
if (key == "s") {
saveGif("object-array", 5);
}
}