A simple Python library made to facilitate the easy generation of two-dimensional, procedurally-generated terrains and maps.
- A function to generate two-dimensional terrains given a width, height, smoothness, and a dictionary of terrain values.
- A function to easily display terrains generated by Platypus.
Generates a new terrain.
Arguments:
width
: The width of the terrain to generate.height
: The height of the terrain to generate.smoothness
: The number of times to iterate over and smooth the terrain.- This should be an integer >= 0.
- If
smoothness
is a small value, the terrain will be more noisy. This is good for small terrains, but can be chaotic for large ones. - If
smoothness
is a large value, the terrain will be more smoothly-bordered. This is great for large terrains, but can result in overly-simplified small terrains.
values
: A dictionary of terrain values (characters, text, objects, doesn't matter!) paired to their relative likelihoods to appear.- This should be formatted as so:
{*value*: *likelihood*, *value*: *likelihood*, ...}
- The likelihoods to appear are all relative -- they don't have to add up to 1 (or 100, for that matter). One could write a
values
dictionary like so:{"#": 3, "%": 2}
and it would only mean that "%" is 2/3 as likely to appear as "#".
- This should be formatted as so:
Displays a terrain on the console.
Argument:
terrain
: The terrain to display.- Only Platypus-generated terrains are guaranteed to display properly.
Running this code:
terrain = platypus.generate(10, 10, 1, {"#": 1, " ": 1})
platypus.display_terrain(terrain)
...can lead to this output:
# # # #
# # # #
# # # # #
# # #
#
# # #
# # # # # # #
# # # # # #
# # # #
# # #
...and running this code:
terrain = platypus.generate(80, 40, 10, {"X": 0.2442, "#": 0.2558, ".": 0.2442, " ": 0.2558})
platypus.display_terrain(terrain)
...can lead to this output:
# # # # # # # # # # # # # # # # # # # # # # . . . . . X X X X # # # # # # # # # . . . . X X X X X X X X
# # # # # # # # # # # # # # # # # # # # # # . . . . . X X X X # # # # # # # # # . . . . X X X X X X X X
# # # # # # # # # # # # # # # # # # # # # # # # . . . . . X X X X # # # # # # # # # . . . . X X X X X X X X
# # # # # # # # # # # # # # # # # # # # # # # # . . . X X # # # # # # # # # # . . . X X X X X X X X X
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # . X X X X X X X X X X
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # X X X X X X X X X X
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # X X X X X X X X X
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # X X X X X X X X
# # # # # # # # # # # . . . . . . . # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # X X X X X X X X
# # # # # # # # # # # . . . . . . . . . . # # # # # # # # # # # # # # # # # # # # # # # X X X X X X # # # # # X X X X X X X
# # # X X X # # # # . . . . . . . . . . . # # # # # # # # # # # # # # # # # # # # # X X X X X X X X X # # # # # X X X X X X X
X X X X X X X X # . . . . . . . . . . . . . # # # # # # # # # # # # # # # # X X X X X X X X X X X X X X # # # # X X X X X X X X X
X X X X X X X X X . . . . . . . . . . . . # # # # # # # # # # X X X X X X X X X X X X X X X # # X X X X X X X X X X X X X
X X X X X X X X X X . . . . . . . . . . # # # # # # # # # X X X X X X X X X X X X X X X X X X X X X X X X X X X X X # # # #
X X X X X X X X X X . . . . . . . . . # # # # # # # X X X X X X X X X X X X X X X X X X X X X X X X X X X X X X # # # # #
X X X X X X X X X X . . . . . . . . # # # # # # X X X X X X X X X X X X X X X X X X X X X # # . X X X X X X X X X X X # # # # #
X X X X X X X X X . . . . . . . . . # # # # # X X X X X X X X X X X X X X X X X X X X X X # # # # # . . . . X X X X X X X X X X # # # # #
X X X X X X X X X . . . . . . . . # # # # X X X X X X X X X X X X X X X X X X X X X X X X # # # # . . . . . . X X X X X X X X # # # #
X X X X X X X X X . . . . . . . . # # # # X X X X X X X X X X X X X . . X X X X X X X X X X X # . . . . . . . . X X X X X X
X X X X X X X X X . . . . . . . . # # # # X X X X X X X X X X X X . . . . X X X X X X X X X X X . . . . . . . . X X X X X
X X X X X X X X X X . . . . . . . # # # X X X X X X X X X X X X . . . . . X X X X X X X X X X X X . . . . . . X X X X X
X X X X X X X X X X . . . . . . . . . . X X X X X X X X X X X X . . . . . . X X X X X X X X X X X . . . . . X X X X X
X X X X X X X X X X . . . . . . . . . . . . . X X X X X X X X X # # . . . . . . X X X X X X X X X X X X . . . . X X X X
X X X X X X X X X X X . . . . . . . . . . . . . . X X X X X X X # # # # . . . . . X X X X X X X X X X X X # # # # # X X
X X X X X X X X X X X . . . . . . . . . . . . . . . . X X X X X # # # # # # . . . . X X X X X X X X X X X # # # # # # #
X X X X X X X X X # # # # # . . . . . . . . . . . . . . . . X # # # # # # # # # . # # X X X X X X X X X # # # # # # # #
X X X X X X X X # # # # # # # . . . . . . . . . . . . . . . . # # # # # # # # # # # # # # X X X X X # # # # # # # # # #
X X X X # # # # # # # # # # . . . . . . . . . . . . . . # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
X # # # # # # # # # # # # # # # . . . . . . . . . . . . . . # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # . . . . . . . . . . . . . # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # . . . . . . . . . . . # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # . . . . . . . . # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # . . . . . . . # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # . . . . . . . # # # # # # # # # # # # # # # # # # # # # # # # # # . . .
# # # # # # # # # # # # # # # # # # # # # # # # # . . . . . . . # # # # # # # # # # # # # # # # # # # # # # # # . . . . . X X
X X # # # # # # # # # # # # # # # # # # # # # # # # # # # . . . . . # # # # # X X # # # # # # # # # # # # # # # . . . . . . . X X X X
X X X X # # # # # # # # # # # # # # # # # # # # # # # # # # . . . . . . # # X X X X X # # # # # # # # # # # # # # . . . . . . X X X X X X
X X X X X X # # # # # # # # # # # # # # # # # # # # # # # # # . . . . . . . X X X X X X X # # # # # # # # # # # # . . . . . . . . X X X X X X # # # #
X X X X X X X # # # # # # # # . . . # # # # # # # # # # # . . . . . . . X X X X X X X X # # # # # # # # # # # . . . . . . . . X X X X X X # # # # #
X X X X X X # # # # # X # . . . . # # # # # # # # # # . . . . . . . X X X X X X X X # # # # # # # # # # # . . . . . . . . X X X X X X # # # # #
- Python 3 (developed with Python 3.6.5)
At the moment, Platypus is not available on PyPI or for installation with distutils. For now, just copy the platypus.py file into your working directory.
This package is protected by the MIT license (license.txt). Basically, if you use my library, include my license with my code in your package. It gives me credit, and it gives you permissive access! (This summary is not legally binding whatsoever. For exact wording of the license, see license.txt.)