Bitmap/Bresenham's line algorithm: Difference between revisions

(Added code for Metal compute shader)
(→‎{{header|zkl}}: added flood)
Line 3,150:
=={{header|zkl}}==
[[File:Line.zkl.jpg|200px|thumb]]
Algorithm from Wikipedia plus other functions so I can reference this code in other examples.
<lang zkl>ppm:=PPM(200,200,0xFF|FF|FF);
ppm.line(50,100, 100,190, 0);
Line 3,221:
if(e2 > -dy){ err=err - dy; x0=x0 + sx; }
if(e2 < dx) { err=err + dx; y0=y0 + sy; }
}
}
fcn flood(x,y, repl){ // slow!
targ:=self[x,y];
(stack:=List.createLong(10000)).append(T(x,y));
while(stack){
x,y:=stack.pop();
if((0<=y<h) and (0<=x<w)){
p:=self[x,y];
if(p==targ){
self[x,y]=repl;
stack.append( T(x-1,y), T(x+1,y), T(x, y-1), T(x, y+1) );
}
}
}
}
Anonymous user