Page MenuHomec4science

ParticleWin.pde
No OneTemporary

File Metadata

Created
Sun, Oct 6, 14:22

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 updateNdraw(){
if (frameCount-prevF>=timeInterval*frameRate && !shiftMod) {
timeInterval=random(0.01,0.05);
prevF=frameCount;
list.add(new smallP(emitter.location.copy()));
}
ArrayList<smallP> toBeDestroyed=new ArrayList<smallP>();
for(smallP sp:list){
sp.updateNdraw();
if(sp.isDead()){
toBeDestroyed.add(sp);
}
}
list.removeAll(toBeDestroyed);
}
class smallP{
PVector loc;
PVector speed;
PVector rotation;
PVector rotationSpeed;
float ttl=100;
color c;
smallP(PVector loc){
this.loc=loc;
speed=new PVector(random(-1,1),random(-1,1),random(-1,1));
rotation=new PVector(random(-PI,PI),random(-PI,PI),random(-PI,PI));
rotationSpeed=new PVector(random(-0.2,0.2),random(-0.2,0.2),random(-0.2,0.2));
c=color((int)random(50,200),(int)random(50,200),(int)random(50,200));
}
void updateNdraw(){
ttl--;
speed.x+=random(-1,1);
speed.y+=random(-1,1);
speed.z+=random(-1,1);
rotation.add(rotationSpeed);
loc.add(speed);
gameSurface.pushMatrix();
gameSurface.translate(loc.x,-plate_t+min(-loc.z,0),loc.y);
gameSurface.rotateX(rotation.x);
gameSurface.rotateY(rotation.y);
gameSurface.rotateZ(rotation.z);
p.setFill(c);
gameSurface.shape(p);
gameSurface.emissive(0);
gameSurface.popMatrix();
}
boolean isDead(){
return ttl<0;
}
}
}

Event Timeline