Skip to main content

No project description provided

Project description

#DiamondSquare.py This is a python implementation of the classic diamond-square algorithm for 2-D height maps, which are often used for terrain generation and random map creation.

Feel free to post questions or requests, and I'll see what I can do.

If you use it for something interesting, I'd love to hear about it.

Best, -HKB-

Using it in a python project is easy:


from hkb_diamondsquare import DiamondSquare as DS

#make a height map of size 16x20, with values ranging from 1 to 100, with moderate roughness
map1 = DS.diamond_square(shape=(16,20), 
                         min_height=1, 
                         max_height=100,
                         roughness=0.75)

#make a square height map with sides of length 120, that are VERY rough
map2 = DS.diamond_square(shape=(120,120),
                         min_height=1,
                         max_height=100,
                         roughness=0.99)

#make a VERY smooth map with values from -10 to 10
map3 = DS.diamond_square(shape=(10,10), 
                         min_height=-10, 
                         max_height=10, 
                         roughness=0.05)

#use a specific random seed to ensure replicability
same_map_1 = DS.diamond_square((15,15), 1, 100, 0.8, random_seed=1.234)
same_map_2 = DS.diamond_square((15,15), 1, 100, 0.8, random_seed=1.234)
import numpy as np
np.allclose(same_map_1, same_map_2)
# prints True

different_map = DS.diamond_square((15,15), 1, 100, 0.8, random_seed=1.2341, as_ndarray=True)
np.allclose(same_map_1, different_map)
# prints False

You can also vizualize your landscape using Seaborn (not included by default) as shown:

from hkb_diamondsquare import DiamondSquare
import seaborn

def show_terrain_2D(terrain_array):

    seaborn.set()
    ax = seaborn.heatmap(terrain_array)

map = DiamondSquare.diamond_square(shape=(50,50), min_height=0, max_height=10, roughness=0.3)
show_terrain_2D(map)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hkb_diamondsquare-1.0.0.tar.gz (5.9 kB view details)

Uploaded Source

File details

Details for the file hkb_diamondsquare-1.0.0.tar.gz.

File metadata

  • Download URL: hkb_diamondsquare-1.0.0.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3

File hashes

Hashes for hkb_diamondsquare-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c7e528db1480f984d3581bff5189a057e1ce6d7d8d907276bb84f387075eb3ba
MD5 adf4b38a0332ba585f0b09a87d225b9b
BLAKE2b-256 af68310f2f8497774c3612d985d0858146a85ed7438f604fb25cabe5ab9d800e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page