Page 1 of 1

spreading colors!

Posted: Sat Jan 25, 2014 3:47 pm
by blyzzard1
the game i am trying to create would be a kind of simulator where the color would represent a plague (or a vaccination campaing).
i would like to fill up the blue country with red (the color would spread at a knew speed) and after a few seconds the green color would start spreading at many place in the same time (also with a knew speed)

I would like to know 4 things :
how should i make thje color spread?
how could i make color spread on the image of the world map without coloring the sea?
how could I create bridge between the country?
how could i create a function that would be trigged later and would also spread color (like the first one
but it would even color the first one)
and heres the map were i am trying to make de color spread :

Re: spreading colors!

Posted: Sat Jan 25, 2014 4:28 pm
by jjmafiae
love.graphics.setColor() or having two pictures?

Re: spreading colors!

Posted: Sat Jan 25, 2014 4:38 pm
by blyzzard1
im trying to make the colors spread on the map without spreading on the scea is this function able to do that??

Re: spreading colors!

Posted: Sat Jan 25, 2014 4:39 pm
by blyzzard1
and their is on picture but two colors
red would start spreading with a mouse click
and greend would spread after a set duration

Re: spreading colors!

Posted: Sat Jan 25, 2014 5:11 pm
by veethree
I believe you may be looking for the flood fill algorithm.

Re: spreading colors!

Posted: Sat Jan 25, 2014 5:17 pm
by blyzzard1
could you help me to implent this algorithm on my map??
i never used something like that before.

Re: spreading colors!

Posted: Sat Jan 25, 2014 5:57 pm
by blyzzard1
i have been able to set function to generate the color but now i need to find a way to make it spread on the contry (also the color doesn't want to appear on the picture)
anyone can help me with those 2 things?

Re: spreading colors!

Posted: Sat Jan 25, 2014 6:00 pm
by blyzzard1
well now i only need 2 function:
how to make in the spread
and how to make it spread only on the blue contry
heres my work by now:

Re: spreading colors!

Posted: Sun Jan 26, 2014 8:26 pm
by lachlaan
You can write a sort of data map that corresponds to the image map, a grid of places on your map, and then apply the algorithm to that based on the map color info.

Alternatively, you could draw the picture onto a canvas and then use https://www.love2d.org/wiki/Canvas:getPixel to make the previously mentioned grid of your map, or any map in the future.

Alter-alternatively , you could use the getPixel function with a list of "active pixels" that spread with rules similar to the game of life, except not as limited when it comes to being cramped. And just make the clicked pixel spread in a + shape around it, then remove it from active list and add the 4 new pixels to active list and make them check for blue pixels around them.

Re: spreading colors!

Posted: Sun Jan 26, 2014 8:39 pm
by slime
FYi - Canvas:getPixel is very, very slow. Nearly as slow as [wiki]Canvas:getImageData[/wiki] most of the time. So just use the latter function if you want to get more than one pixel from a Canvas, unless memory is the primary concern and performance is no concern. :)