Sign in to follow this  
greenpig83

Generate random map of fixed size chunk

Recommended Posts

greenpig83    330
Hi i'm working on a rts map, based on tile. And when generate the random map, I want to divide things into chunk of fixed size. Example I want to have about 10 chunks of forest of size 100 (100 tiles /chunk, no need exactly just about, so we can control it)... Or dessert, water... The chunk should have random and natural shape!
 
Of couse we all think about perlin noise, cause it give us the most random and natural shape. However after research about the perlin and its application. It's not easy to control the size of each island, you change some noise parameter (octave,persist,frequence..) : http://libnoise.sourceforge.net/tutorials/tutorial4.html
 
It does change the result map, but it's not easy to control the size. Do you know other algorith that address my problem, or should I try to change the result of the perlin algorith to create my chunk ?
Edited by greenpig83

Share this post


Link to post
Share on other sites
Postie    1559

Perlin Noise provides a source of randomness but is generally unsuitable in its raw form. It is typical to combine multiple levels of Perlin Noise with different frequencies and amplitudes as the result has detail at different scales. With that in mind, it's not unreasonable to apply another process on the result to create specific topography. For example, if you wanted a single island, you might create a mask that emphasizes values towards the centre of the map, but eliminates those towards the edges. If you want multiple islands, some sort of checkerboard mask might be suitable, but it could be too regular depending on your application.

 

Another approach is to raise or lower the virtual sealevel in your terrain map, which will separate or join landmasses.

Share this post


Link to post
Share on other sites
TheUnnamable    1129

It really depends on what shape you want. Also, if you don't want *exactly* 100 blocks, just to approximate, that helps a lot.

Using the forest example you gave, I would create an ellipse consisting of 90 blocks, then adding random smaller patches ( circles, ellipses, whatever, you name it ) until I'm done.

Or just morph that ellipse. Maybe distort it, using perlin noise. Or use the perlin noise and mask it with the ellipse. The ellipse would have high values on the inside ( so that the ellipse is guaranteed to be filled ) and fade to negative values over some distance.

Or choose a bounding box and iterate with it until having enough patches. Each iteration would choose a random position in the bounding box, check it's distance from the center and use it as a probability to create a patch at that location.

If you're marginally past your tile count, you can even chop off random patches ( starting from the sides would be a good idea, a forest with a hole in it's center would be weird )

 

If you are rasterizing these patches on CPU, it's really not hard to count the number of tiles filled. Otherwise, you could just add up the patches' areas and hope for the best.
Also, I've been using your forest example, but you could apply these principles to almost anything you want to generate. I really encourage visual testing, as that gives you a clear clue about the shape you get with these methods. Feel free to experiment ( even with some weird exotic functions ), you can go iterative and put down patches, or you could define functions, use sine waves, gradients, or even the mix of the two. Go really wild with your experiments :)

Share this post


Link to post
Share on other sites
greenpig83    330

Of course it's not need to be exactly 100, just about 100, so you can control it. So that's there are not too much forest, or the forest are not too big. Just about that size is ok! I know there are a lot of way to solve this problem, so I just want the most simple way, and easy to use in my project. This is just a very small part of the project, so I dont want to spend too much time on it, just make it's work is ok! Thanks!

The shape is not very important, no need to look realistic, just not too strange is ok and not too similiar. Just like a province on map...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this