Bitmap/Flood fill: Difference between revisions

no edit summary
m (→‎{{header|Wren}}: Changed to Wren S/H)
imported>Chinhouse
No edit summary
 
Line 2,023:
Import the test image and fill the region containing the pixel at coordinate 100,100 with red (RGB 100%,0%,0%) using a tolerance of 1%
<pre>floodFill[Import["http://rosettacode.org/mw/images/0/0f/Unfilledcirc.png"], {100, 100}, 0.01, {1, 0, 0}]</pre>
 
=={{header|MiniScript}}==
This implementation is for use with [http://miniscript.org/MiniMicro Mini Micro]. The first parameter can be either a PixelDisplay or Image object. Flooding only occurs if the color as well as the opacity matches.
<syntaxhighlight lang="miniscript">
floodFill = function(bmp, x, y, targetColor, replacementColor)
// Check if pixel is outside the bounds
if not(0 < x < bmp.width) or not(0 < y < bmp.height) then return
// Check the current pixel color
currentColor = bmp.pixel(x, y)
if currentColor != targetColor then return
// Replace the color
bmp.setPixel x, y, replacementColor
// Recursively apply to adjacent pixels
floodFill(bmp, x + 1, y, targetColor, replacementColor)
floodFill(bmp, x - 1, y, targetColor, replacementColor)
floodFill(bmp, x, y + 1, targetColor, replacementColor)
floodFill(bmp, x, y - 1, targetColor, replacementColor)
end function
clear
img = file.loadImage("Unfilledcirc.png")
gfx.drawImage img, 0, 0
floodFill gfx, 50, 50, "#FFFFFFFF", "#00FFFFFF"
floodFill gfx, 100, 125, "#000000FF", "#0000FFFF"
</syntaxhighlight>
 
=={{header|Nim}}==
{{Trans|Python}}
Anonymous user