Map Generator - How it's made
Modules
The generator relies on numpy and openCV modules. Numpy is used for quick 2D array calculation - I did build a map generator solely with Python 2D arrays, however the program would take too long to handle calculations - while openCV is used for compiling the array into an image.
Generating Fractal Terrain
The completed map is a combination of 3 fractal arrays:
- One array for the ocean.
- One array for the land.
- One array with much lower fractal resolution, to use as a negative.

+

/

The result is a map with hard coastlines and mountains that cut straight into the ocean on occasion.

Breaking up the Coastline
The following passes take most of the map generation time. As such, it's at this point that the array is cropped into its final size (selected in the form).
Progressively, three separate passes break up and randomize the coastline. The program runs through the array, checking all tiles in a 3-tile square radius, and can determine the edge if a coast or lake by the presence of Sea tiles. Each coastline tile has a chance to be mutated into something else, depending on the map configuration.
Last Touches
After these three passes, the River Pass is performed, which looks at a larger surrounding radius (4) to find a water source to start from, and meanders along lower terrain as you would expect. Surprisingly, although the scan always runs from left to right, top to bottom, the shape and direction of rivers don't repeat as much as I expected.
Finally, the City Pass will randomly place cities in places they would be expected (typically by waterfronts and around land tiles). The cities vary in size and shape.

Seed: 900
On the Application's Side
The frontend consists of a form, which fetches the map from the server where it is is generated. When a map is returned, it is loaded both as a standalone image, and as part of an image carousel where all past images are stored (see Carousel project page).
The image filename will include the time of creation and the seed used (even if no seed was set), so that a user can always get it back later if needed.
The carousel will load a maximum of 15 images. Beyond that old images will be destroyed. Additionally, images that are over a day old will also be destroyed.
Future Improvements
In the future, users will be able to register an account, which will let them store more than 15 maps on the application.
While it's not planned, there are some features I'd like to add to this if I ever return to it:
- A fantasy map type (i.e. D&D map look).
- City Names
- A tool to import settings from downloaded settings.txt files
Link to Code
If you'd like to run this map locally, you can find the code in this GitHub repo.