spreading colors!

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
blyzzard1
Prole
Posts: 8
Joined: Thu Jan 23, 2014 11:22 am

spreading colors!

Post 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 :
Attachments
lua - Copie (2).rar
(351.01 KiB) Downloaded 88 times
jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

Re: spreading colors!

Post by jjmafiae »

love.graphics.setColor() or having two pictures?
blyzzard1
Prole
Posts: 8
Joined: Thu Jan 23, 2014 11:22 am

Re: spreading colors!

Post by blyzzard1 »

im trying to make the colors spread on the map without spreading on the scea is this function able to do that??
blyzzard1
Prole
Posts: 8
Joined: Thu Jan 23, 2014 11:22 am

Re: spreading colors!

Post 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
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: spreading colors!

Post by veethree »

I believe you may be looking for the flood fill algorithm.
blyzzard1
Prole
Posts: 8
Joined: Thu Jan 23, 2014 11:22 am

Re: spreading colors!

Post by blyzzard1 »

could you help me to implent this algorithm on my map??
i never used something like that before.
blyzzard1
Prole
Posts: 8
Joined: Thu Jan 23, 2014 11:22 am

Re: spreading colors!

Post 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?
Attachments
lua - Copie (2) - Copie.rar
(351.54 KiB) Downloaded 84 times
blyzzard1
Prole
Posts: 8
Joined: Thu Jan 23, 2014 11:22 am

Re: spreading colors!

Post 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:
Attachments
lua - Copie (2) - Copie.rar
(351.54 KiB) Downloaded 97 times
lachlaan
Prole
Posts: 30
Joined: Sun Jun 30, 2013 7:23 pm

Re: spreading colors!

Post 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.
User avatar
slime
Solid Snayke
Posts: 3160
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: spreading colors!

Post 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. :)
Post Reply

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 2 guests