Hi. I am trying to develop a Coloring book application and I’d like to know if the function “Fill bucket” –the functionality to fill an area limited by lines on the draw automatically with the color selected- it could be easily to develop. Thanks!
Flood fill is going to near impossible to do if your just drawing points on the screen. If you are building up a series of points and you don’t exceed the maximum amount to create a display.newPolygon(), then you could replace the line with a newPolygon() and fill that. But I think in most drawing cases, its going to be very hard to make a newPolygon().
Rob
I did a flood fill game before with Corona, years back. Cannot remember the algorithms i used, and i dont believe i have the code anymore.
I do recall it working very well though.
I also did a flood fill a while back while working on a “pixel drawing” sample (never finished or published :() ; it wasn’t too hard. As Rob said, Corona isn’t the best engine for this particular role, but it’s still possible.
Basically what you’ll want to do is populate the screen with rectangles (basically simulating pixels), the smaller the rectangle, the better the “granularity” of the picture, then just flood fill on the rectangles. You can find some algorithms that are pretty simple at Wikipedia: http://en.wikipedia.org/wiki/Flood_fill. You can also use vector lines (or polygons) to describe your shapes and fill them with rectangles if you want a crisper shape.
You can actually expand the “lots of rectangles” approach and go on to do pen hardness (color a circle of “pixels” progressively less based on distance from center), eraser hardness (same but with erasing), color selection (very similar to flood fill) and more.
- Caleb
Thanks for your comments.
Don’t you know who can help with this development?
Don’t you have any code in order not to start from the scratch?
Thanks!
I believe I do have the code; if you’ll let me find it and allow a bit for cleanup (this predates graphics 2.0), I’ll get it to you ASAIC. I’ll estimate probably sometime tomorrow.
- Caleb
Just uploaded to Gist:
https://gist.github.com/GymbylCoding/8fc95e1e8d1ce2c152ef
Let me know if there’s any way I can help.
- Caleb
Thanks so much Caleb. I will try the code and then I will let you know about the result.
Great work! Worked perfectly! And just what I need for one of my projects!