RosettaCodeData/Task/Bitmap-Flood-fill/Phix/bitmap-flood-fill.phix
2023-07-01 13:44:08 -04:00

26 lines
835 B
Text

-- demo\rosetta\Bitmap_FloodFill.exw (runnable version)
include ppm.e -- blue, green, read_ppm(), write_ppm() (covers above requirements)
function ff(sequence img, integer x, y, colour, target)
if x>=1 and x<=length(img)
and y>=1 and y<=length(img[x])
and img[x][y]=target then
img[x][y] = colour
img = ff(img,x-1,y,colour,target)
img = ff(img,x+1,y,colour,target)
img = ff(img,x,y-1,colour,target)
img = ff(img,x,y+1,colour,target)
end if
return img
end function
function FloodFill(sequence img, integer x, y, colour)
integer target = img[x][y]
return ff(img,x,y,colour,target)
end function
sequence img = read_ppm("Circle.ppm")
img = FloodFill(img, 200, 100, blue)
write_ppm("FloodIn.ppm",img)
img = FloodFill(img, 10, 10, green)
write_ppm("FloodOut.ppm",img)