Skip to content
Generate Pythagoras Tree Fractals 🌳
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
.gitignore
LICENSE.md
README.md
tree.py

README.md

Pythagoras Tree Fractal Generator

Introduction

The Pythagoras Tree Fractal is a fractal that is made up of cubes and triangles. When it is generated with enough iterations, it looks like a tree, so that's where the name came from. You can read more over it on wikipedia.

Examples

Image of Pythagoras Tree Fractal Image of Pythagoras Tree Fractal

Prerequisites

  • Python >= 3.2
  • pip
  • Pillow
  • numpy

Installation

git clone https://github.com/lagmoellertim/pythagoras-tree-fractal.git

cd pythagoras-tree-fractal

Usage

Initialize the Generation Process

generator = TreeFractal()

You can specify the width, height, base_length, background_color, offset_x and offset_y as seen in the code documentation

Generate a Tree

generator.generate()

You can choose the depth, background color, a style generation function, angle and mirror as seen in the code documentation

Custom style generation function

You can create your own style generation functions, based on this example function

def new_style_generator(depth, shape=None):
    if shape == "cube":
        return {"fill": (depth*10, 0, 0), "outline": (0, 0, 0)}
    elif shape == "triangle":
        return {"fill": (0, 0, 0), "outline": (depth*10, 0, 0)}

generator.generate(style_gen=new_style_generator)

Save the image

generator.save(*filename*)

Contributing

If you are missing a feature or have new idea, go for it! That is what open-source is for!

Author

Tim-Luca Lagmöller (@lagmoellertim)

Moritz Simonsmeier (@simonchristiansen)

Donate

You can also contribute by buying me a coffee.

License

MIT License

Copyright © 2019-present, Tim-Luca Lagmöller & Moritz Simonsmeier

Have fun 🎉

You can’t perform that action at this time.