Fractal heightmaps: Now with Gui!

Post your custom scenarios here. Saved games also welcome. All Transport Tycoon games acceptable (including TTDPatch and OpenTTD).
zooks
Transport Coordinator
Transport Coordinator
Posts: 262
Joined: 29 Jun 2006 08:36

Fractal heightmaps: Now with Gui!

Post by zooks » 21 Jun 2012 07:12

Hi all,

Ive been playing around with fractal algorithms to create heightmaps for ottd. Especially the 1 height difference limit makes it hard to have nice looking mountains (with peaks) in the game. I wrote a map generator using the plasma fractal (random midpoint displacement), while forcing it to make water edges to get some big continental shapes. Tell me what you think, I myself am quite happy with how mountain ranges look while still enough flat land to have a playable scenario.

Ingame example:
screenshot#13.png
Ingame shot of a mountain range
(200.87 KiB) Downloaded 13 times
The GUI should be really intuitive. Select some parameters, seeds and generate until you see something that suits you:
2013-04-18-191115_1024x600_scrot.png
2013-04-18-191115_1024x600_scrot.png (104.69 KiB) Viewed 5526 times


The results will be saved in a directory called 'output' and consist of both a coloured image and a greyscale image. The coloured looks nice, and the greyscale is for use in openttd.

If you encounter some nice maps/seeds, please share them here with the rest :) Also if you make improvements to the script, I would very much like to see those.

cheers

zooks


edit (09/04/13): added python source
edit (11/04/13): added link to png library
edit (18/04/13): uploaded the gui
Attachments
mapgen.tar.gz
The source code (executable python script + png library)
Depends on pygtk > 2.0
(180 KiB) Downloaded 310 times
Last edited by zooks on 18 Apr 2013 17:28, edited 3 times in total.

Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Fractal heightmaps

Post by Kogut » 21 Jun 2012 08:04

It seems very interesting, what about publishing more heightmaps?
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD

zooks
Transport Coordinator
Transport Coordinator
Posts: 262
Joined: 29 Jun 2006 08:36

Re: Fractal heightmaps

Post by zooks » 21 Jun 2012 10:38

Here you go, 65 heightmaps (30mb). Takes me around 4 minutes each to make them. I'm still thinking about adding rivers but I'm not sure how to make those look good without making the generation process take too long.

User avatar
FLHerne
Tycoon
Tycoon
Posts: 1537
Joined: 12 Jul 2011 12:09
Location: St Ives, Cambs, UK

Re: Fractal heightmaps

Post by FLHerne » 21 Jun 2012 11:23

That is rather cool. :bow: They certainly look better than the standard map generator...would it work for the More Heightlevels patch/ChillPP? Then you could do really huge mountains! :D
Temporary Permanent signature filling text. Content coming soon delayed indefinitely! Oh, and I have had a screenshot thread.
Linux user (XMonad DWM/KDE, Arch), IRC obsessive and rail enthusiast. No longer building robots; now I ring church bells.
Author of an incredibly boring stickied post about NewGRFs.

ZxBiohazardZx
Tycoon
Tycoon
Posts: 1534
Joined: 14 Mar 2006 12:46
Location: Netherlands
Contact:

Re: Fractal heightmaps

Post by ZxBiohazardZx » 21 Jun 2012 11:24

any chance you could share sources for the generator?

User avatar
jor[D]1
Director
Director
Posts: 607
Joined: 17 Aug 2010 10:36
Location: Netherlands

Re: Fractal heightmaps

Post by jor[D]1 » 21 Jun 2012 13:10

Realy cool, but I think you should get big rivers, (A bit like the rhine donau etc.)

See attached image.

Also I think cities are a bit concentrated too much at the plains. (Or only there). Some small flat low coasts would be great to get some hard to reach coastal villages.

The bottum aprt of that big lake already looks like a river, it reminded me about my holiday at the Mozel.

Edit:
ADVICE TOO ALL!

Go play this maps with you nicest GRF, they are so great. Finnally Make rail building a challange.

(1 small realistic railway line: 26 tunnels, 14 bridges and uncountable corners)
Attachments
Geen naam, 01-01-1930.png
(1.27 MiB) Downloaded 12 times
View my (train)pictures on Flickr

zooks
Transport Coordinator
Transport Coordinator
Posts: 262
Joined: 29 Jun 2006 08:36

Re: Fractal heightmaps

Post by zooks » 22 Jun 2012 07:36

FLHerne wrote:That is rather cool. :bow: They certainly look better than the standard map generator...would it work for the More Heightlevels patch/ChillPP? Then you could do really huge mountains! :D
With a few modifications it would indeed as it basically translates a 0 to 1 float value to 0 to 15 ints atm, though larger mountain areas are needed to get the higher peaks, maybe in combination with the extra large maps patch as well. If I generate a 256*256 map, mountains will be about half as high as 2048*2048 because there's less space..
ZxBiohazardZx wrote:any chance you could share sources for the generator?
Sure I will, though preferably not in its current state, I want to make the code a bit more readable before sharing it and maybe add rivers and deal with some oddities. If youre really eager, pm me and Ill send you the source.
jor[D]1 wrote:Realy cool, but I think you should get big rivers, (A bit like the rhine donau etc.)
See attached image.
The problem with rivers is that it is hard to come up with a set of rules like where they should start and how they should flow etc, if you have some pointers (weblinks) to useful algorithms, let me know :)
PS, did you downscale the map to 1024^2? It looks as if the mountains in the picture are less rough than normal..
jor[D]1 wrote:Also I think cities are a bit concentrated too much at the plains. (Or only there). Some small flat low coasts would be great to get some hard to reach coastal villages.
I'm not sure why the flat plains are mostly concentrated in the centre, I can try to force the process into more flat land at the coast, but as everything is basically random this is hard. Some maps turn out with great flat coastlines while others have mostly hilly coasts.
jor[D]1 wrote:Finnally Make rail building a challange.[/b]
(1 small realistic railway line: 26 tunnels, 14 bridges and uncountable corners)
Thanks :), It indeed is more of a challenge to (realistically) find your way through the mountains.

User avatar
jor[D]1
Director
Director
Posts: 607
Joined: 17 Aug 2010 10:36
Location: Netherlands

Re: Fractal heightmaps

Post by jor[D]1 » 22 Jun 2012 08:31

No, played on 20xx*20xx''

But, i use it with chill patchpack, which uses 256 colors for heightmaps. Maybe that makes them less rough, or it could just be coincidence, some maps had real rough costs with "boulders" in sea.
View my (train)pictures on Flickr

ZxBiohazardZx
Tycoon
Tycoon
Posts: 1534
Joined: 14 Mar 2006 12:46
Location: Netherlands
Contact:

Re: Fractal heightmaps

Post by ZxBiohazardZx » 22 Jun 2012 09:39

Mainly wondering because my previous realistic map attempt failed due to a harddrive issue, i am in need of a fast landscape generator that results into realisitc landscapes. i dont care if i have to after-edit it, i just need a plain heightmap that i can fill with rivers, cities, infra etc

similar to cindini, with a change of me not manually scaping the land, for im not that crazy

zooks
Transport Coordinator
Transport Coordinator
Posts: 262
Joined: 29 Jun 2006 08:36

Re: Fractal heightmaps

Post by zooks » 22 Jun 2012 11:41

jor[D]1 wrote:No, played on 20xx*20xx''

But, i use it with chill patchpack, which uses 256 colors for heightmaps. Maybe that makes them less rough, or it could just be coincidence, some maps had real rough costs with "boulders" in sea.
Hmm, yeah I see now, the problem is that the heightmaps are in the range of 255 but only define 15 levels in between, also ottd automatically smooths the slopes which makes it look less rough. To get it looking the same with the 256 height levels some things would have to change. I suggest you try it once with only 16 heightlevels, it looks better :)
ZxBiohazardZx wrote:Mainly wondering because my previous realistic map attempt failed due to a harddrive issue, i am in need of a fast landscape generator that results into realisitc landscapes. i dont care if i have to after-edit it, i just need a plain heightmap that i can fill with rivers, cities, infra etc

similar to cindini, with a change of me not manually scaping the land, for im not that crazy
PM'd you the source ;)

ZxBiohazardZx
Tycoon
Tycoon
Posts: 1534
Joined: 14 Mar 2006 12:46
Location: Netherlands
Contact:

Re: Fractal heightmaps

Post by ZxBiohazardZx » 23 Jun 2012 07:34

hmmz i cant get a nice looking 4k*4k out of it, it works ok for the 2k*2k, but on 4k's it isnt popping something i like yet...

zooks
Transport Coordinator
Transport Coordinator
Posts: 262
Joined: 29 Jun 2006 08:36

Re: Fractal heightmaps

Post by zooks » 08 Aug 2012 02:52

Im in nepal at the moment so lots of inspiration here. When Im back I'll get back on this, and will look how easy it is to adjust for larger mapsizes and more heightlevels. Right now it was really focussed on 2048, and down to 512 it looks fine but outside that range it turns bad indeed. If anyone knows some good information sources on natural map/river/town generation, please share it with me ;)

User avatar
YNM
Tycoon
Tycoon
Posts: 3546
Joined: 22 Mar 2012 11:10
Location: West Java

Re: Fractal heightmaps

Post by YNM » 09 Aug 2012 14:50

Sorry to say, but likely the mountains generated are too sharp for OTTD slopes ? Because its a quite large problem when the slopes becomes too much...

Aanyway, maybe some extra large map patches can overcome those...
YNM = yoursNotMine - Don't get it ?
「ヨーッスノットマイン」も合うでしょう。

zooks
Transport Coordinator
Transport Coordinator
Posts: 262
Joined: 29 Jun 2006 08:36

Re: Fractal heightmaps

Post by zooks » 08 Nov 2012 16:22

Yoursnotmine wrote:Sorry to say, but likely the mountains generated are too sharp for OTTD slopes ? Because its a quite large problem when the slopes becomes too much...

Aanyway, maybe some extra large map patches can overcome those...
The generation process is limited to 15 heightlevels and afterwards gets adjusted to openttd slopes so what you see on the previews is pretty much what you get ingame.

A problem though is that there seem to be no parameters that specify things like continent size, number of continents/islands, variety distribution. This is probably because I don't understand the (diamond square) fractal enough.

zooks
Transport Coordinator
Transport Coordinator
Posts: 262
Joined: 29 Jun 2006 08:36

Re: Fractal heightmaps

Post by zooks » 09 Apr 2013 11:59

Here is the python code (2.7.x). Not documented and not really readable, no guarantees.
mapgen.tar.gz
(2.04 KiB) Downloaded 168 times
The call should look something like this:

Code: Select all

python mapgen.py <width> <height> [seedstart] [seedend] 
width and height can range from 1(128) to 5(2048)
seedstart and seedend are the seeds given to the random generator. If both left empty, the script will produce one random map called test.png

example: to create 100 maps 1024*512, you would use:

Code: Select all

python mapgen.py 4 3 100 200
This results will be saved in a directory called 'output', and you have to create this directory (once) yourself if it is not there.
The results will be both a coloured image and a greyscale image. The coloured looks nice, and the greyscale is to use in openttd.

If you encounter some nice maps, please share them here with the rest :) Also if you make improvements to the script, I would very much like to see those.

cheers

zooks

MisterX
Engineer
Engineer
Posts: 36
Joined: 25 Mar 2013 18:24

Re: Fractal heightmaps

Post by MisterX » 09 Apr 2013 16:45

I really don't how i get this working...

zooks
Transport Coordinator
Transport Coordinator
Posts: 262
Joined: 29 Jun 2006 08:36

Re: Fractal heightmaps

Post by zooks » 10 Apr 2013 11:15

MisterX wrote:I really don't how i get this working...
That's not much of a question, can you tell me what the problem is? What python version are you using? What operating system? I can help you if you're on linux

MisterX
Engineer
Engineer
Posts: 36
Joined: 25 Mar 2013 18:24

Re: Fractal heightmaps

Post by MisterX » 10 Apr 2013 11:45

I just downloaded python 2.7.4 for this. Have no experience with python, so maybe I do something stupid...
Operation system is Windows 7, not linux.

I googled to found how to run a .py file and found the following:
On windows platform, you have 2 choices:

1.
In a command line terminal, type

c:\python23\python xxxx.py

2.
Open the python editor IDLE from the menu, and open xxxx.py, then press F5 to run it.
This help was for python 2.3.x, so i have to change the python23 to python27, i guess and i placed mapgen.py in c:\python23\
Then i tried the first option (ofcourse with mapgen instead of xxxx). But i get 'SyntaxError: invalid syntax' and the : is highlighted in red.
The same happens when i add 4 3 100 200 (the same numbers as in your example) after it. Same error happens....

Thus tried the second option. When I press F5, also a error occurs:
Traceback (most recent call last):
File "C:\Python27\mapgen.py", line 5, in <module>
import sys,os,png,random,colorsys,math,time
ImportError: No module named png
So somewhere i do something wrong... Maybe i place the map output at a wrong place? Where must i create that map?

Hope you see my mistake...

zooks
Transport Coordinator
Transport Coordinator
Posts: 262
Joined: 29 Jun 2006 08:36

Re: Fractal heightmaps

Post by zooks » 10 Apr 2013 14:49

MisterX wrote: Thus tried the second option. When I press F5, also a error occurs:
Traceback (most recent call last):
File "C:\Python27\mapgen.py", line 5, in <module>
import sys,os,png,random,colorsys,math,time
ImportError: No module named png
So somewhere i do something wrong... Maybe i place the map output at a wrong place? Where must i create that map?

Hope you see my mistake...
Ah I see now. I totally forgot to mention that it uses the pypng module/library. Apologies

Easy fix: put this file: http://pypng.googlecode.com/svn/trunk/code/png.py
in the same directory as mapgen.py

After that, it should work. Let me know if this helps.

cheers

MisterX
Engineer
Engineer
Posts: 36
Joined: 25 Mar 2013 18:24

Re: Fractal heightmaps

Post by MisterX » 10 Apr 2013 19:11

On windows platform, you have 2 choices:

1.
In a command line terminal, type

c:\python23\python xxxx.py

2.
Open the python editor IDLE from the menu, and open xxxx.py, then press F5 to run it.
1 gives still an error, i think a do still something wrong, but with 2 i can make maps. But then he used the predefined sizes. Standard 256x256, so the first time i tried 2, i get a 256x256 map. But in mapgen.py, i easiely can change the standard, so as second a 2048 x 2048 was made. So i can make some heightmaps with it.

Thanks for this tool, very usefull.

How big could you choose seedstart and seedend? Are there some limits?

Post Reply

Return to “Scenarios and Saved Games”

Who is online

Users browsing this forum: No registered users and 2 guests