let p = [];
let snowA = [];
let nSnow = 500;
function preload() {
for (let i = 1; i <= 7; i++) {
p[i - 1] = loadImage("/assets/" + i + ".png");
}
}
function setup() {
w = min(windowWidth, windowHeight) * 0.9;
createCanvas(windowWidth, windowHeight, WEBGL);
noStroke();
for (let i = 0; i < nSnow; i++) {
snowA.push(new SNOW());
}
}
function draw() {
background(0);
fill(74, 116, 158);
translate(0, 0, -10);
sphere(2000, 25, 25);
noFill();
rotateY((PI / 10) * sin(frameCount / 100));
s = w * 0.8;
for (let i = 6; i >= 0; i--) {
if (i !== 2) {
texture(p[i]);
for (let j = 0; j < 10; j++) {
push();
translate(0, 0, -20 * i + j);
plane(s * (1 + 0.05 * i));
pop();
}
}
}
fill(255);
for (let i = 0; i < nSnow; i++) {
snowA[i].move();
snowA[i].display();
}
noFill();
texture(p[2]);
for (let j = 0; j < 10; j++) {
push();
translate(0, 0, j);
plane(s, s);
pop();
}
}
class SNOW {
constructor() {
this.x = random(-w / 2, w / 2);
this.y = random(-height / 2, height / 2);
this.s = random(0.2, 0.5);
}
move() {
this.y += this.s;
if (this.y > w / 2) {
this.y = -w / 2;
this.z = random(0, 20);
}
}
display() {
push();
translate(this.x, this.y, 100 - this.z);
plane(2, 2);
pop();
}
}