Skip to content

Instantly share code, notes, and snippets.

@tinytintoy
Created August 1, 2013 16:49
Show Gist options
  • Save tinytintoy/6133145 to your computer and use it in GitHub Desktop.
Save tinytintoy/6133145 to your computer and use it in GitHub Desktop.
Fireworks #1
/*
* [021] Fireworks #1
*
* 2013 [+++] @tinytintoto
*/
ArrayList<Fire> fires = new ArrayList<Fire>();
int initialSize;
float sleshold = 0.5;
void setup(){
size(500, 280);
frameRate(30);
noStroke();
rectMode(CENTER);
initialSize = floor( min( width, height ) / 10 );
fires.add( new Fire(
new PVector( width / 2, height / 10 * 7 ),
new PVector( 0, -(height / 80) ),
initialSize,
color( 255 ),
8
)
);
}
void draw(){
background( 0 );
for( int i = fires.size() - 1; i >= 0; i-- ){
Fire f = (Fire) fires.get(i);
f.update();
if( f.siz < sleshold ){
fires.remove(i);
}
}
}
class Fire{
int dev, life;
float siz;
PVector pos, velo;
color col;
Fire( PVector p, PVector v, float s, color c, int d ){
pos = p;
velo = v;
siz = s;
col = c;
dev = d;
life = 100;
}
void update(){
pushMatrix();
translate( pos.x, pos.y );
fill(col);
rect( 0, 0, siz, siz );
popMatrix();
life--;
switch(life){
case 80:
devide();
break;
}
siz*=0.98;
pos.add(velo);
}
void devide(){
PVector v = new PVector( velo.x, velo.y );
for( int i = 0; i < dev; i++ ){
fires.add( new Fire(
new PVector( pos.x, pos.y ),
new PVector( v.x, v.y),
siz,
col,
dev - 1
)
);
v.rotate(TWO_PI / dev );
}
if( dev > 0 ){
siz = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment