// blur by: seb cheverel www.seb.cc, as implemented in http://www.toxi.co.uk/p5/base26/ by toxi. // Modified slightly to increase speed when image is fairly black by John Gilbertson // http://www.hardcorepawn.com/sparks/ class spark { float x,y; float theta,dtheta; float v; int age; float oldx,oldy; spark(int _x, int _y, float _dx, float _dy) { x=_x; y=_y; v=sqrt(_dx*_dx+_dy*_dy); theta=atan2(_dy,_dx); dtheta=(random(PI)-HALF_PI)*0.1; /* dx=_dx; dy=_dy;*/ age=0; oldx=x; oldy=y; } void move() { oldx=x; oldy=y; if(random(100)20) return true; else return false; } } void blur(int tt) { for(int ttt = 0; ttt <= tt; ttt++) { int R,G,B,left,right,top,bottom; int c,cl,cr,ct,cb; int w1=width-1; int h1=height-1; int index=0; for(int y=0;y0) ? -width : h1*width; bottom=(y==h1) ? -h1*width : width; for(int x=0; x0) ? -1 : w1; right=(x>16 & 255) + (cr>>16 & 255) + (c>>16 & 255) + (ct>>16 & 255) + (cb>>16 & 255)) / 5; G=((cl>>8 & 255) + (cr>>8 & 255) + (c>>8 & 255) + (ct>>8 & 255) + (cb>>8 & 255)) / 5; B=((cl & 255) + (cr & 255) + (c & 255) + (ct & 255) + (cb & 255)) / 5; pixels[index++]=(R<<16)+(G<<8)+B; } else { index++; } } } } } spark[] sparks; int x,y; int oldx,oldy; int id; int maxid; int t; int frame; int numsparks=20; int k; void keyPressed() { k=key; } void setup() { t=0; frame=0; size(350,350); background(0); sparks=new spark[numsparks]; x=mouseX; y=mouseY; id=0; maxid=0; } void loop() { if(k!=0) { if(k=='a') numsparks+=10; if(k=='z' && numsparks>10) numsparks-=10; setup(); k=0; } frame++; oldx=x; oldy=y; x=mouseX; y=mouseY; sparks[id]=new spark(x,y,(x-oldx)/3.0,(y-oldy)/3.0); for(int i=0;imaxid) maxid=id; blur(1); //framerate only work in processing... if(frame%100==0) { int rt=millis()-t; println("FPS:"+((float)100/((float)rt/(float)1000))); t=millis(); } }