# How can I do programmatic generation of fantasy maps?

I found this twitter bot https://twitter.com/unchartedatlas posting maps that look like they came from a pulp fantasy novel.

Any idea on how they are done?

## 3 Answers

Fortunately the author, Martin O'Leary, has posted rather detailed walkthrough of the algorithm of how the maps are generated here: http://mewo2.com/notes/terrain/ as well as how the names were created here: http://mewo2.com/notes/naming-language/.

A brief summary of the algorithm covered by Martin O'Leary’s post:

• Grid: Create a height map with a grid of random points. Random points doesn’t look naturalistic so apply an iteration of Lloyd’s algorithm to the corners of the Voronoi polygons.

• Rough Outline: Apply a set of sequence of primitives (constant slope, cones, blobs) and operations (normalize, round hills, average local height, set sea level) can be varied to produce different kinds of landscape, such as coastlines, islands and mountain ranges.

• Erosion: Apply a constant flow of water over the entire map and use Planchon-Darboux algorithm to fill in the depressions. Calculate water flux to get rivers.

• Render terrain: Coastline is where the height map crosses zero. Rivers based on the water flux and some smoothing of the points. Apply shading to slope.

• Cities and borders: Place city near river and penalize nearness to other cities and to edge of map. Mark out region based on distance, slope, water flux, and shorelines.

This is a rough summary of Martin O'Leary's post. I really recommend reading the post as the author does go into detail about the programmatic terrain generation and the post itself has interactive elements.

Similarly the author the post on the linguistic aspect of how the place names were generated also has interactive elements.

The terrain map project is open sourced on github here: https://github.com/mewo2/terrain

The naming project is open sourced on github here:

https://github.com/mewo2/naming-language

• Another detailed article on programmatic map generation: www-cs-students.stanford.edu/~amitp/game-programming/… Commented Aug 10, 2016 at 18:50
• Links rot. Would you care to describe the process inside the post instead?
– Mast
Commented Aug 10, 2016 at 19:42
• @Mast what is in those links would be a very very very very long answer that is still lacking... Commented Aug 10, 2016 at 19:48
• The main flaw with those programs is that they don't map a full world and putting it together would be extremely tough. I really wish someone made one of those that worked on a global scale, but that's unlikely because how tough it is to get such stuff to work correctly. Commented Aug 10, 2016 at 19:50
• @Mast I agree on the link rot but if you actually looked at the post it is (a) long and (b) interactive. I suspect that the each of references within the post alone would merit its own discussion, i.e. just the Grid section speaks of Lloyd relaxation and Voronoi polygons. The author is directed to a technical audience but as he does provide the code and his thought process, I thought it would be at least a reference appropriate for this site. Commented Aug 10, 2016 at 19:50

The creator's website is pretty well documented on how they did it.

• (This was brought up in chat, and we encouraged OP to answer his own question as it's a useful resource, and it seemed the best way to document it for the community.) Commented Aug 10, 2016 at 18:00

There's also a wonderful fantasy map generator at: https://donjon.bin.sh/fantasy/world/

Also, a more scientific world map generator at the same site - https://donjon.bin.sh/scifi/world/ & also a complete stellar system generator: https://donjon.bin.sh/scifi/system/