xxxxxxxxxx
93
let snowflakes = [];
function setup() {
createCanvas(500, 700);
fill(240);
noStroke();
}
function draw() {
background(18, 18, 50);
let t1 = frameCount / 60;
//tree branch
fill(250,100);
stroke(255,100);
push();
beginShape();
curveVertex(0,300);
curveVertex(200,175);
curveVertex(175,215);
curveVertex(375,175);
curveVertex(250,215);
curveVertex(400,250);
curveVertex(290,242);
curveVertex(300,280);
curveVertex(260,250);
curveVertex(100,280);
curveVertex(-30,500);
endShape(CLOSE);
beginShape();
curveVertex(500,600);
curveVertex(400,500);
curveVertex(433,570);
curveVertex(375,600);
curveVertex(475,615);
curveVertex(550,700);
endShape(CLOSE);
pop();
// snowflakes
for (let i = 0; i < random(5); i++) {
snowflakes.push(new snowflake());
}
for (let flake of snowflakes) {
flake.update(t1);
flake.display();
}
}
function snowflake() {
this.posX = 0;
this.posY = random(-50, 0);
this.initialangle = random(0, 2 * PI);
this.size = random(2, 5);
this.radius = sqrt(random(pow(width / 2, 2)));
this.update = function(time) {
let w = 0.6;
let angle = w * time + this.initialangle;
this.posX = width / 2 + this.radius * sin(angle);
this.posY += pow(this.size, 0.5);
if (this.posY > height) {
let index = snowflakes.indexOf(this);
snowflakes.splice(index, 1);
}
};
this.display = function() {
fill(255,200);
ellipse(this.posX, this.posY, this.size);
};
}