-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|302|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Off Topic -> Flood Fill Function

Posted : Monday, 30 April 2018, 11:50
Does anyone have in their code collection a non-recusive flood fill function? I remember about 20 or so years ago using one that filled an area using a diamond shape, rather than lines and it worked no matter the size of the fill area. Everything I am finding uses a stack of some sort, which I can't do (tiny stack, almost no RAM). Any ideas?

Check out my excellent homepage!
Posted : Monday, 30 April 2018, 11:50
Same as my AI Pathfinding code..
Essentially start from x/y, and grow your loop outward until you ain't drawing no more.

Needs a secondary grid to keep track of what's been filled, though. That will probably be an issue!

Perhaps if you make secondary use of the pixel-values themselves to keep track of what's been filled?
(eg, instead of filling with R,G,B, fill with R+500,G,B. Then after the fill is complete, scan through the whole image and remove the +500)

''Load, Next List!''
Posted : Monday, 30 April 2018, 12:29
That might take a lot more thinking.... I'm using a palette based screen, probably with only 4 colours...

I was thinking along the lines of path finding, that's part of the reason I was trying to hunt through playmycode, I have a maze generator in there somewhere I think.

Check out my excellent homepage!
Posted : Monday, 30 April 2018, 13:48
I did a very simple flood fill not that long ago. It was for pathfinding as I added numbers from the initial start growing the further they got away.

Because it needed to be simple I just continuously looped the array (for x and y)and looked for the current fill number and filled l/r/u/d with the next number if not set before. No stack.

I have it in my appgamekit book.

Posted : Tuesday, 01 May 2018, 09:12
The blitzbasic forum still has few flood fill examples:

Posted : Thursday, 03 May 2018, 16:58
I now present to you a non-recursive, no stack, no extra arrays, 2 bit per pixel fill routine. This was a challenging project here and was actually surprised I got it to work the very first time. The program is written in BlitzMax, hopefully you can convert it to whatever language and platform you are using. That is, if you can understand what I am doing.

Since I didn't know the exact format of the image you are using, I decided to make an abstract type which you can extend. You only need to implement the two abstract methods WritePixel and ReadPixel which sets/returns the color index at the x,y coordinates, and you need to set the Width and Height fields to the image's dimentions. The example included with the code shows a way to extend the type for use.

The example included is a simple paint program, press left mouse button to draw, right mouse button to fill an area with current color, and the number keys 1-4 to change to one of the four colors. Tried a variety of shapes to fill and haven't gotten it to crash yet.