xxxxxxxxxx
94
function setup() {
createCanvas(200, 200);
b1 = new Ball(random(width), random(height));
b2 = new Ball(random(width), random(height));
b3 = new Ball1(random(width),random(height))
b4 = new Ball2(random(width),random(height))
}
function draw() {
background("black");
b1.move();
b1.draw();
b2.move();
b2.draw();
b3.move();
b3.draw();
b4.move()
b4.draw()
}
class Ball {
constructor(x, y) {
this.x = x;
this.y = y;
}
move() {
this.x = this.x + 10;
if (this.x > width) {
this.reappear();
}
}
reappear() {
this.x = random(width);
this.y = random(height);
}
draw() {
fill("#65D46E")
rect(this.x, this.y, 20);
}
}
class Ball1{
constructor(x, y) {
this.x = x;
this.y = y;
}
move() {
this.y = this.y + 10;
if (this.y > height) {
this.reappear();
}
}
reappear() {
this.x = random(width);
this.y = random(height);
}
draw() {
fill("yellow")
rect(this.x, this.y, map(this.y,0,height/2,10,40));
}
}
class Ball2{
constructor(x, y) {
this.x = x;
this.y = y;
}
move() {
this.y = this.y + 10;
if (this.y > height) {
this.reappear();
}
}
reappear() {
this.x = random(width);
this.y = random(height);
}
draw() {
fill("pink")
rect(this.x, this.y, 10);
}
}
function keyPressed() {
if (key == "s") {
saveGif("animation", 5);
}
}