Pixelart Tree GeneratorJanuary 2nd 2021
This project is from about 18 months ago but I wanted to put someting on the blog so here goes!
I was working on a little survival game and while populate my little 2D world with fauna I wondered if anyone had written a good algorithm for creating tree art. It’s a well-understood biological process so I thought it would be easy enough to emulate (especially given how much programmers love trees!).
After a little digging I found this Reddit post, I played around with their generator but wanted to make my own. They put the source code behind a paywall so I kept searching and came across this animation, showing how these trees were generated. This gave me enough to work with.
I set about making my program in Python, with a little Tkinter interface. The algorithm works by growing the tree from the root, emulating nature and following a similar process to the animation above. There is then a random chance of branching, splitting, etc. as well as a number of parameters to control the depth of branches, the width by which the trunk changes each step and the amount of leaves to draw. The result is a happy little tree like this.
The UI looks like this, the default settings which were used to generate the above tree are also shown in the screenshot.
You might have noticed the “Animate” button and various animation settings, indeed it can generate animations and it would be remiss of me not to show you one!
The project can be downloaded here.