Skip to main content

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

Sample Default Terrain Sample Desert Terrain Sample Tundra Terrain Sample Tropical Terrain Sample Volcanic Terrain Sample Swamp Terrain Sample Ocean Terrain Sample Mars Terrain Sample Crazy 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
    • Pgzero Terrain Example
    • Pgzero Interactive Terrain Example
    • Pygame Terrain Example
    • Pygame Interactive Terrain Example
    • 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 Terrain Example

Go to /sample_codes/pgzero_terrain.py

Pgzero Interactive Terrain Example

Go to /sample_codes/pgzero_interactive_terrain.py

Pygame Terrain Example

Go to /sample_codes/pygame_terrain.py

Pygame Interactive Terrain Example

Go to /sample_codes/pygame_interactive_terrain.py

Image Saving Examples

Go to /sample_codes/save_terrain.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:

terrain.draw_func(screen)
terrain.on_mouse_down_func(pos)
terrain.on_mouse_up_func()
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 0.1.9: Improve speed in C file and fix bugs.

Version 0.1.8: Add remake terrain button for interactive mode in pgzero.

Version 0.1.7: Fix terrain generation and README updates.

To view previous versions, go to versions.txt


Coming Soon

Version 0.2.0: Add re-generate button for interactive mode in pygame.

Metadata

Release files for diamond-square 0.1.9

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 0.1.9
File Size Uploaded
diamond_square-0.1.9.tar.gz 15.1 kB Details

Built distribution (wheel)

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

Total release size: 30.6 kB

Release files / diamond_square-0.1.9.tar.gz

Download URL diamond_square-0.1.9.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
57d3f90ef10b22c9551083a6eb688e1fc5646288f72ff7fa8da11ec66ff47d17
BLAKE2b-256 checksum
How to use checksums
b33ea8bccf06f9da91ca31fdf654a894dea222f3738c33ea9a2310734d545ebb
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.9-py3-none-any.whl

Download URL diamond_square-0.1.9-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1bb72653518d0e9b0a5a8ccfe0d3167371b8277e273dd3846ca5e412a789150a
BLAKE2b-256 checksum
How to use checksums
fccaba1c11101e190d5c4d372f99ac7eee6d2a797674a7dccb159d46381c0aee
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

1.2.1

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

This release

0.1.9 This release

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