I have seen this video and the author posted the code, but it does not work. It's slightly broken at the
for loop Here is the video
Here is the site
http://null-null.net/blog/2007/11/569.php Here is the code
Code: import javax.media.opengl.*; import processing.opengl.*; import java.nio.*; //JOGL's PGraphicsOpenGL pgl; GL gl; //constant numbers for particle float DAMPING_VELOCITY = 0.98; float GRAVITY = 0; int AGE_MAX = 30; int NUM_GENERATION_AT_ONE_LOOP = 30; //particle list ArrayList particles; ArrayList clearParticles; //texture PImage texImage; int[] texID; //screen capture PImage cp; boolean isCap = false; int cpTimer = 0; void setup(){ int i; size(480, 360, OPENGL); background(0); frameRate(30); noSmooth(); //initialize JOGL's pgl = (PGraphicsOpenGL) g; gl = pgl.gl; randomSeed(int(random(1,1000))); //initialize particle list particles = new ArrayList(); clearParticles = new ArrayList(); //load image for texture texImage = loadImage("p.png"); //generate texture and bind texture pgl.beginGL(); gl.glEnable(GL.GL_TEXTURE_2D); texID = new int[1]; gl.glGenTextures(1,texID,0); gl.glBindTexture(GL.GL_TEXTURE_2D, texID[0]); gl.glTexImage2D( GL.GL_TEXTURE_2D, 0, 4, texImage.width, texImage.height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, IntBuffer.wrap(texImage.pixels) ); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); pgl.endGL(); //initialize image for screen capture cp = createImage(width,height,RGB); } void draw(){ int i; Particle p; Iterator it; background(0); //generate for(i=0; i //brend func pgl.beginGL(); gl.glDisable(GL.GL_DEPTH_TEST); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE); pgl.endGL(); //update and draw clearParticles.clear(); it = particles.iterator(); while(it.hasNext()){ p = (Particle)it.next(); p.update(); p.drawMe(); if(p.age>AGE_MAX){ clearParticles.add(p); } } //clear if(clearParticles.size() != 0){ it = clearParticles.iterator(); while(it.hasNext()){ p = (Particle)it.next(); particles.remove(p); } } // screen capture if(isCap){ cp = get(); cp.save("cap/cp_"+cpTimer+".jpg"); cpTimer++; } } void keyPressed(){ if(key=='s'){ isCap = true; }else if(key=='a'){ isCap = false; } } ///////////////////Color4f/////////////////// class Color4f { float r, g, b, a; public Color4f(){ r = g = b = a = 0.0; } public Color4f(float inR, float inG, float inB, float inA){ r = inR; g = inG; b = inB; a = inA; } } ///////////////////Particle/////////////////// class Particle { float x, y; float vx, vy; float size = 100; int age = 0; Color4f c; public Particle(float inX, float inY, float inVx, float inVy){ x = inX; y = inY; vx = inVx; vy = inVy; age = 0; c = new Color4f(random(0,1), random(0,1), random(0,1), 1); } void drawMe(){ float helfSize = size/2; float d = 1.0-(float)age/AGE_MAX; c.a = d; pgl.beginGL(); gl.glBindTexture(GL.GL_TEXTURE_2D, texID[0]); gl.glColor4f(c.r, c.g, c.b, c.a); gl.glBegin(GL.GL_QUADS); gl.glTexCoord2f(0,0); gl.glVertex2f(x-helfSize, y-helfSize); gl.glTexCoord2f(1,0); gl.glVertex2f(x+helfSize, y-helfSize); gl.glTexCoord2f(1,1); gl.glVertex2f(x+helfSize, y+helfSize); gl.glTexCoord2f(0,1); gl.glVertex2f(x-helfSize, y+helfSize); gl.glEnd(); pgl.endGL(); } void update(){ vy += GRAVITY; x += vx; y += vy; vx *= DAMPING_VELOCITY; vy *= DAMPING_VELOCITY; age++; } }
You can see the break in code is here
background(0); //generate for(i=0; iThe void loop() should be void draw()
-Thanks