DLA [] w; BImage swap; int W,H; boolean drawit = true; int saveCount = 0; void setup(){ swap = loadImage("e.gif"); size (600,450); background(swap); w = new DLA[20000]; for(int i = 0; i < w.length; i++){ w[i] = new DLA(); } } void loop(){ background(swap); for(int i = 0; i < w.length; i++){ w[i].move(); w[i].check(); if(drawit){ w[i].draw(); } } } void keyPressed(){ switch(key){ case 'd': case 'D': drawit = !drawit; break; case 's': case 'S': println("saved DLA"+(++saveCount)+".tif"); save("DLA"+saveCount+".tif"); break; } } class vector{ int x,y; vector(){ reset(); } void reset(){ int option = int(random(3)); switch(option){ case 0: x = int(random(1,width-1)); y = minOrMax(1,height-2); break; case 1: x = minOrMax(1,width-2); y = int(random(1,height-1)); break; default: x = int(random(1,width-1)); y = int(random(1,height-1)); } } } class DLA{ vector v; int thresh; DLA(){ v = new vector(); thresh = int(grey(swap.pixels[(v.x+1) + v.y * width])); } void move(){ int d = int(random(4)); switch(d){ case 0: v.x++; break; case 1: v.y++; break; case 2: v.x--; break; case 3: v.y--; break; } if (v.y < 1 || v.x < 1 || v.y > height-2 || v.x > width-2){ v.reset(); } } void check(){ if (int(grey(swap.pixels[(v.x+1) + v.y * width])) == thresh){ int delta = thresh - int(grey(swap.pixels[v.x + v.y * width])); swap.pixels[v.x + v.y * width] = tone(swap.pixels[v.x + v.y * width],delta); v.reset(); } if (int(grey(swap.pixels[v.x + (v.y+1) * width])) == thresh){ int delta = thresh - int(grey(swap.pixels[v.x + v.y * width])); swap.pixels[v.x + v.y * width] = tone(swap.pixels[v.x + v.y * width],delta); v.reset(); } if (int(grey(swap.pixels[(v.x-1) + v.y * width])) == thresh){ int delta = thresh - int(grey(swap.pixels[v.x + v.y * width])); swap.pixels[v.x + v.y * width] = tone(swap.pixels[v.x + v.y * width],delta); v.reset(); } if (int(grey(swap.pixels[v.x + (v.y-1) * width])) == thresh){ int delta = thresh - int(grey(swap.pixels[v.x + v.y * width])); swap.pixels[v.x + v.y * width] = tone(swap.pixels[v.x + v.y * width],delta); v.reset(); } } void draw(){ stroke(thresh); point(v.x,v.y); } } int ini(){ return int(random(height)); } int minOrMax(int n1, int n2){ return int(random(2)) > 0 ? n1 : n2; } color tone (color c, int val){ int r=c>>16&0xff; int g=c>>8&0xff; int b=c&0xff; r += val; g += val; b += val; return color(r,g,b); } int grey(color p) { return max((p >> 16) & 0xff, (p >> 8 ) & 0xff, p & 0xff); }