Archived

This topic is now archived and is closed to further replies.

Writing a Fill tool

This topic is 5775 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Anyone know a clean way to write a fill tool, or at least know a tutorial that might suggest how? I only need a real simple one, zero fill tolerance, etc... But frankly I''m clueless how to write one that wouldn''t be a total mess. Maybe that''s how they always are, but I figured I''d check. Thanks! Arek the Absolute

Share this post


Link to post
Share on other sites
Assuming you mean graphics filling...

simplest way would be to use already written GDI functions to do it. e.g. ExtFloodFill(), GradientFill(), FillPath() etc.

Algorithmically, doing it yourself, the simplest algorithm I can think of is the old Amiga hardware style one (off the top of my head...):


for (y=0; y<height; ++y)
{
bool fill = false;
for (x=0; x<width; ++x)
{
if (image[x][y] == outlineColour)
{
fill = !fill;
}

if (fill)
{
image[x][y] = fillColour;
}
}
}


--
Simon O'Connor
Creative Asylum Ltd
www.creative-asylum.com

Edited by - S1CA on February 20, 2002 2:13:23 PM

Share this post


Link to post
Share on other sites
if you want a border fill, or something like that, then the easiest thing to do is recusion.

off the top of my head,
  
int fill(int atx, int aty, int fillColor, int borderColor)
{
if ( color[x][y] != borderColor)
color[x][y] = fillColor;
else
for(int x = atx - 1; x < atx+ 1; x++)
for (int y = aty - 1; y < aty + 1; y++)
if (x != atx && y != aty && color[x][y] != fillColor)
fill(x,y,fillcolor,bordercolor);
}

ofcouse this is not optimised, and will overflow the stack on big areas, so you need to modify it a bit.

Share this post


Link to post
Share on other sites