Always liked
Noise Particles
Love what came out of this thread
Colored VBO particle sim
I also really like the BoomBox sketch.. though I can't remember who made it and I can't find it online, but here is an interactive 3d version I created based off the code.
- import processing.opengl.*;
- // OPENGL Voodoo for additive rendering
- import processing.opengl.*;
- import javax.media.opengl.*;
- import peasy.*;
- PGraphicsOpenGL pgl;
- GL gl;
- PeasyCam cam;
- float[] rotations = new float[3];
- //
- PImage glowKernel; // generated glow kernel for each particle
- int n=4000;
- Ball[] b=new Ball[n];
- Ball m;
- int S=400;
- float ax,ay;
- int deadCount;
- void setup(){
- size(800,800,OPENGL);
- hint( ENABLE_OPENGL_4X_SMOOTH );
- cam = new PeasyCam(this, width);
- cam.setResetOnDoubleClick(false);
- background(0);
- for(int i=0;i<n;i++){
- b[i]=new Ball(new PVector(random(-S,S),random(-S,S),random(-S,S)),new PVector(random(-1,1),random(-1,1),random(-1,1)));
- b[i].vel.normalize();
- b[i].vel.mult(2);
- }
- frameRate(30);
- float glowKernelWidth=100f;// glow core size parameter
- float glowKernelDecayPower=2.4f;// glow core decay power
- int reqGlowKernelSize =2*(int)pow(100f*glowKernelWidth,1f/glowKernelDecayPower);// required image size to accomodate the glow kernel
- println(reqGlowKernelSize+1);
- glowKernel=createImage(reqGlowKernelSize, reqGlowKernelSize, RGB);
- for(int i=0; i < reqGlowKernelSize; i++) {
- for(int j=0; j < reqGlowKernelSize; j++) {
- float bri=255.999999f*glowKernelWidth/(glowKernelWidth+pow(dist(i,j,reqGlowKernelSize/2,reqGlowKernelSize/2),glowKernelDecayPower));// radial symmetric decreasing function
- glowKernel.pixels[i+reqGlowKernelSize*j] = color(bri,bri);
- }
- }
- deadCount=0;
- pgl=(PGraphicsOpenGL)g;
- gl=pgl.gl;
- }
- void draw(){
- background(0);
- /*
- translate(S,S,-650);
- float tay=mouseX/(float)width*TWO_PI;
- if((tay-ay)>PI) tay-=TWO_PI;
- if((tay-ay)<-PI) tay+=TWO_PI;
- ay=0.9*ay+0.1*tay;
- rotateY(ay);
- */
-
- /*
- pgl.beginGL();
- gl.glDepthMask(true);
- gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
- pgl.endGL();
- gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
- */
- // drawFrame();
- pgl.beginGL();
- gl.glDepthMask(false);
- gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_ONE);
- pgl.endGL();
- if(m!=null){
- m.draw();
- m.update();
- }
- for(int i=0;i<n;i++){
- b[i].draw();
- if(b[i].state==Ball.EXPLODING){
- for(int j=0;j<n;j++){
- checkCollision(b[i],b[j]);
- }
- }
-
- else{
- if(m!=null)checkCollision(b[i],m);
- }
-
- b[i].update();
- }
- }
- void drawFrame(){
- /*
- float nearZ=0.91f;
- float farZ=0.97f;
- float dZ=farZ-nearZ;
- int level=140;
- S+=10;
- noFill();
- strokeWeight(2);
- beginShape(QUADS);
- stroke(level-(screenZ(S,S,S)-nearZ)/dZ*level,100);
- vertex(S,S,S);
- stroke(level-(screenZ(-S,S,S)-nearZ)/dZ*level,100);
- vertex(-S,S,S);
- stroke(level-(screenZ(-S,-S,S)-nearZ)/dZ*level,100);
- vertex(-S,-S,S);
- stroke(level-(screenZ(S,-S,S)-nearZ)/dZ*level,100);
- vertex(S,-S,S);
- stroke(level-(screenZ(S,S,-S)-nearZ)/dZ*level,100);
- vertex(S,S,-S);
- stroke(level-(screenZ(-S,S,-S)-nearZ)/dZ*level,100);
- vertex(-S,S,-S);
- stroke(level-(screenZ(-S,-S,-S)-nearZ)/dZ*level,100);
- vertex(-S,-S,-S);
- stroke(level-(screenZ(S,-S,-S)-nearZ)/dZ*level,100);
- vertex(S,-S,-S);
- endShape();
- beginShape(LINES);
- stroke(level-(screenZ(S,S,S)-nearZ)/dZ*level,100);
- vertex(S,S,S);
- stroke(level-(screenZ(S,S,-S)-nearZ)/dZ*level,100);
- vertex(S,S,-S);
- stroke(level-(screenZ(S,-S,-S)-nearZ)/dZ*level,100);
- vertex(S,-S,-S);
- stroke(level-(screenZ(S,-S,S)-nearZ)/dZ*level,100);
- vertex(S,-S,S);
- stroke(level-(screenZ(-S,S,S)-nearZ)/dZ*level,100);
- vertex(-S,S,S);
- stroke(level-(screenZ(-S,S,-S)-nearZ)/dZ*level,100);
- vertex(-S,S,-S);
- stroke(level-(screenZ(-S,-S,-S)-nearZ)/dZ*level,100);
- vertex(-S,-S,-S);
- stroke(level-(screenZ(-S,-S,S)-nearZ)/dZ*level,100);
- vertex(-S,-S,S);
- endShape();
-
- fill(0);
- S-=10;
- */
- }
- void mouseClicked(){
- m=new Ball(new PVector(), new PVector());
- m.state=Ball.EXPLODING;
- m.c=color(255);
- }
- void checkCollision(Ball b1, Ball b2){
- if(b1!=b2){
- float d2=(b1.pos.x-b2.pos.x)*(b1.pos.x-b2.pos.x)+(b1.pos.y-b2.pos.y)*(b1.pos.y-b2.pos.y)+(b1.pos.z-b2.pos.z)*(b1.pos.z-b2.pos.z);
- if((d2<100f*(b1.size+b2.size)*(b1.size+b2.size))&&((b1.state==Ball.EXPLODING)||(b2.state==Ball.EXPLODING))){
- if(b1.state==Ball.HEALTHY){
- b1.state=Ball.EXPLODING;
- }
- if(b2.state==Ball.HEALTHY){
- b2.state=Ball.EXPLODING;
- }
- }
- }
- }
- void keyPressed(){
- m=null;
- for(int i=0;i<n;i++){
- b[i]=new Ball(new PVector(random(-S,S),random(-S,S),random(-S,S)),new PVector(random(-1,1),random(-1,1),random(-1,1)));
- b[i].vel.normalize();
- b[i].vel.mult(2);
- }
- }
- class Ball{
- static final int HEALTHY=0;
- static final int EXPLODING=1;
- static final int DECAYING=2;
- static final int DEAD=3;
- PVector pos;
- PVector vel;
- int state;
- int stateCounter=0;
- float size;
- color c;
- Ball(PVector p, PVector v){
- pos=p.get();
- vel=v.get();
- state=HEALTHY;
- stateCounter=0;
- c=color(120,120,random(120,255));
- size=.25;
- }
- void update(){
- switch(state){
- case HEALTHY:
- pos.add(vel);
- constrain();
- break;
- case EXPLODING:
- size=min(size+.2,4.0);
- stateCounter+=1;
- if (stateCounter>34){
- state=DECAYING;
- //stateCounter=0;
- }
- break;
- case DECAYING:
- size+=.1;
- stateCounter+=50;
- if (stateCounter>510){
- state=DEAD;
- stateCounter=0;
- deadCount++;
- }
- break;
- }
- }
- void constrain(){
- if(pos.x<-S){
- pos.x=-2*S-pos.x;
- vel.x*=-1;
- }
- if(pos.y<-S){
- pos.y=-2*S-pos.y;
- vel.y*=-1;
- }
- if(pos.z<-S){
- pos.z=-2*S-pos.z;
- vel.z*=-1;
- }
- if(pos.x>=S){
- pos.x=2*S-pos.x;
- vel.x*=-1;
- }
- if(pos.z>=S){
- pos.z=2*S-pos.z;
- vel.z*=-1;
- }
- if(pos.y>=S){
- pos.y=2*S-pos.y;
- vel.y*=-1;
- }
- }
- void draw(){
- if(state!=DEAD){
- rotations = cam.getRotations();
- pushMatrix();
- translate(pos.x,pos.y,pos.z);// offset to bead position
- //rotateY(-ay);
- rotateX(rotations[0]);
- rotateY(rotations[1]);
- rotateZ(rotations[2]);
- scale(size);// rescale image
- translate(-glowKernel.width/2,-glowKernel.height/2);// offset from left-top corner to center of image, apply before rescaling image
- tint(red(c),green(c),blue(c),255-0.5*stateCounter);
- image(glowKernel,0,0);
- popMatrix();
- }
- }
- }