xxxxxxxxxx
174
let particles = [];
function setup() {
createCanvas(500, 700);
fill(240);
noStroke();
}
function draw() {
background(18, 18, 25);
tree();
// decide which particle to add
if(frameCount<400){
particles.push(new autumnleave());
}else if(frameCount<800){
particles.push(new snowflake());
}else if(frameCount<1200){
particles.push(new cherryblossom());
}else if(frameCount>1200){
frameCount = 0;
}
for (let part of particles) {
part.update();
part.display();
}
}
function tree(){
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();
}
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 * (frameCount/60) + this.initialangle;
this.posX = width / 2 + this.radius * sin(angle);
this.posY += pow(this.size, 0.5);
if (this.posY > height) {
let index = particles.indexOf(this);
particles.splice(index, 1);
}
};
this.display = function() {
fill(255,200);
ellipse(this.posX, this.posY, this.size);
};
}
function cherryblossom() {
//angleMode(DEGREES);
this.posX = 50;
this.posY = 0;
this.posZ = 0;
this.initialangle = random(0, 2 * PI);
this.size = random(5, 10);
this.size2 = random (15,20);
this.colour = color(random(210,255),183,197);
this.radius = sqrt(random(pow(width / 2, 2)));
this.update = function() {
let w = 0.6;
let angle = w * (frameCount/60) + this.initialangle;
this.posX = width / 2 + this.radius * sin(angle);
this.posY += pow(this.size, 0.5);
if (this.posY > height) {
let index = particles.indexOf(this);
particles.splice(index, 1);
}
};
this.display = function() {
fill(this.colour);
stroke(255,183,197);
ellipse(this.posX, this.posY, this.size2, this.size);
}
}
function autumnleave() {
this.posX = 0;
this.posY = 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() {
let w = 0.6;
let angle = w * (frameCount/60) + this.initialangle;
this.posX = width / 2 + this.radius * sin(angle);
this.posY += pow(this.size, 0.5);
if (this.posY > height) {
let index = particles.indexOf(this);
particles.splice(index, 1);
}
};
this.display = function() {
fill(this.colour);
ellipse(this.posX, this.posY, this.size, this.size2);
};
}