xxxxxxxxxx
114
class Dandelion {
constructor(hour,minutes,seconds){
this.seeds = [];
this.x = random(100,500);
this.y = random(100,500);
this.center = createVector(this.x, this.y);
//length of stem
this.stem = minutes;
//number of seeds
this.seedtot = 60;
//which seed to fall
this.nseed = seconds%60;
//length of feather
this.l = 20;
//number of feather
this.n = 10;
for (var i=0; i<this.seedtot; i++){
this.seeds.push(new Seed(this.x,this.y,this.l,this.n,this.nseed));
}
this.gen = false;
}
update(minutes,seconds){
this.s = minutes;
this.nseed = seconds%60;
for (var i=0; i<this.seeds.length; i++){
//which seeds to move
if (this.seeds.length>0 && i<= this.nseed){
this.seeds[i].move = true;
}
}
//refresh every minute
if (this.nseed == 59){
this.gen = true;
}
if (this.nseed == 0&&this.gen==true){
this.seeds=[];
for (var j=0; j<this.seedtot; j++){
this.seeds.push(new Seed(this.x,this.y,this.l,this.n,this.nseed));
}
this.gen = false;
}
}
show(){
//draw stem
stroke(225);
noFill();
arc(this.center.x, this.center.y+this.s/2,10,this.s,-PI/2,PI/2);
//draw seed
for (let seed of this.seeds){
seed.show();
}
//draw center
for (var k=this.l*1.5; k>0; k--){
noStroke();
fill(255,255,255,80*(this.l*1.5-k)/this.l*1.5);
circle(this.center.x,this.center.y,k);
}
}
}
class Seed {
constructor(x,y,l,n,sec){
this.x = x;
this.y = y;
this.pos = createVector(x, y);
this.v = p5.Vector.random2D();
print(this.v);
this.v.setMag(random(0.8,1.2));
this.angle = 0;
//length of feather
this.l = l;
//number of feather
this.n = n;
//not cluster in the cetner
for (var i=0; i<this.l; i++){
this.pos.add(this.v);
}
this.move = false;
this.sec = sec;
}
show(){
//draw each seed
for (var i=0; i<this.n; i++){
push();
translate(this.pos.x,this.pos.y);
rotate(this.v.heading());
strokeWeight(1);
stroke(225,225,225,125*sin(PI*(i/this.n)));
line(0,0,this.l*sin(this.angle+i*PI/15),this.l*cos(this.angle+i*PI/15));
pop();
}
//draw seed stem
push();
translate(this.pos.x,this.pos.y);
rotate(-(this.v.heading()));
strokeWeight(1);
stroke(225);
//line(0,0,this.l*sin(this.angle+i*PI/15),this.l*cos(this.angle+i*PI/15));
pop();
if (this.move == true){
this.pos.add(this.v);
}
}
}