Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Need something like the flood fill.... Any ideas?
Started by info1911 May 03 2014 08:04 AM

14 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

info1911

[GLOBAL: userInfoPane.html]
info1911
  • Observer

  • 13 posts
  • Corona SDK

Hi everyone

 

I am developing a coloring book and need something like the flood fill.

If the user tap in an area the complete area until the next black stroke should be filled with f.e. the color red.

 

Have anyone an idea?

 

I am new in Corona/.lua and thankful for every hint.

 

Greetings

 

Bianca



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,922 posts
  • Enterprise

You can't do flood fill's with Corona SDK.  What I've done in the past is cut the coloring book into pieces and each piece has a touch handler on it.  Then you can do a :setFillColor() call to change the color of the piece.  The pieces will likely need to be masked so that the outside each piece isn't touchable.

 

Rob



[TOPIC: post.html]
#3

info1911

[GLOBAL: userInfoPane.html]
info1911
  • Observer

  • 13 posts
  • Corona SDK

Oh ok. Sad :(. Thx for your reply

[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,922 posts
  • Enterprise

Don't dismiss the idea about slicing each colorable spot into it's own image and using :setFillColor.  It works fairly well.

 

Rob



[TOPIC: post.html]
#5

paulscottrobson

[GLOBAL: userInfoPane.html]
paulscottrobson
  • Contributor

  • 456 posts
  • Corona SDK

Would it be possible to use a ShapeObject to do this as well, so you colouring book is defined by vectors ? Are input events on Shapes limited to the shape pattern or a bounding rectangle ?



[TOPIC: post.html]
#6

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,922 posts
  • Enterprise

I know we support polygons which can be filled (may be an advanced graphics feature for Pros and up), but I think there is a limit to the number of vectors which would make smooth curves impossible.



[TOPIC: post.html]
#7

FAVIO007

[GLOBAL: userInfoPane.html]
FAVIO007
  • Observer

  • 14 posts
  • Corona SDK

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!



[TOPIC: post.html]
#8

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,922 posts
  • Enterprise

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



[TOPIC: post.html]
#9

euphoriacorona

[GLOBAL: userInfoPane.html]
euphoriacorona
  • Contributor

  • 133 posts
  • Corona SDK

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.

[TOPIC: post.html]
#10

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

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



[TOPIC: post.html]
#11

FAVIO007

[GLOBAL: userInfoPane.html]
FAVIO007
  • Observer

  • 14 posts
  • Corona SDK

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!



[TOPIC: post.html]
#12

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

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



[TOPIC: post.html]
#13

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

Just uploaded to Gist:

 

https://gist.github.com/GymbylCoding/8fc95e1e8d1ce2c152ef

 

Let me know if there's any way I can help.

 

- Caleb



[TOPIC: post.html]
#14

FAVIO007

[GLOBAL: userInfoPane.html]
FAVIO007
  • Observer

  • 14 posts
  • Corona SDK

Thanks so much Caleb. I will try the code and then I will let you know about the result.



[TOPIC: post.html]
#15

prh

[GLOBAL: userInfoPane.html]
prh
  • Enthusiast

  • 36 posts
  • Corona SDK

Great work! Worked perfectly! And just what I need for one of my projects!




[topic_controls]
[/topic_controls]