Bitmap/Flood fill: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Add a Perl 6 example) |
m (→{{header|REXX}}: added whitespace.) |
||
Line 2,280: | Line 2,280: | ||
white= '111111111111111111111111'b /* " " white " " " */ |
white= '111111111111111111111111'b /* " " white " " " */ |
||
/*image is defined to the test image. */ |
/*image is defined to the test image. */ |
||
hx=125; |
hx= 125; hy= 125 /*define limits (X,Y) for the image. */ |
||
area=white; call fill 125, 25, red |
area= white; call fill 125, 25, red /*fill the white area in red. */ |
||
area=black; call fill 125, 125, green |
area= black; call fill 125, 125, green /*fill the center orb in green. */ |
||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
fill: procedure expose image. hx hy area; parse arg x,y,fill_color /*obtain the args.*/ |
fill: procedure expose image. hx hy area; parse arg x,y,fill_color /*obtain the args.*/ |
||
if x<1 | x>hx | y<1 | y>hy then return /*X or Y are outside of the image area*/ |
if x<1 | x>hx | y<1 | y>hy then return /*X or Y are outside of the image area*/ |
||
pixel=image.x.y |
pixel= image.x.y /*obtain the color of the X,Y pixel. */ |
||
if pixel\==area then return |
if pixel \== area then return /*the pixel has already been filled */ |
||
/*with the fill_color, or we are not */ |
/*with the fill_color, or we are not */ |
||
/*within the area to be filled. */ |
/*within the area to be filled. */ |
||
image.x.y= |
image.x.y= fill_color /*color desired area with fill_color. */ |
||
pixel=@(x , y-1); |
pixel= @(x , y-1); if pixel==area then call fill x , y-1, fill_color /*north*/ |
||
pixel=@(x-1, y ); |
pixel= @(x-1, y ); if pixel==area then call fill x-1, y , fill_color /*west */ |
||
pixel=@(x+1, y ); |
pixel= @(x+1, y ); if pixel==area then call fill x+1, y , fill_color /*east */ |
||
pixel=@(x , y+1); |
pixel= @(x , y+1); if pixel==area then call fill x , y+1, fill_color /*south*/ |
||
return |
return |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |