Skip to main content

Diamond Square

Implementation of the Diamond–Square Algorithm. This package can draw 2d terrains and 2d interactive terrains in pgzero and pygame.

Also can draw 3D terrains and 3D interactive terrains in panda3d.


Sample Generations

Sample Default 3D Terrain Sample Default Terrain Sample Desert Terrain Sample Tundra Terrain Sample Tropical Terrain Sample Volcanic Terrain Sample Swamp Terrain Sample Ocean Terrain Sample Mars Terrain


⚠️ You MUST include all four interactive functions for pgzero interactive

Missing even one will cause failures or unpredictable behavior.


Table of Contents

  • Why Use Diamond Square?
  • Usage
    • Terrain Examples
      • Pgzero Terrain Example
      • Pygame Terrain Example
      • Panda3d 3D Terrain Example
    • Interactive Terrain Examples
      • Pgzero Interactive Terrain Example
      • Pygame Interactive Terrain Example
      • Panda3d Interactive Terrain Example
    • Other Examples
      • Custom Biome Examples
      • Terrain and Terrain 3D Saving Examples
  • Requirements for Pgzero Interactive
  • Versions
  • Coming Soon

Why Use diamond-square?

This package provides a complete implementation of the Diamond–Square algorithm with:

  • Fast rendering of the Diamond-Square algorithm written in C.

  • Multiple built‑in biomes.

  • Adjustable roughness, scale, and size.

  • Support for pgzero and pygame.

  • 3d terrain drawing in panda3d.

  • Interactive mode in 2d and 3d terrains.

  • Change the border shape of the terrain (it is normally a square) using a filter function.

  • The ability to save generated terrain as an image.

  • Functions to add or remove biomes dynamically.

It is designed for both experimentation and game development, making 2d/3d terrain generation simple and customizable.


Usage

Terrain Examples

Pgzero Terrain Example

Go to /sample_codes/pgzero_terrain.py

Pygame Terrain Example

Go to /sample_codes/pygame_terrain.py

Panda3d 3D Terrain Example

Go to /sample_code/panda3d_terrain3d.py


Interactive Terrain Examples

Pgzero Interactive Terrain Example

Go to /sample_codes/pgzero_interactive_terrain.py

Pygame Interactive Terrain Example

Go to /sample_codes/pygame_interactive_terrain.py

Panda3d Interactive Terrain Example

Go to /sample_codes/panda3d_interactive_terrain.py


Other Examples

Terrain and 3D Terrain Saving Examples

Go to /sample_codes/terrain_saving.py

Custom Biome Examples

Go to /sample_code/custom_biome.py


Requirements for Pgzero Interactive

For Pgzero Interative Mode, it requires all four of the following functions to be placed in their corresponding pgzero event handlers:

...

def draw():
  terrain.draw_func(screen)
  ...

def on_mouse_down():
  terrain.on_mouse_down_func(pos)
  ...

def on_mouse_up():
  terrain.on_mouse_up_func()
  ...

def on_mouse_move():
  terrain.on_mouse_move_func(pos)
  ...

If any one of these is missing, the interactive mode will:

  • fail to update correctly

  • behave unpredictably

  • or stop working entirely

These must be placed in these functions in pgzero:

  • def draw(): → terrain.draw_func(screen)

  • on_mouse_down(pos): → terrain.on_mouse_down_func(pos)

  • on_mouse_up(): → terrain.on_mouse_up_func()

  • on_mouse_move(pos): → terrain.on_mouse_move_func(pos)


Versions

(Latest) Version 1.2.1: Bug Fixes.

Version 1.2.0: Added 3D Interactive Mode.

Version 1.1.0: Add filter functions for 2D terrains.

To view previous versions, go to versions.txt


Coming Soon

Version 1.3.0: Add Save as Image option in Interactive Mode.

Metadata

Release files for diamond-square 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for diamond-square 1.2.1
File Size Uploaded
diamond_square-1.2.1.tar.gz 23.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for diamond-square 1.2.1
File Interpreter ABI Platform
diamond_square-1.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 49.0 kB

Release files / diamond_square-1.2.1.tar.gz

Download URL diamond_square-1.2.1.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
96be078fbcf5c24b6eec693270297c85de94eedc23d7d88c49e87eef4eead745
BLAKE2b-256 checksum
How to use checksums
ac24a3e6c6b96d0abd6f0d53d667e73e18048bb276228abae8c1f3fbc75bc3a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / diamond_square-1.2.1-py3-none-any.whl

Download URL diamond_square-1.2.1-py3-none-any.whl
Size 25.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
41e737151246820ec470b711ced61ea3794390d6ac5ba8295bcd2d1bee5dfd26
BLAKE2b-256 checksum
How to use checksums
38ca6065208901a130dddf08ae90eba7b918022eada6166e5eebb0490f6a3f1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

This release

1.2.1 This release

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

1 release file

0.1.1

1 release file

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page