23 lines
746 B
Text
23 lines
746 B
Text
function ff(sequence img, integer x, integer y, integer colour, integer 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, integer y, integer 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)
|