xxxxxxxxxx
119
let autumnleaves = [];
function setup() {
createCanvas(500, 700);
fill(240);
noStroke();
}
function draw() {
background(50,18,18);
let t = frameCount / 120;
//tree branch
fill(171,78,82);
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();
//leaves
push();
fill(100,255,0);
ellipse(190,210,40,20);
ellipse(430,250,40,20);
ellipse(320,550,20,40);
fill(255,100,0);
ellipse(230,170,40,20);
ellipse(170,450,20,40);
ellipse(300,325,20,40);
fill(240,240,0);
ellipse(320,400,40,20);
ellipse(400,175,40,20);
ellipse(280,630,40,20);
ellipse(110,330,40,20);
pop();
for (let i = 0; i < random(5); i++) {
autumnleaves.push(new autumnleave());
}
for (let leave of autumnleaves) {
leave.update(t);
leave.display();
}
}
// snowflake class
function autumnleave() {
this.posX = 0;
this.posY = random(-50000, 0);
this.initialangle = random(0, 2 * PI);
this.size = random(20,40);
this.size2 =random(20,40);
this.colour = color(random(100,255),random(100,255),0);
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 = autumnleaves.indexOf(this);
autumnleaves.splice(index, 1);
}
};
this.display = function() {
fill(this.colour);
ellipse(this.posX, this.posY, this.size, this.size2);
};
}