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
⚠️ 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
- Terrain 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
Usage examples are found in the documentation or in the sample codes:
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
Versions
(Latest) Version 1.2.4:: Updated Documentation.
Version 1.2.3: Added dynamic sizes instead of just 2**n+1.
Version 1.2.2: Update Panda3DInteractive.
To view previous versions, go to versions.txt
Coming Soon
Version 1.3.0: Add Save as Image option in 2D Interactive Mode.
Metadata
Release files for diamond-square 1.2.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| diamond_square-1.2.4.tar.gz | 26.5 kB | Without provenance | Details for diamond_square-1.2.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| diamond_square-1.2.4-py3-none-any.whl | Python 3 | none | any | Details for diamond_square-1.2.4-py3-none-any.whl |
Total release size: 55.5 kB
Release files / diamond_square-1.2.4.tar.gz
| Download URL | diamond_square-1.2.4.tar.gz |
|---|---|
| Size | 26.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
560202237f9a5ab4b72f8ba90a46e89182b7cb9c153cf47228b62f1ebed41d5c
|
|
BLAKE2b-256 checksum How to use checksums |
bd257ead10237a277725b51e8b6ca2512691f5dca006724384cdd1d2fa44ccd9
|
| 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.4-py3-none-any.whl
| Download URL | diamond_square-1.2.4-py3-none-any.whl |
|---|---|
| Size | 29.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b337989fd7a74f94a97f00cb17071f963bb6e1900ce40dcce90d52ca6bbd5a17
|
|
BLAKE2b-256 checksum How to use checksums |
7c63ed8e87c70d30966f75222520bcdd42412259d507ef6b2be700e0f90b7099
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for diamond-square 1.2.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.