xxxxxxxxxx
59
let Clouds = [];
let img;
function preload() {
img = loadImage('appa.png');
}
function setup() {
createCanvas(600, 600);
rectMode(CENTER);
for (let i = 0; i < 10; i++) {
let y = random(height-200);
if (i % 2 == 0) {
y = random(height-200);
}
Clouds.push(new Cloud(0,random(height) , color(255)));
}
}
function draw() {
background(157, 216, 252);
image(img, mouseX-170, mouseY-100);
for (let i = 0; i < Clouds.length; i++) {
Clouds[i].run();
}
}
class Cloud {
constructor(x, y, c) {
this.posX = x;
this.posY = y;
this.cloudWidth = 100;
this.cloudHeight = this.cloudWidth / 2.5;
this.cloudColor = c;
this.wheelWidth = this.cloudWidth * 0.2;
this.wheelHeight = this.wheelWidth / 2.5;
this.speed = random(1, 5);
}
run() {
this.drawCloud();
this.updateCloud();
}
drawCloud() {
fill(this.cloudColor);
noStroke();
ellipse(this.posX, this.posY, this.cloudWidth, this.cloudHeight);
fill(0);
}
updateCloud() {
this.posX += this.speed;
if (this.posX > width + this.cloudWidth / 2) {
this.posX = -this.cloudWidth / 2;
}
}
}