Diamond Square
Implementation of the Diamond–Square Algorithm. This package can draw terrain on pgzero and pygame, and can also set up interactive mode.
Sample Generations
⚠️ You MUST include all four interactive functions for pgzero interactive
Missing even one will cause failures or unpredictable behavior.
⚠️ You must pass the pgzero screen into draw functions
Use
terrain.draw(screen)orterrain.for_draw(screen)— the yellow underline is expected.
Table of Contents
- Why Use Diamond Square?
- Usage
- Pgzero Examples
- Pygame Examples
- Image Saving Examples
- Custom Biome 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 and scale.
-
Support for pgzero and pygame.
-
Optional interactive mode.
-
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 terrain generation simple and customizable.
Usage
Pgzero Examples
Look at /sample_codes/pgzero_draw_terrain.py
Pygame Examples
Look at /sample_codes/pygame_draw_terrain.py
Image Saving Examples
Look at /sample_codes/save_terrain.py
Custom Biome Examples
Look at /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:
terrain.for_draw(screen)
terrain.for_on_mouse_down(pos)
terrain.for_on_mouse_up()
terrain.for_on_mouse_move(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
Version 0.0.1: Main code for diamond-square added.
Version 0.0.2: Updated README file and added documentation.
Version 0.0.3: Fixed bugs and errors.
Version 0.0.4: Added sample terrain.
Version 0.0.5: Added more sample terrains.
Version 0.0.6: Added functions to add/remove biomes.
Version 0.0.7: Added pos parameter to determine where to place the terrain, added a function to save terrain as an image, and made interative mode avaliable in pgzero.
Version 0.0.8: Added C file for fast rendering of the Diamond–Square Algorithm.
Version 0.0.9: Made pgzero and pygame interactive mode into one function and added documentation.
Version 0.1.0: Fix bugs in C file and save_terrain function.
Version 0.1.1: Refactor Code for more OOP.
Version 0.1.2: Add documentation.
Version 0.1.3: Complete documentation, fix bugs, and remove duplicate functions.
Version 0.1.4: Bug fixes.
Version 0.1.5: Bug fixes, documentation changes, added utils.py, and updated sample code files.
(Latest) Version 0.1.6: Added custom_biome.py in sample_codes.
Coming Soon
Version 0.1.7: Complete documentation. Version 0.1.8: Add re-generate button for interactive mode pgzero and pygame.
Metadata
Release files for diamond-square 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| diamond_square-0.1.6.tar.gz | 14.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| diamond_square-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 28.9 kB
Release files / diamond_square-0.1.6.tar.gz
| Download URL | diamond_square-0.1.6.tar.gz |
|---|---|
| Size | 14.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9886332b160b13624bf9e16deca51ae582d7c33585f7296571328ca735fabe6f
|
|
BLAKE2b-256 checksum How to use checksums |
55af9fa5835be84263ad28de80f3cdaad9450fdc724c88aefc37cae9c49dffaf
|
| 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-0.1.6-py3-none-any.whl
| Download URL | diamond_square-0.1.6-py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3353d856e8f1ab581444c08be3e65d0b992e9567a0e5765ce0e4a840c4be3c1a
|
|
BLAKE2b-256 checksum How to use checksums |
8530521c62df94ab9efbfed10f3ed9f4d943db3f028dddf432e39b925c28c5ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|