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 for.


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.

⚠️ You must pass the pgzero screen into draw functions

Use terrain.draw(screen) or terrain.for_draw(screen) — the yellow underline is expected.


Table of Contents

  • Why Use Diamond Square?
  • Usage
    • Drawing Terrain
      • Pgzero Example
      • Pygame Example
    • Interactive Mode
      • Pgzero Example
      • Pygame Example
  • 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

Drawing Terrain

Pgzero Example

Look at sample_code_pgzero_drawing_terrain.py for pgzero examples.


Pygame Example

Look at sample_code_pygame_drawing_terrain.py for pygame examples.

The screen parameter must be the pygame display surface.

Interactive Mode

This creates an interactive scene where the user can change the biome and roughness in real time.

Pgzero example

Look at sample_code_pgzero_drawing_terrain.py for pgzero examples.

Pygame example

Look at sample_code_pygame_drawing_terrain.py for pygame examples.


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:

  • draw() → terrain.for_draw(screen)
  • on_mouse_down(pos) → terrain.for_on_mouse_down(pos)
  • on_mouse_up() → terrain.for_on_mouse_up()
  • on_mouse_move(pos) → terrain.for_on_mouse_move(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 and added function to save terrain as an image. Also made interative mode avaliable to 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.

(Latest) Version 0.1.5: Bug fixes, documentation changes, added utils.py, and updated sample code files.


Coming Soon

Version 0.1.6: Complete documentation. Version 0.1.7: Add re-generate button for interactive mode pgzero and pygame.

Metadata

Release files for diamond-square 0.1.5

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.5
File Size Uploaded
diamond_square-0.1.5.tar.gz 14.0 kB Details

Built distribution (wheel)

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

Total release size: 28.9 kB

Release files / diamond_square-0.1.5.tar.gz

Download URL diamond_square-0.1.5.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d3f20fd13d706385df49afa0d5d4e3d00a193f9130426557ff1b2bdf50916eed
BLAKE2b-256 checksum
How to use checksums
b4854398881fe3dab0fd435a2b3ad053f6c7e931ccc71ee6ab42f9de64cf91b4
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.5-py3-none-any.whl

Download URL diamond_square-0.1.5-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e02d0975cbc6647a7e4e8734410d8de4fafb924fc939c7f74397334bf0e0d261
BLAKE2b-256 checksum
How to use checksums
b41661f1d66798b23583eb1962afcf2fe55047ede20da1d2a738868eafcdd78d
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

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

This release

0.1.5 This release

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