xxxxxxxxxx
let bg;
let dropCount = 500;
let drops = [];
let bgX = 0;
let rainSound;
function preload() {
bg = loadImage("Forest.jpg");
rainSound = loadSound("Rain.mp3");
}
function setup() {
createCanvas(920, 690);
bg.resize(width, height);
userStartAudio();
for (let i = 0; i < dropCount; i++) {
drops[i] = new Drop();
}
rainSound.loop();
}
function draw() {
background(bg);
// Parallax effect for the background
bgX -= 0.25;
if (bgX <= -bg.width) {
bgX = 0;
}
image(bg, bgX, 0);
image(bg, bgX + bg.width, 0);
for (let drop of drops) {
drop.fall();
drop.show();
}
}
class Drop {
constructor() {
this.x = random(width);
this.y = random(-500, -50);
this.len = random(10, 20);
this.speed = random(1, 20);
}
fall() {
this.y += this.speed;
this.speed += 0.2;
if (this.y > height) {
this.y = random(-200, -100);
this.speed = random(4, 10);
}
}
show() {
strokeWeight(2);
stroke(0, 191, 255);
line(this.x, this.y, this.x, this.y + this.len);
}
}
function mouseClicked(){
save("img_" + month() + '-' + day() + '_' + hour() + '-' + minute() + '-' + second() + ".jpg");
}