![]() |
![]() |
![]() |
![]() |
|---|---|---|---|
| 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.
- 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.jsonand 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.
- Clone the repository
git clone https://github.com/Nitnaf10/Tree-generator.git
cd Tree-generator- Install dependencies The project requires Python 3.8 or newer and the Pillow library.
pip install pillow- Run the script
python main.py --helpThe program is controlled through subcommands.
python main.py generate --type oak --seed 12345 --save my_oakArguments 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.pngpython 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.4This 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 blossomAll 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()))"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]
}
}Tree-generator/
├── main.py # Main script (generation and CLI)
├── preset.json # Persistent tree presets (auto-created)
├── generated/ # Output images (created automatically)
└── README.md
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.
Found a bug? Open an issue



