
baby's first tree
December 15, 2022
ian jojo
today I'm learning all about recursion and getting lost in math with the hope if generating a beautiful tree
p5
Today's experiment has been a long time coming. I've been fascinated by creative uses of coding for a long time. I've mostly been experimenting with generative music as music is more my background, but today I went in another direction. I'm really not much of an artist when it comes to drawing with a pen and paper. I can never seem to translate what's in my head onto the page. I just don't have those skills. But the realization that I can create visual art with code has been a very exciting one.
I started with a brief lesson on recursion and the use of π to replicate natural curves. Drawing a line, changing the angle by a fraction of π, then another line - each time a little shorter than the last. Then again on the other side, but with a negative angle value. It's pretty magical how this starts to emulate real natural foliage.

From here I began to randomize the values of the angles and the length of each line, just slightly, to make things less symmetrical and more natural.
Once my tree function was giving me results like this, I made an array of several foliage colours and cycled through it each time a line was drawn to vary the colouring. I then started writing loops to place these trees at various spots along the X axis, randomly again, providing different height values for each one. I created a few different layers of trees and added bits of blur to the further layers, while also experimenting with different visual blend modes. I ended up liking the way things became a bit ghostly while using blend modes like burn and multiply.
Finally, I added a background image for my trees to stand out a bit more. In the future I'd like to work on generating a background similarly to how I'm generating my trees. But for now I'm quite happy with how this turned out as well as with the concept that the final drawing will never be the same twice. The initial spark for this project was all thanks to Daniel Shiffman's Coding Train series and I really can't thank him enough for this inspiration.
You can check out my final piece here - each time you click the mouse, a new scene will be generated (give it a few seconds). I hope this writeup was somewhat informative and perhaps inspires someone to also create art with code.