FRACTAL TREES

 INTRODUCTION

Judging by the title, it might seem like a data structure lecture but this is something different, this is something very much interesting.

Let me tell you why I decided to write a blog on this.

THE CONTEXT

So, I was minding my own business when my brain thought about python. If you read my last blog you might've known that I do not like using python for anything except data science.

Well I felt like I was being too harsh on python and decided to try out it's turtle package.

Believe me or not, I never had used turtle in my entire life, I just knew how it worked but I end up using the javascript canvas for almost everything.

So I thought maybe I should do something very beautiful with turtle, and this was when I came across FRACTAL TREES.

FRACTAL TREES

Okay we saw about how I wanted to make fractal trees, but what are Fractal Trees and why should you care about it?

Each canopy is created by splitting a line segment into two smaller segments at the end and then splitting the two smaller segments as well, and so on, infinitely. Canopies are distinguished by the angle between concurrent adjacent segments and ratio between lengths of successive segments.

It's basically, a tree. A normal looking, weirdly symmetric tree.

Let's code this in turtle to visualize a basic fractal tree.

THE CODE

Coding this in turtle was quite easy, I had the help of turtle documentation and it's actually good(for now).

This was the result.






As you can see, the initial branch splits into two, and then those branches split into two and the pattern keeps repeating.

This looks good(not really), but I wanted more, I wanted more flexibility.

So I added a way in which I can change the angles between branches,


30 degrees


40 degrees


90 degrees



All the trees above are 15 leveled trees, which means that the initial branch has split 15 times. 

If you go beyond 90 degrees, the tree stops looking like a regular tree but creates really pretty looking patterns.
150 degrees

180 degrees



 Some of these trees make a really good looking pattern, this just shows how much a simple code with a bit of tweaks can do.

MORE...

Even though turtle is really good, I just wasn't satisfied with it, I wanted even more, so I headed towards the good ol' javscript canvas.

And the results, were prettier than I could ever imagine, I'm gonna keep this blog short and just throw some fractal trees at you, you can find the code for all the trees here.

Thank you for reading this blog, see ya next time.

Goodbye

And yeah, the treees...










I hope you enjoyed and yea see ya laterrr..






Comments

Post a Comment