Skip to main content

MoonTex is a noise-based texture generator that creates realistic grayscale moon phase images.

Project description

MoonTex v1.0.1

MoonTex Moon Phases (1) MoonTex Moon Phases (3) MoonTex Moon Phases (7)

MoonTex is a procedural moon texture generator for Python that creates stylized, noise-based moon phase images with full control over surface detail, lighting geometry, color tinting, and export behavior.

MoonTex is designed for games, simulations, and procedural worlds, where moons are generated programmatically rather than painted by hand.

Key Features

  • Procedural moon surface using 2D simplex noise
  • Manual crescent / gibbous shaping via phase_offset
  • Quarter (half-lit) moons via phase_offset = 0
  • Color-tinted moons (RGB or hex, CQCalendar-compatible)
  • Multiple shadow styles (blend, alpha, multiply, auto)
  • Soft terminator edge for smooth light-to-dark transitions
  • Optional transparent background (RGBA)
  • Deterministic output via seeds

Powered by Python, Pillow, and noise. No heavy dependencies or GPU requirements.


Example Usages

You probably already know what you're going to use MoonTex for but here are some example usages if you need ideas.

Day/Night Cycle Skybox

Here's an example of MoonTex being used in a raycasting demo made with Tkinter and CQCalendar. The player is in a walled off grassy area with a pond in the middle. Underneath the 2D minimap, you can see the current time/date/moon phase. Time passes on an hourly basis. As day turns into night an image of the moon is shown in the sky based on the current moon phase.


Dependency Installation

pip install -r requirements.txt

How to Generate a Single Moon Phase Texture

#Initialize Generator
generator = moontex.MoonTex()

#You can specify the output directory if you want. Specify a moon phase name.
generator.export_moon_phase_image(output_dir=".", phase="Full Moon")

How to Generate All Moon Phase Textures

#Initialize Generator
generator = moontex.MoonTex()

#You can specify the output directory if you want. Specify a moon phase name.
generator.export_all_moon_phase_images(output=".")

Manual Shape & Color Control (Core Feature)

MoonTex does not force predefined lunar geometry. You can define moon shapes directly using a continuous phase_offset:

-1.0 → thin waxing crescent

0.0 → half moon

1.0 → thin waning crescent

Combined with color tinting, this allows custom moons, magical events, or stylized worlds.

generator.generate(
	phase="Custom",
	phase_offset=-0.9,
	moon_color_hex="#ff0000",   # blood moon
	terminator_softness=1.5
)

If you use a custom phase name, phase_offset is required. Built-in phase names work without it.


Customization Options

MoonTex(
	# --- Core image settings ---
	image_size=300,              # int or (width, height)
	bg_color=(5, 5, 20),         # background RGB (used if not transparent)

	# --- Noise / surface detail ---
	noise_scale=0.01,
	octaves=3,
	persistence=0.5,
	lacunarity=3,
	seed=0,
	intensity=0.4,
	invert_crater_noise=True,

	# --- Brightness ---
	brightness=(50, 230),

	# --- Rendering ---
	transparent_background=False,
	padding=4,
	edge_softness=1.5,

	# --- Shadow behavior ---
	shadow_factor=0.15,
	shadow_mode="bg",            # legacy compatibility
	dark_floor=0.0,
)


Shadow Styles (Per-Image)

When calling generate() you can choose how the dark side behaves:

  • "blend" – blends into bg_color (classic look)
  • "alpha" – uses transparency (best for skyboxes & overlays)
  • "multiply" – multiplies light (stylized / painterly)
  • "auto" – selects best option based on transparency

Skybox Usage (Raycasting, Overlays)

MoonTex(
    transparent_background=True,
    shadow_mode="neutral",
    dark_floor=0.0,
)

Standalone Image Usage

MoonTex(
    transparent_background=False,
    shadow_mode="bg",
)


Built-In Phase Names

  • "New / New Moon"
  • "Waxing Crescent"
  • "First Quarter"
  • "Waxing Gibbous"
  • "Full / Full Moon"
  • "Waning Gibbous"
  • "Last Quarter"
  • "Waning Crescent"

You may also use custom phase names when supplying phase_offset.


Related Tools

MoonTex Studio

  • MoonTex Studio is a visual GUI built on top of the MoonTex library that allows you to design, preview, and export procedural moon phases and full lunar cycles without writing code. It provides real-time previews, per-phase editing, and batch export tools for faster iteration in games and simulations.

Related Libraries

  • CQCalendar: A lightweight, tick-based time and calendar system for Python games and simulations.
  • TerraForge: A versatile Python toolset for procedural map generation.

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

moontex-1.0.1.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

moontex-1.0.1-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file moontex-1.0.1.tar.gz.

File metadata

  • Download URL: moontex-1.0.1.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for moontex-1.0.1.tar.gz
Algorithm Hash digest
SHA256 3309a4f5efe9ea9e3cbe5016633a7cfe2c4cba0c81c2088437ad5051797b6346
MD5 d5d4c5d8602ba67cf1fe78f20f4b8b33
BLAKE2b-256 15894463b8e29ccd8a14c5c74a40b570154d607236d4bd738e0abbae0f44dc81

See more details on using hashes here.

File details

Details for the file moontex-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: moontex-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for moontex-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 54b1d2808f9fc50706bff2d907a5470eb2d046bfa0fb46a809e18dc3cd50f818
MD5 3ce88e01504706d523ad2e76fb41d848
BLAKE2b-256 a84f963ef4c9dd14bd2ca2367137d9295fd4bc4cc6e0fa3db2930f0ca915ef93

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