#### Archived

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

# Writing a Fill tool

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

## 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 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 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.

1. 1
2. 2
3. 3
Rutin
18
4. 4
5. 5
JoeJ
13

• 14
• 10
• 23
• 9
• 49
• ### Forum Statistics

• Total Topics
632638
• Total Posts
3007584
• ### Who's Online (See full list)

There are no registered users currently online

×