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

Mon, 30 Apr 2018, 11:50
spinal
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!
Mon, 30 Apr 2018, 11:50
Jayenkai
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!''
Mon, 30 Apr 2018, 12:29
spinal
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!
Mon, 30 Apr 2018, 13:48
Pakz
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.

cromdesi.home.xs4all.nl/agkmobile/appgamekitmobiletutorial.pdf
Tue, 01 May 2018, 09:12
Dan
The blitzbasic forum still has few flood fill examples:

http://mojolabs.nz/codearcs.php?cat=1&order=&asc=&lang_id=1
Thu, 03 May 2018, 16:58
TomToad
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.