Writing a Fill tool

Started by
1 comment, last by Arek the Absolute 22 years, 1 month ago
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
-Arek the Absolute"The full quartet is pirates, ninjas, zombies, and robots. Create a game which involves all four, and you risk being blinded by the sheer level of coolness involved." - Superpig
Advertisement
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

Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site

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.

This topic is closed to new replies.

Advertisement