|
fcn flood(pixmap, x,y, repl){ // slow!
|
|
targ,h,w:=pixmap[x,y], pixmap.h,pixmap.w;
|
|
stack:=List(T(x,y));
|
|
while(stack){
|
|
x,y:=stack.pop();
|
|
if((0<=y<h) and (0<=x<w)){
|
|
p:=pixmap[x,y];
|
|
if(p==targ){
|
|
pixmap[x,y]=repl;
|
|
stack.append( T(x-1,y), T(x+1,y), T(x, y-1), T(x, y+1) );
|
|
}
|
|
}
|
|
}
|
|
}
|