xxxxxxxxxx
34
function Snow() {
// initialize coordinates
this.posX = 0;
// this.posY = random(-50, 0);
this.posY = height/2.5; // control the snow height
this.initialangle = random(0, 2 * PI);
this.size = random(2, 5);
// radius of snowflake spiral
// chosen so the snowflakes are uniformly spread out in area
let snow_width = 130; // control the snow width
this.radius = sqrt(random(pow(width / 2, 2)))-snow_width;
this.update = function(time) {
// x position follows a circle
let w = 0.4; // angular speed
let angle = w * time + this.initialangle;
this.posX = width / 2 + this.radius * sin(angle);
// different size snowflakes fall at slightly different y speeds
this.posY += pow(this.size, 0.5);
// delete snowflake if past end of screen
if (this.posY > height) {
let index = snowflakes.indexOf(this);
snowflakes.splice(index, 1);
}
};
this.display = function() {
fill(255,255,255,95)
ellipse(this.posX, this.posY, this.size);
};
}