//import processing.opengl.*; class Particle3 { float x, y, z; float sx, sy, sz; float svx, svy, svz; float centrex, centrey; float mass; int startTime, endTime; float vx, vy, vz; float ax, ay, az; boolean isAlive; color c; float dscale = 0.1f; float viewdist = 120.0f; int generation = 0; Particle3(int xpos, int ypos, int zpos, int lifespan ) { sx = (float)xpos; sy = (float)ypos; sz = (float)zpos; x = sx; y = sy; z = sz; mass = 1; startTime = millis(); isAlive = true; centrex = width/2; centrey = height/2; endTime = startTime + lifespan; c = color( 0 ); } void display( ) { float scrx, scry; if ( !isAlive ) return; if ( z + 202.0f < 1.0f ) return; // too close to or behind camera //if ( x > width || x < 0 || y > height || y < 0 ) return; fill ( c ); //noStroke(); scrx = x / (z + 202.0f) * viewdist; scry = y / (z + 202.0f) * viewdist; ellipse( centrex + (scrx/dscale), centrey + (scry/dscale), mass*20, mass*20 ); } void update() { vx += ax; vy += ay; vz += az; x += vx; y += vy; z += vz; if ( millis() > endTime ) isAlive = false; } } class ParticleCloud3 { int centrex, centrey, centrez; int nParticles; float density; float colldist; float minmass, maxmass; int numAlive; Particle3[] p = new Particle3[400]; int explodeNumber; ParticleCloud3( int cx, int cy, int cz, int n, float d, float minm, float maxm ) { centrex = cx; centrey = cy; centrez = cz; nParticles = n; density = d; minmass = minm; maxmass = maxm; numAlive = nParticles; explodeNumber = 4; colldist = 0; for( int i=0;i ( nParticles / 2 ) ) p[i].isAlive = false; } reset(); } void reset() { float rads; for( int i=0; i explodeNumber ) break; if ( p[k].isAlive==true ) continue; newparts[numNew] = k; numNew++; } if ( numNew==0 ) continue; for (k=0;k 100 || abs(p[i].vy) > 100 ) p[i].isAlive = false; if ( abs(p[i].x) > 10000 || abs(p[i].y) > 10000 ) { p[i].isAlive = false; //numAlive--; } } } int nearest( int i ) { int j; float bestd = 9999999; float d = 0; int bestIndex = 0; if (!p[i].isAlive) return -1; for (j=0; j