Temple of The Roguelike Forums

Development => Programming => Topic started by: Krice on March 26, 2010, 07:43:52 PM

Title: Need for weighed scattering routine
Post by: Krice on March 26, 2010, 07:43:52 PM
I might as well ask for help to implement a routine which shoud scatter tiles around circular area and use a weight information to put more stuff on center area. Any ideas? My math skills are lousy, so I have hard time trying to figure this out.
Title: Re: Need for weighed scattering routine
Post by: Hi on March 26, 2010, 07:59:38 PM
Would you like the density to fall off as an inverse square?  Or would you prefer Gaussian?
Title: Re: Need for weighed scattering routine
Post by: Krice on March 26, 2010, 09:35:54 PM
Would you like the density to fall off as an inverse square?  Or would you prefer Gaussian?

You can decide that.
Title: Re: Need for weighed scattering routine
Post by: corremn on March 27, 2010, 01:09:46 AM
Would you like the density to fall off as an inverse square?  Or would you prefer Gaussian?

You can decide that.
LOL
Title: Re: Need for weighed scattering routine
Post by: Hi on March 27, 2010, 03:11:25 AM
I like bell curves because they are easy
if you do this for both the x and the y you will end up with a nice circular distribution of items

R=radius
repeat 2 * R times
{
    flip a coin
    if heads
        position+1
}
position - R/2


Although the possible positions is square, the probabilities is circular and so to your eyes it looks like a circle.

if you really wanted you could force it to be circular by looking at each point
dx means the difference between old x and new x
dy is the same for y
while(dx^2 +dy ^2 is > R^2)
    use bresen's line to move it back toward the center
Title: Re: Need for weighed scattering routine
Post by: Krice on March 27, 2010, 10:47:12 AM
Sorry, I'm too dumb to make anything out of that pseudo code. Anyway, I decided to try flood fill and randomly skip seeds to create irregular shape (it would be always diamond shaped without that). I think it's working nicely and I could add that weigh part using the iteration count to determine the rough distance from the center. I'm only looking a way to create stuff like lakes and forests, or scattered rocks, anything like that.
Title: Re: Need for weighed scattering routine
Post by: Hi on March 27, 2010, 05:22:36 PM
That should work, the best algorithm is the one you understand perfectly.