/** Looping Smoke Generator by Bill Robinson 2009. Use the mouse. R key to reinitialise. Assume a BSD style license. */ static final Random rand=new Random(); static final int MAX_SIZE=64; static final int nframes=50; static int tick; static final class particle { final float x1,y1; final int toff; int col; particle(final int swidth, final int sheight) { final int ew=swidth-MAX_SIZE*2, eh=sheight-MAX_SIZE*2; x1=ew/2+MAX_SIZE+(rand.nextInt(ew<<8)-(ew<<7))/256f; y1=eh/2+MAX_SIZE+(rand.nextInt(eh<<8)-(eh<<7))/256f; toff=rand.nextInt(nframes); int cel=rand.nextInt(64)+16; col=cel|(cel<<8)|(cel<<16); } } static particle[] particles; void dummy() {} public void setup() { size(512,512,P2D); background(0); init_particles(); frameRate(50); } private void init_particles() { particles=new particle[128]; for (int i=0;i>>8; } } static void quicksort(int i0, int i1) { int i=i0, j=i1; final int pivot=particles[i0+i1>>1].toff; do { while (particles[i].toffpivot) j--; if (i<=j) { final particle temp=particles[i]; particles[i]=particles[j]; particles[j]=temp; i++; j--; } } while (i<=j); if (i0=nframes-f) { o=i; break; } // System.out.println("mouse "+mouseX+","+mouseY); final int swid = width; final int ox = mouseX>=0 && mouseX=0 && mouseY>2 ? (pf-(nframes>>2))*255/(nframes>>2) : ((nframes>>2))*255/(nframes*3>>2); // int op=(int)(256/Math.max(1,pf/5f)); int op=ipf*256*ipf/nframes2; // int rad=40+(MAX_SIZE-40)*pf/nframes; int rad=(int)(Math.pow((float)pf/nframes,0.3)*MAX_SIZE); int rad2=rad*rad; int d=p.col; for (int y=-rad;y=height) break; int y2=y*y; for (int x=-rad,off=sy*swid+(int)(cx+x);x=swid) break; final int x2=x*x; if (y2+x2>rad2) continue; int c=pixels[off]; int v = Math.max(c>>>24,Math.max(0, (int)(rad2-(x2+y2))*256/rad2)*op>>8); int u=256-v; pixels[off]= (((((c )&0xff00ff)*u>>>8)&0x00ff00ff)+ ((((d )&0xff00ff)*v>>>8)&0x00ff00ff))+ (((((c>>>8)&0xff00ff)*u>>>8)&0x00ff00ff)+ ((((d>>>8)&0xff00ff)*v>>>8)&0x00ff00ff)<<8); } } } updatePixels(); tick++; }