BImage swap,store; slider [] s; int count = 1; int mode = 1; void setup(){ swap = loadImage("a.gif"); store = swap.copy(); size(681,510); //size(swap.width,swap.height); s = new slider[10000]; for (int i = 0; i < s.length; i++){ s[i] = new slider(int(random(swap.width)),int(random(swap.height))); } } void loop(){ background(swap); for (int i = 0; i < s.length; i++){ s[i].slide(); } } void mousePressed(){ swap = store.copy(); mode = (mode+1)%2; } void keyPressed(){ save("slide.tif"); println("save count "+count++); } class slider{ int x,y,d; slider(int x, int y){ this.x = x; this.y = y; } void slide(){ int lastx = x; int lasty = y; int d = int(random(4)); switch(d){ case 0: x++; break; case 1: y++; break; case 2: x--; break; case 3: y--; break; } /* //wrap around if (x > swap.width-1){ x = 0; } if (y > swap.height-1){ y = 0; } if (x < 0){ x = width-1; } if (y < 0){ y = height-1; } */ ///* if (x > swap.width-1){ x = width-1; } if (y > swap.height-1){ y = height-1; } if (x < 0){ x = 0; } if (y < 0){ y = 0; } //*/ color a = swap.pixels[x + y * swap.width]; color b = swap.pixels[lastx + lasty * swap.width]; switch(mode){ case 0: swap.pixels[x + y * swap.width] = b; swap.pixels[lastx + lasty * swap.width]= a; break; case 1: swap.pixels[x + y * swap.width] = mean(a,b); swap.pixels[lastx + lasty * swap.width]= mean(a,b); break; } } } color mean(color c1, color c2){ float r = (red(c1)+red(c2))/2; float g = (green(c1)+green(c2))/2; float b = (blue(c1)+blue(c2))/2; return color (r,g,b); }