Bitmap/Flood fill: Difference between revisions
Content added Content deleted
(Applesoft BASIC) |
(add ocaml) |
||
Line 2,100: | Line 2,100: | ||
img.floodFill((30, 122), White, color(255, 0, 0)) |
img.floodFill((30, 122), White, color(255, 0, 0)) |
||
img.writePPM("Unfilledcirc_red.ppm")</lang> |
img.writePPM("Unfilledcirc_red.ppm")</lang> |
||
=={{header|OCaml}}== |
|||
{{Trans|C}} |
|||
<lang ocaml> |
|||
let floodFill ~img (i, j) newColor = |
|||
let oldColor = get_pixel ~img ~pt:(i, j) in |
|||
let width, height = get_dims ~img in |
|||
let rec aux (i, j) = |
|||
if 0 <= i && i < height |
|||
&& 0 <= j && j < width |
|||
&& (get_pixel ~img ~pt:(i, j)) = oldColor |
|||
then begin |
|||
put_pixel img newColor i j; |
|||
aux (i-1, j); |
|||
aux (i+1, j); |
|||
aux (i, j-1); |
|||
aux (i, j+1); |
|||
end; |
|||
in |
|||
aux (i, j)</lang> |
|||
=={{header|Pascal}}== |
=={{header|Pascal}}== |