// Raindrops // // based on an idea by Hugo Elias // (http://freespace.virgin.net/hugo.elias/graphics/x_water.htm) // // Implementation with Processing // and smoothing by Mario Klingemann // http://incubator.quasimondo.com // // Reuse of this code is permitted // as long as this copyright notice // is included. int[] map1; int[] map2; int[] mapIn; int[] mapOut; int asize; boolean step; int rainfall; boolean show; int strength=8000; BImage a; void setup(){ a= loadImage("floor.jpg"); size(a.width,a.height); asize=width*height; rainfall=1; step=false; initmaps(); show=false; } void loop(){ if (!step){ mapIn=map1; mapOut=map2; } else { mapOut=map1; mapIn=map2; } rain(); updatemap(); fastblur(); if (show){ showmap(); } else { rendermap(); } step=!step; } void keyPressed(){ show=true; } void keyReleased(){ show=false; } void rain(){ mapIn[int(random(asize-1))]+=int(random(-strength,strength)); } void initmaps(){ map1=new int[asize]; map2=new int[asize]; } void updatemap(){ int x,y,yw,i; for (y=1;y>1) - mapOut[i]; mapOut[i] -=mapOut[i]>>8; } } } void showmap(){ int p; for (int i=0;i255) p=255; pixels[i]=0xff000000 | p<<16 | p<<8 | p; } } void rendermap(){ int o,p,i,x,y,xo,yo,r,g,b,shade; int[] pix=a.pixels; i=0; for (y=0;y>2; xo+=x; yo+=y; while (xo<0) xo+=width; while (yo<0) yo+=height; while (xo>=width) xo-=width; while (yo>=height) yo-=height; /* // Additional Shading p=pix[xo+yo*width]; r=(p&0xff0000)>>16; g=(p&0x00ff00)>>8; b=(p&0x0000ff); r+=shade; g+=shade; b+=shade; if (r<0) r=0; if (r>255) r=255; if (g<0) g=0; if (g>255) g=255; if (b<0) b=0; if (b>255) b=255; pixels[i++]=0xff000000 | r<<16 | g<<8 | b; */ pixels[i++]=pix[xo+yo*width]; } } } void fastblur(){ int w=width; int h=height; int wm=w-1; int hm=h-1; int wh=w*h; int div=3; int r[]=new int[wh]; int sum,x,y,i,p,p1,p2,yp,yi,yw; int vmin[] = new int[max(w,h)]; int vmax[] = new int[max(w,h)]; yw=yi=0; for (y=0;y