xxxxxxxxxx
55
let cloud1;
let cloud2;
let cloud3;
let cloud4;
let cloud5;
function setup() {
createCanvas(displayWidth / 2, displayHeight / 2);
cloud1 = new Cloud();
cloud2 = new Cloud();
cloud3 = new Cloud();
cloud4 = new Cloud();
cloud5 = new Cloud();
}
function draw() {
background(102, 178, 255);
noStroke();
fill(255);
cloud1.create();
cloud2.create();
cloud3.create();
cloud4.create();
cloud5.create();
cloud1.move();
cloud2.move();
cloud3.move();
cloud4.move();
cloud5.move();
}
class Cloud {
constructor() {
this.x = random(displayWidth/2);
this.y = random(displayHeight/2);
this.length = random(40, 100);
this.m = 0;
}
create() {
rect(this.x + this.m, this.y, this.length + 100, this.length, 40);
circle(this.x + this.m + 40, this.y, this.length);
circle(this.x + this.m + 85, this.y, this.length + 30);
}
move() {
if (this.x + this.m < displayWidth/2) {
this.m = this.m + 2;
} else {
this.m = this.m - displayWidth/1.5;
this.y = random(displayHeight/2);
}
}
}