Skip to content

Repository files navigation

Tree Generator

Python License Status GitHub last commit GitHub issues GitHub stars GitHub forks

Examples

birch cherry_blossom oak strange
birch tree cherry blossom tree oak tree a strange tree

A procedural tree generator that creates pixel-art trees with customizable trunk and foliage colors.
Trees are grown using random walks and stored as PNG images. All tree types (presets) are saved in a preset.json file, which can be extended via the command line.

Features

  • Procedural generation – each tree is unique thanks to seed-based randomness.
  • Multiple built-in presets – oak, birch, and a strange variant with distinct shapes and colors.
  • Custom tree creation – define your own tree type with custom growth rules and colors.
  • Persistent presets – all tree types are stored in preset.json and survive restarts.
  • Color customization – every preset can have its own trunk and leaf colors.
  • Simple command-line interface – generate images and manage presets without editing code.

Installation

  1. Clone the repository
git clone https://github.com/Nitnaf10/Tree-generator.git
cd Tree-generator
  1. Install dependencies The project requires Python 3.8 or newer and the Pillow library.
pip install pillow
  1. Run the script
python main.py --help

Usage

The program is controlled through subcommands.

Generate a tree image

python main.py generate --type oak --seed 12345 --save my_oak

Arguments for generate:

Option Description
--type Tree preset name (e.g., oak, birch, strange). If omitted, a random preset is chosen.
--seed Integer seed for reproducible generation. If not given, a random seed is used.
--save Base name for the output PNG (saved into generated/). If not provided, no image is saved.

Example:

python main.py generate --save random_tree
# Output: Generating a birch with the seed 9876543
#         Saving the generated tree as generated/random_tree.png

Create a new tree preset

python main.py create cherry_blossom --log_min 8 --log_max 12 --leave_min 10 --leave_max 15 --log_color "180,130,150" --leave_color "255,182,193" --logd_up 0.9 --logd_down 0.1 --leaved_up 0.7 --leaved_down 0.4

This adds (or overwrites) the preset cherry_blossom with custom parameters:

  • --log_min / --log_max : range for the number of trunk blocks.
  • --leave_min / --leave_max : factor applied to log count to determine leaf block count.
  • --logd_up, --logd_left, --logd_down, --logd_right : probability (0–1) that the trunk extends in that direction.
  • --leaved_up, --leaved_left, --leaved_down, --leaved_right : probability that leaves spread in that direction.
  • --log_color : RGB color for the trunk, as R,G,B.
  • --leave_color : RGB color for the foliage, as R,G,B.

Once created, the new type is immediately usable:

python main.py generate --type cherry_blossom --save blossom

List available presets

All presets are stored in preset.json. You can view them manually or list keys with a short Python command:

python -c "import json; print(list(json.load(open('preset.json')).keys()))"

Preset file (preset.json)

The file preset.json contains all tree definitions. It is automatically created with three default presets (oak, birch, strange) on the first run. You can edit it directly, but using the create command is recommended to avoid formatting errors.

Example structure:

{
  "oak": {
    "log_range": [5, 15],
    "logd": [0.9, 0.1, 0.05, 0.1],
    "leave_factor_range": [9, 12],
    "leaved": [0.5, 0.6, 0.5, 0.6],
    "log_color": [120, 75, 0],
    "leave_color": [20, 200, 75]
  }
}

File Structure

Tree-generator/
├── main.py          # Main script (generation and CLI)
├── preset.json      # Persistent tree presets (auto-created)
├── generated/       # Output images (created automatically)
└── README.md

License

This project is distributed under the MIT License. See the LICENSE file for details (if not present, the standard MIT terms apply).

Contributions, issues, and suggestions are welcome.

Support

Found a bug? Open an issue

About

Tree Generator - Procedural pixel-art tree generator with customizable trunk and foliage colors. Create your own tree types via CLI, save them as PNG, and persist all presets in preset.json.

Topics

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages