Bitmap/Flood fill: Difference between revisions

m
put PL/I where it belongs
(Added simple recursive solution for R)
m (put PL/I where it belongs)
Line 1,658:
img = FloodFill(img, 10, 10, green)
write_ppm("FloodOut.ppm",img)</lang>
 
 
=={{header|PicoLisp}}==
Using the format of [[Bitmap#PicoLisp|Bitmap]], a minimal recursive solution:
<lang PicoLisp>(de ppmFloodFill (Ppm X Y Color)
(let Target (get Ppm Y X)
(recur (X Y)
(when (= Target (get Ppm Y X))
(set (nth Ppm Y X) Color)
(recurse (dec X) Y)
(recurse (inc X) Y)
(recurse X (dec Y))
(recurse X (inc Y)) ) ) )
Ppm )</lang>
Test using 'ppmRead' from [[Bitmap/Read a PPM file#PicoLisp]] and 'ppmWrite' from [[Bitmap/Write a PPM file#PicoLisp]], filling the white area with red:
<pre>(ppmWrite
(ppmFloodFill (ppmRead "Unfilledcirc.ppm") 192 128 (255 0 0))
"Filledcirc.ppm" )</pre>
 
=={{header|PL/I}}==
<lang PL/I>fill: procedure (x, y, fill_color) recursive; /* 12 May 2010 */
<lang PL/I>
fill: procedure (x, y, fill_color) recursive; /* 12 May 2010 */
declare (x, y) fixed binary;
declare fill_color bit (24) aligned;
Line 1,686 ⟶ 1,703:
if pixel_color = area_color then call fill (x, y+1, fill_color);
 
end fill;</lang>
</lang>
The following PL/I statements change the color of the white area
of the sample image to red, and the central orb to green.
Line 1,699 ⟶ 1,715:
call fill (125, 125, '000000001111111100000000'b );
</lang>
 
=={{header|PicoLisp}}==
Using the format of [[Bitmap#PicoLisp|Bitmap]], a minimal recursive solution:
<lang PicoLisp>(de ppmFloodFill (Ppm X Y Color)
(let Target (get Ppm Y X)
(recur (X Y)
(when (= Target (get Ppm Y X))
(set (nth Ppm Y X) Color)
(recurse (dec X) Y)
(recurse (inc X) Y)
(recurse X (dec Y))
(recurse X (inc Y)) ) ) )
Ppm )</lang>
Test using 'ppmRead' from [[Bitmap/Read a PPM file#PicoLisp]] and 'ppmWrite' from [[Bitmap/Write a PPM file#PicoLisp]], filling the white area with red:
<pre>(ppmWrite
(ppmFloodFill (ppmRead "Unfilledcirc.ppm") 192 128 (255 0 0))
"Filledcirc.ppm" )</pre>
 
 
=={{header|PureBasic}}==
2,295

edits