Page MenuHomec4science

ParticleWin.pde
No OneTemporary

File Metadata

Created
Sun, Jul 6, 20:51

ParticleWin.pde

class ParticleWin {
Mover emitter;
ArrayList<smallP> list=new ArrayList<smallP>();
float ttl=1;//time to live
float size=20;
float f;
float timeInterval;
float prevF;
PShape p=new PShape();
ParticleWin(Mover m) {
emitter=m;
p = createShape();
p.beginShape(TRIANGLES);
p.vertex(0, 0, 0);
p.vertex(size, 0,0);
p.vertex(size, -size, size);
p.vertex( 0,0, size);
p.vertex(0, -size, 0);
p.vertex(size, -size, 0);
p.endShape();
p.setStroke(false);
}
void draw(){
if (frameCount-prevF>=timeInterval*frameRate && !shiftMod) {
timeInterval=random(0, 0.2);
prevF=frameCount;
list.add(new smallP(emitter.location.copy()));
}
ArrayList<smallP> toBeDestroyed=new ArrayList<smallP>();
for(smallP sp:list){
sp.draw();
if(sp.isDead()){
toBeDestroyed.add(sp);
}
}
list.removeAll(toBeDestroyed);
}
class smallP{
PVector loc;
PVector speed;
float ttl=100;
color c;
smallP(PVector loc){
this.loc=loc;
speed=new PVector(random(-1,1),random(-1,1),random(0,0.5));
c=color((int)random(50,200),(int)random(50,200),(int)random(50,200));
}
void draw(){
ttl--;
speed.x+=random(-1,1);
speed.y+=random(-1,1);
speed.z+=random(-1,1);
loc.add(speed);
gameSurface.pushMatrix();
gameSurface.translate(loc.x,-plate_t+min(-loc.z,0),loc.y);
p.setFill(c);
gameSurface.shape(p);
gameSurface.emissive(0);
gameSurface.popMatrix();
}
boolean isDead(){
return ttl<0;
}
}
}

Event Timeline