|
Hi, I need to write a flood fill algorithm using C# in Unity, in order to make a simple colour-fill tool similar to the one in MS paint. The user will be presented with a white texture with black line-drawings to be filled. They will pick a colour from a pallet, and click to fill sections of the line-drawing with colour. Black will always represent the boundary colour. Here is the flood-fill method I have written. The code surrounding the sample is checked and works, but the algorithm seems to only fill one line to the left of the clicked pixel. It would be great to get some advice on this, either to find out what is wrong with the existing code, or find another method of doing colour-fills. I think it's overflowing the stack. EDIT: New version of code below, still with same problem: void FloodFill() { }
(comments are locked)
|
|
Ok, it seems you're trying to implement the second alternative floodfill algorithm on wikipedia but there are some things wrong or a bit messy:
I've had some time and implemented the algorithm myself and created two extension methods FloodFillArea and FloodFillBorder if someone is interested. Note that Get/SetPixel inherently check boundaries, depending on whether the texture is set to repeat or clamp.
Mar 04 '12 at 06:53 AM
Eric5h5
Good to know, thanks ;)
Mar 04 '12 at 11:43 AM
Bunny83
Thanks, this is an excellent answer :) I'll have a go at making the recommended changes.
Mar 04 '12 at 06:25 PM
jameshill88
Oh and you're exactly right, this is the floodfill from wikipedia
Mar 04 '12 at 06:26 PM
jameshill88
Hey @Bunny83, thanks for your work on this algorithm. I needed to add a tolerance factor for the color comparison for a project I'm working on. I created a Gist here incase anyone else wants to use it. https://gist.github.com/dchen05/5298031
Apr 03 at 02:47 AM
dchen05
(comments are locked)
|
