Skip to main content

A package which can implement and draw the diamond-square in pgzero and pygame. Uses C for fast rendering.

Project description

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.

⚠️ 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

  • Quick Start
    • Installation
  • Why Use Diamond Square?
  • Usage
    • Drawing Terrain
      • Pgzero Example
      • Pygame Example
    • Interactive Mode
      • Pgzero Example
      • Pygame Example
  • Requirements for Pgzero Interactive
  • Versions
  • Coming Soon

Quick Start

Installation

pip install diamond-square

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 (pgzero only)
  • 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 sample terrains.
Version 0.0.6: Added functions to add/remove biomes and added external documentation website.
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 (Latest) Version 0.0.9: Made pgzero and pygame interactive mode into one function and added documentation


Coming Soon

Version 0.1.0: Complete documentation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diamond_square-0.0.9.tar.gz (16.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

diamond_square-0.0.9-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file diamond_square-0.0.9.tar.gz.

File metadata

  • Download URL: diamond_square-0.0.9.tar.gz
  • Upload date:
  • Size: 16.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for diamond_square-0.0.9.tar.gz
Algorithm Hash digest
SHA256 377a4cddb728898171313697027ac04e3ea73bda36a645cbff382167f9594da4
MD5 812f8fe11651be55eb171da96f10f097
BLAKE2b-256 74c43c72b0c0f73861976ee25b80a61c3ff6f611ee0da320bde530aa656202bf

See more details on using hashes here.

File details

Details for the file diamond_square-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: diamond_square-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for diamond_square-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 e030efc0b684025640f27a1bf319f0ff93052fcb14182f92e2ae36253da88252
MD5 c1aee91bad6bd1c720f2973feca32a94
BLAKE2b-256 a7d4a08489336cd4f41a5087dd0758e8e6ac58f040b3666c608cbb8e5b66bcc0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page