Anonymous user
Bitmap/Flood fill: Difference between revisions
no edit summary
(Applesoft BASIC) |
imported>Chinhouse No edit summary |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1:
{{task|Raster graphics operations}}Implement a [[wp:flood fill|flood fill]].
A flood fill is a way of filling an area using ''color banks'' to define the contained area or a ''target color'' which "determines" the area (the ''valley'' that can be flooded; Wikipedia uses the term ''target color''). It works almost like a water flooding from a point towards the banks (or: inside the valley): if there's a hole in the banks, the flood is not contained and all the image (or all the "connected valleys") get filled.
Line 8:
[[Image:Unfilledcirc.png|128px|thumb|right]]
'''Testing''': the basic algorithm is not suitable for ''truecolor'' images; a possible test image is the one shown on the right box; you can try to fill the white area, or the black inner circle.
=={{header|Action!}}==
In the following solution a simple implementation of queue has been used.
{{libheader|Action! Bitmap tools}}
<
RGB black,white,yellow,blue
Line 182 ⟶ 181:
DO UNTIL CH#$FF OD
CH=$FF
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Flood_fill.png Screenshot from Atari 8-bit computer]
=={{header|Ada}}==
<
( Picture : in out Image;
From : Point;
Line 292 ⟶ 290:
Column (From);
end if;
end Flood_Fill;</
The procedure has the following parameters. ''Picture'' is the image to change. ''From'' is the point to start at. ''Fill'' is the color to fill with. ''Replace'' is the color to replace. ''Distance'' defines the range of color around ''Replace'' to replace as well. The distance is defined as a maximum of the differences of stimuli. The following code snippet reads the test file, fills the area between two circles red, and writes the result:
<
File : File_Type;
begin
Line 312 ⟶ 310:
Close (File);
end;
end;</
=={{header|Applesoft BASIC}}==
<
110 COLOR= 12
120 X = 20:Y = 30: GOSUB 140"FLOOD FILL"
Line 341 ⟶ 339:
350 F = 1 - R:X = 0:Y = R:DX = 0:DY = - 2 * R:PLOT CX,CY + R:PLOT CX,CY - R:HLIN CX - R,CX + R AT CY: IF X > = Y THEN RETURN
360 FOR I = 0 TO 1:IF F > = 0 THEN Y = Y - 1:DY = DY + 2:F = F + DY
370 X = X + 1:DX = DX + 2:F = F + DX + 1:HLIN CX - X,CX + X AT CY + Y:HLIN CX - X,CX + X AT CY - Y:HLIN CX - Y,CX + Y AT CY + X:HLIN CX - Y,CX + Y AT CY - X: I = X > = Y : NEXT I : RETURN</
=={{header|AutoHotkey}}==
* <code>x</code>, <code>y</code> are the initial coords (relative to screen unless the <code>relative</code> parameter is true).
Line 351 ⟶ 349:
=== Recursive ===
This is limited to %StackSize% pixels.
<
CoordMode, Mouse
CoordMode, Pixel
Line 391 ⟶ 389:
FloodFill(x-1, y-1, target, replacement, key)
}
}</
=== Iterative ===
<
#SingleInstance, Force
Line 448 ⟶ 446:
DllCall("ReleaseDC", UInt, 0, UInt, hDC)
DllCall("DeleteObject", UInt, hBrush)
}</
=={{header|BBC BASIC}}==
BBC BASIC has a built-in flood fill statement, but to satisfy the terms of the task it is not used in this example.
<
GCOL 15
CIRCLE FILL 640, 512, 500
Line 475 ⟶ 472:
PROCflood(X%, Y%-2, C%)
NEXT
ENDPROC</
=={{header|C}}==
===Simple and complete example in C89===
<syntaxhighlight lang="c">/*
* RosettaCode: Bitmap/Flood fill, language C, dialects C89, C99, C11.
*
Line 585 ⟶ 581:
writePortableBitMap(stdout);
return EXIT_SUCCESS;
}</
===Second example ===
<syntaxhighlight lang="c">
// http://commons.wikimedia.org/wiki/File:Julia_immediate_basin_1_3.png
Line 696 ⟶ 692:
}
</syntaxhighlight>
===Third example===
Line 703 ⟶ 699:
The <code>sys/queue.h</code> is not POSIX. (See [[FIFO#C|FIFO]])
<
typedef struct {
color_component red, green, blue;
Line 711 ⟶ 707:
void floodfill(image img, int px, int py,
rgb_color_p bankscolor,
rgb_color_p rcolor);</
<
typedef struct _ffill_node {
Line 805 ⟶ 801:
}
return pixelcount;
}</
The '''pixelcount''' could be used to know the area of the filled region. The ''internal'' parameter <code>tolerance</code> can be tuned to cope with antialiasing, bringing "sharper" resuts.
Line 813 ⟶ 809:
(Comments show changes to fill the white area instead of the black circle)
<
#include <stdlib.h>
#include "imglib.h"
Line 839 ⟶ 835:
}
return 0;
}</
=={{header|C sharp|C#}}==
{{works with|C#|3.0}}
Line 847 ⟶ 842:
This implementation matches exact colours only. Since the example image has grey pixels around the edges of the circles, these will remain grey after the interiors are filled.
<
using System;
using System.Collections.Generic;
Line 901 ⟶ 896:
}
}
</syntaxhighlight>
=={{header|C++}}==
{{libheader|OpenCV}}
Line 909 ⟶ 903:
'''Interface'''
<
#define PROCESSING_FLOODFILLALGORITHM_H_
Line 936 ⟶ 930:
#endif /* PROCESSING_FLOODFILLALGORITHM_H_ */
</syntaxhighlight>
'''Implementation'''
<
FloodFillAlgorithm::~FloodFillAlgorithm() {
Line 982 ⟶ 976:
}
</syntaxhighlight>
=={{header|D}}==
This version uses the bitmap module from the Bitmap Task, matches exact colours only, and is derived from the Go version (to avoid stack overflow because unlike Go the D stack is not segmented).
<
void floodFill(Color)(Image!Color img, in uint x, in uint y,
Line 1,015 ⟶ 1,008:
img.floodFill(200, 200, RGB(127, 0, 0));
img.savePPM6("unfilled_circ_flooded.ppm");
}</
=={{header|Delphi}}==
See [[#Pascal]].
Line 1,022 ⟶ 1,015:
Using the image type from [[Basic bitmap storage#E]].
<
def matchColor := image[x, y]
def w := image.width()
Line 1,090 ⟶ 1,083:
fillScan(x, y)
}</
[[File:Filledcirc-E.png|128px|thumb|right|Filled sample image]]Note that this does not make any attempt to smoothly fill 'banks' or have a tolerance; it matches exact colors only. This will fill the example image with red inside green, and there will be black/white fringes:
<syntaxhighlight lang="e">{
println("Read")
def i := readPPM(<import:java.io.makeFileInputStream>(<file:Unfilledcirc.ppm>))
Line 1,104 ⟶ 1,097:
i.writePPM(<import:java.io.makeFileOutputStream>(<file:Filledcirc.ppm>))
println("Done")
}</
=={{header|ERRE}}==
In "PC.LIB" library there is a FILL procedure that do the job, but the example program implements the algorithm in ERRE language using an iterative method. This program is taken from the distribution disk and works in 320x200 graphics.
<syntaxhighlight lang="erre">
PROGRAM MYFILL_DEMO
Line 1,196 ⟶ 1,188:
FLOOD_FILL(100,100,0,1)
END PROGRAM
</syntaxhighlight>
Note: I haven't an "Upload files" item, so I can't show the resulting image!
=={{header|Euler Math Toolbox}}==
Using an emulated stack. EMT's recursive stack space is limited. For the notebook with images see [http://www.euler-math-toolbox.de/renegrothmann/Flood%20Fill.html this page].
<syntaxhighlight lang="text">
>file="test.png";
>A=loadrgb(file); ...
Line 1,240 ⟶ 1,231:
>B=floodfill(B,200,200,rgb(0,0,0.5),0.5);
>insrgb(B);
</syntaxhighlight>
=={{header|FBSL}}==
'''Using pure FBSL's built-in graphics functions:'''
<
#DEFINE WM_CLOSE 16
Line 1,280 ⟶ 1,270:
CIRCLE(FBSL.GETDC, Breadth / 2, Height / 2, 85, &HFFFFFF, 0, 360, 1, TRUE) _ ' White
(FBSL.GETDC, Breadth / 3, Height / 3, 30, 0, 0, 360, 1, TRUE) ' Black
END SUB</
'''Output:''' [[File:FBSLFlood.PNG]]
=={{header|Forth}}==
This simple recursive algorithm uses routines from [[Basic bitmap storage]].
<
: 3dup third third third ;
: 4dup 2over 2over ;
Line 1,312 ⟶ 1,301:
swap 1- swap
then
r> drop ;</
=={{header|Fortran}}==
{{works with|Fortran|90 and later}}
Line 1,319 ⟶ 1,307:
Here the ''target color'' paradigm is used. Again the <code>matchdistance</code> parameter can be tuned to ignore small differences that could come because of antialiasing.
<
use RCImageBasic
use RCImagePrimitive
Line 1,424 ⟶ 1,412:
end subroutine floodfill
end module RCImageArea</
Usage example excerpt (which on the test image will fill with green the inner black circle):
<
=={{header|FreeBASIC}}==
{{trans|BBC BASIC}}
<
' compile with: fbc -s console
Line 1,486 ⟶ 1,473:
Sleep 2000
If InKey <> "" OrElse InKey = Chr(255) + "k" Then End
Loop</
=={{header|Go}}==
An addition to code from the bitmap task:
<
func (b *Bitmap) Flood(x, y int, repl Pixel) {
Line 1,506 ⟶ 1,492:
}
ff(x, y)
}</
And a test program. Works with code from read ppm and write ppm to pipe tasks. For input, it uses a version of the test file converted by the Go solution to "Read an image through a pipe". For output it uses the trick from "PPM conversion through a pipe" to write the .png suitable for uploading to RC.
[[File:Go_flood.png|right]]
<
import (
Line 1,537 ⟶ 1,523:
log.Fatal(err)
}
}</
=={{header|Haskell}}==
This code uses the Bitmap and Bitmap.RGB modules defined [[Bitmap#Haskell|here]].
<
import Data.STRef
import Control.Monad
Line 1,651 ⟶ 1,636:
setSpanRight p False
scanWhileX b st p oldC newC (w, h) (Pixel (x, y + 1))
</syntaxhighlight>
=={{header|HicEst}}==
HicEst color fill is via the [http://www.HicEst.com/DeCoRation.htm decoration option of WRITE()]
<
WRITE(WIN=wh, DeCoRation="EL=14, BC=14") ! color 14 == bright yellow
Line 1,662 ⟶ 1,646:
WRITE(WIN=wh, DeCoRation="L=1/4, R=1/2, T=1/4, B=1/2, EL=25, BC=25")
WINDOW(Kill=wh)</
=={{header|J}}==
'''Solution:'''<br>
Uses <code>getPixels</code> and <code>setPixels</code> from [[Basic bitmap storage#J|Basic bitmap storage]].
<
NB. ref: http://www.jsoftware.com/pipermail/general/2005-August/023886.html
findcontig=: (|."1@|:@:>. (* * 1&(|.!.0)))^:4^:_@(* >:@i.@$)
Line 1,676 ⟶ 1,659:
NB.*floodFill v Floods area, defined by point and color (x), of image (y)
NB. x is: 2-item list of (y x) ; (color)
floodFill=: (1&({::)@[ ;~ 0&({::)@[ getFloodpoints ]) setPixels ]</
'''Example Usage:'''<br>
The following draws the same image as for the [[Flood fill#Tcl|Tcl example image]] below.<br>
Uses definitions from [[Basic bitmap storage#J|Basic bitmap storage]], [[Bresenham's line algorithm#J|Bresenham's line algorithm]] and [[Midpoint circle algorithm#J|Midpoint circle algorithm]].
<
myimg=: white makeRGB 50 70
lines=: _2]\^:2 ] 0 0 25 0 , 25 0 25 35 , 25 35 0 35 , 0 35 0 0
Line 1,689 ⟶ 1,672:
myimg=: (5 34;orange) floodFill myimg
myimg=: (5 36;red) floodFill myimg
viewRGB myimg</
'''Alternative findcontig:'''<br>
The following alternative version of <code>findcontig</code> is less concise but is leaner, faster, works for n-dimensions and is not restricted to numerical arrays.
<
eq=:[:}:"1 [:($$[:([:+/\1:,}:~:}.),) ,&_"1 NB. equal numbers for atoms of y connected in first direction
eq_nd=: i.@#@$(<"0@[([:, |:^:_1"0 _)&> [:EQ&.> <@|:"0 _)] NB. n-dimensional eq, gives an #@$,*/@$ shaped matrix
Line 1,699 ⟶ 1,682:
cnnct=: [: |:@({."1<.//.]) [: ; <@(,.<./)/.~
findcontig_nd=: 3 : '($y)${. ([:({.,~}:) ([ repl cnnct)/\.)^:([:+./@(~:/)2&{.)^:_ (,{.) eq_nd (i.~ ~.@,) y'</
=={{header|Java}}==
Input is the image, the starting node (x, y), the target color we want to fill, and the replacement color that will replace the target color. It implements a 4-way flood fill algorithm. For large images, the performance can be improved by drawing the scanlines instead of setting each pixel to the replacement color, or by working directly on the databuffer.
<
import java.awt.Point;
import java.awt.image.BufferedImage;
Line 1,744 ⟶ 1,726:
}
}
}</
And here is an example of how to replace the white color with red from the sample image (with starting node (50, 50)):
<
import java.awt.Color;
import java.awt.Point;
Line 1,763 ⟶ 1,745:
new Test();
}
}</
=={{header|Julia}}==
{{works with|Julia|0.6}}
Inspired to [[#Python | Python]] version.
<
function floodfill!(img::Matrix{<:Color}, initnode::CartesianIndex{2}, target::Color, replace::Color)
Line 1,814 ⟶ 1,795:
img = Gray{Bool}.(load("data/unfilledcircle.png"))
floodfill!(img, CartesianIndex(100, 100), Gray(false), Gray(true))
save("data/filledcircle.png", img)</
=={{header|Kotlin}}==
{{trans|Java}}
<
import java.awt.Color
Line 1,877 ⟶ 1,857:
ImageIO.write(image, "png", File(title))
JOptionPane.showMessageDialog(null, JLabel(ImageIcon(image)), title, JOptionPane.PLAIN_MESSAGE)
}</
=={{header|Liberty BASIC}}==
<
NoMainWin
WindowWidth = 267.5
Line 1,968 ⟶ 1,947:
result = FloodFill(mouseXX, (mouseYY - 1), targetColor)
End If
End Function</
=={{header|Lingo}}==
Lingo has built-in flood fill for image objects, so a custom implementation would be pointless:
<
=={{header|Lua}}==
Uses Bitmap class [[Bitmap#Lua|here]], with an RGB tuple pixel representation, then extending..
Preprocess with ImageMagick to simplify loading:
<
Some rudimentary PPM support:
<
local fp = io.open( filename, "rb" )
if fp == nil then return false end
Line 2,006 ⟶ 1,982:
end
fp:close()
end</
The task itself:
<
local b = self:get(x, y)
if not b then return end
Line 2,025 ⟶ 2,001:
end
ff(x, y)
end</
Demo:
<
bitmap:loadPPM("unfilledcirc.ppm")
bitmap:floodfill( 1, 1, { 255,0,0 }) -- fill exterior (except bottom right) with red
bitmap:floodfill( 50, 50, { 0,255,0 })-- fill larger circle with green
bitmap:floodfill( 100, 100, { 0,0,255 })-- fill smaller circle with blue
bitmap:savePPM("filledcirc.ppm")</
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
RegionBinarize[img, Image[SparseArray[pos -> 1, ImageDimensions[img]]], tol];
floodFill[img_Image, pos_List, tol_Real, color_List] :=
Line 2,043 ⟶ 2,018:
Dilation[createMask[img, pos, tol],1]
]
]</
{{out}}
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}}
<
proc floodFill*(img: Image; initPoint: Point; targetColor, replaceColor: Color) =
Line 2,099 ⟶ 2,100:
var img = readPPM("Unfilledcirc.ppm")
img.floodFill((30, 122), White, color(255, 0, 0))
img.writePPM("Unfilledcirc_red.ppm")</
=={{header|OCaml}}==
{{Trans|C}}
<syntaxhighlight 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)</syntaxhighlight>
=={{header|Pascal}}==
{{trans|C#}}
<syntaxhighlight lang="pascal">
program FloodFillTest;
Line 2,174 ⟶ 2,194:
end.
</syntaxhighlight>
=={{header|Perl}}==
Line 2,182 ⟶ 2,201:
The <tt>fill</tt> of the Perl package Image::Imlib2 is a flood fill (so the documentatin of Image::Imlib2 says). The target colour is the one of the starting point pixel; the color set with <tt>set_color</tt> is the fill colour.
<
use strict;
Line 2,191 ⟶ 2,210:
$img->fill(100,100);
$img->save("filledcirc.jpg");
exit 0;</
A homemade implementation can be:
<
use Image::Imlib2;
Line 2,242 ⟶ 2,261:
floodfill($img, 100,100, 0, 0, 0);
$img->save("filledcirc1.jpg");
exit 0;</
This fills better than the Image::Imlib2 <tt>fill</tt> function the inner circle, since because of JPG compression and thanks to the <tt>$distparameter</tt>, it "sees" as black also pixel that are no more exactly black.
=={{header|Phix}}==
{{Trans|Go}}
Requires read_ppm() from [[Bitmap/Read_a_PPM_file#Phix|Read a PPM file]], write_ppm() from [[Bitmap/Write_a_PPM_file#Phix|Write a PPM file]]. <br>
Uses the output of [[Bitmap/Midpoint_circle_algorithm#Phix|Midpoint circle algorithm]] (Circle.ppm), results may be verified with demo\rosetta\viewppm.exw
<
include ppm.e -- blue, green, read_ppm(), write_ppm() (covers above requirements)
Line 2,275 ⟶ 2,293:
write_ppm("FloodIn.ppm",img)
img = FloodFill(img, 10, 10, green)
write_ppm("FloodOut.ppm",img)</
=={{header|PicoLisp}}==
Using the format of [[Bitmap#PicoLisp|Bitmap]], a minimal recursive solution:
<
(let Target (get Ppm Y X)
(recur (X Y)
Line 2,288 ⟶ 2,305:
(recurse X (dec Y))
(recurse X (inc Y)) ) ) )
Ppm )</
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}}==
<
declare (x, y) fixed binary;
declare fill_color bit (24) aligned;
Line 2,320 ⟶ 2,336:
if pixel_color = area_color then call fill (x, y+1, fill_color);
end fill;</
The following PL/I statements change the color of the white area
of the sample image to red, and the central orb to green.
<syntaxhighlight lang="text">
/* Fill the white area of the suggested image with red color. */
area_color = (24)'1'b;
Line 2,331 ⟶ 2,347:
area_color = '0'b;
call fill (125, 125, '000000001111111100000000'b );
</syntaxhighlight>
=={{header|Processing}}==
<
import java.util.Queue;
import java.util.LinkedList;
Line 2,413 ⟶ 2,428:
img.pixels[pixel_position(x, y)] = fill_color;
return true;
}</
==={{header|Processing Python mode}}===
<
image_file = "image.png"
Line 2,489 ⟶ 2,504:
return False
img.pixels[pixel_position(x, y)] = fill_color
return True</
=={{header|PureBasic}}==
=== built-in ===
<
; Fills an Area in red</
=== Iterative ===
<
old_color = Point(x,y)
NewList stack.POINT()
Line 2,526 ⟶ 2,540:
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf</
=={{header|Python}}==
<
import Image
def FloodFill( fileName, initNode, targetColor, replaceColor ):
Line 2,574 ⟶ 2,587:
break
return img
</syntaxhighlight>
===Usage example===
<
# "FloodFillClean.png" is name of input file
# [55,55] the x,y coordinate where fill starts
Line 2,585 ⟶ 2,598:
#The resulting image is saved as Filled.png
img.save( "Filled.png" )
</syntaxhighlight>
=={{header|R}}==
'''Stack-based recursive version'''
<syntaxhighlight lang="r">
library(png)
img <- readPNG("Unfilledcirc.png")
Line 2,613 ⟶ 2,625:
image(M, col = c(1, 0, 2))
</syntaxhighlight>
'''Queue-based version (Forest Fire algorithm)'''
<syntaxhighlight lang="r">
library(png)
img <- readPNG("Unfilledcirc.png")
Line 2,653 ⟶ 2,665:
image(M, col = c(1, 0, 2, 3))
</syntaxhighlight>
=={{header|Racket}}==
<
#lang racket
Line 2,739 ⟶ 2,750:
;; ... and after:
bm
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
Line 2,746 ⟶ 2,756:
Using bits and pieces from various other bitmap tasks.
<syntaxhighlight lang="raku"
class Bitmap {
has Int ($.width, $.height);
Line 2,818 ⟶ 2,828:
$outfile.write: $b.P6;
</syntaxhighlight>
See output image [https://github.com/thundergnat/rc/blob/master/img/Bitmap-flood-perl6.png Bitmap-flood-perl6 ] (offsite image file, converted to PNG for ease of viewing)
=={{header|REXX}}==
{{trans|PL/I}}
<
black= '000000000000000000000000'b /*define the black color (using bits).*/
red = '000000000000000011111111'b /* " " red " " " */
Line 2,848 ⟶ 2,857:
return
/*──────────────────────────────────────────────────────────────────────────────────────*/
@: parse arg $x,$y; return image.$x.$y /*return with color of the X,Y pixel.*/</
<br><br>
=={{header|Ruby}}==
Uses [[Raster graphics operations/Ruby]]
<
require_relative 'raster_graphics'
Line 2,911 ⟶ 2,919:
bitmap.draw_circle(Pixel[200, 100], 40, RGBColour::BLACK)
bitmap.flood_fill(Pixel[140, 160], RGBColour::BLUE)
bitmap.save_as_png('flood_fill.png')</
{{libheader|RubyGems}}
Line 2,917 ⟶ 2,925:
JRubyArt is a port of Processing to the ruby language
<
Pixel = Struct.new(:x, :y)
Line 2,969 ⟶ 2,977:
size(256, 256)
end
</syntaxhighlight>
=={{header|Rust}}==
<
/* Naive Rust implementation of RosettaCode's Bitmap/Flood fill excercise.
*
Line 3,061 ⟶ 3,068:
write_image(data);
}</
=={{header|Scala}}==
Line 3,069 ⟶ 3,075:
See [[Basic_bitmap_storage#Scala|Basic Bitmap Storage]] for RgbBitmap class.
<
import scala.collection.mutable
Line 3,111 ⟶ 3,117:
}
}
}</
=={{header|Standard ML}}==
This implementation is imperative, updating the pixels of the image as it goes.
Line 3,118 ⟶ 3,123:
data structures instead.
<
* fundamental would change if we used more colors. *)
datatype color = Black | White
Line 3,166 ⟶ 3,171:
(* Fill the image with black starting at the center. *)
val () = fill test Black (3,3)</
=={{header|Tcl}}==
{{libheader|Tk}}
{{tcllib|struct::queue}}
Using code from [[Basic bitmap storage#Tcl|Basic bitmap storage]], [[Bresenham's line algorithm#Tcl|Bresenham's line algorithm]] and [[Midpoint circle algorithm#Tcl|Midpoint circle algorithm]]
<
package require Tk
package require struct::queue
Line 3,245 ⟶ 3,249:
toplevel .flood
label .flood.l -image $img
pack .flood.l</
Results in:
[[Image:Tcl_flood_fill.png]]
=={{header|Wren}}==
{{libheader|DOME}}
Line 3,257 ⟶ 3,260:
When the up arrow is pressed, the red square changes to blue and when the down arrow is pressed the blue square turns back to red.
<
import "dome" for Window
import "input" for Keyboard
Line 3,327 ⟶ 3,330:
}
var Game = Bitmap.new("Bitmap - flood fill", 600)</
=={{header|XPL0}}==
[[File:FloodXPL0.gif|right|Output]]
<
proc Flood(X, Y, C, C0); \Fill an area of color C0 with color C
Line 3,390 ⟶ 3,393:
if ChIn(1) then []; \wait for keystroke
SetVid(3); \restore normal text mode
]</
=={{header|zkl}}==
[[file:Flood_before.zkl.jpg|right]][[file:Flood.zkl.jpg|right]]
Line 3,397 ⟶ 3,399:
Uses the PPM class from http://rosettacode.org/wiki/Bitmap/Bresenham%27s_line_algorithm#zkl
<
targ,h,w:=pixmap[x,y], pixmap.h,pixmap.w;
stack:=List(T(x,y));
Line 3,410 ⟶ 3,412:
}
}
}</
<
pixmap.circle(101,200,100,0); pixmap.circle(75,100,25,0);
Line 3,418 ⟶ 3,420:
flood(pixmap, 75,100, 0x00|00|F0);
pixmap.writeJPGFile("flood.zkl.jpg");</
{{omit from|AWK}}
{{omit from|Computer/zero Assembly|this language doesn't support video output and only has 32 bytes of RAM}}
{{omit from|Lotus 123 Macro Scripting}}
{{omit from|PARI/GP}}
|