# Tree Fractal

A simple self-similar fractal. Similar to a Fern

Here's one that bifurcates at every iteration. By altering the angle of the branches we get completely different shapes. Topologically identical, but visually very different.

;export tree to tree :length :branches :angle :ratio fw :length if (:branches > 0) [ lt :angle tree (:length * :ratio) (:branches - 1) :angle :ratio rt (:angle * 2) tree (:length * :ratio) (:branches - 1) :angle :ratio lt :angle ] back :length end

;import tree tree 50 7 2 0.7 setxy 140 200 tree 50 7 30 0.7 setxy 340 200 tree 50 7 45 0.7 setxy 510 200 tree 50 7 90 0.7 setxy 630 200 tree 50 7 105 0.7 setxy 730 200 tree 50 7 135 0.7 setxy 840 200 tree 50 7 155 0.7 setxy 890 200 tree 50 7 180 0.7

It can be modified to appear more natural by adding a little randomness to each angle. Also altering the width of the branch based on its length, and adding color increases the natural appeal of the shape.

to tree :length :branches :angle :ratio penwidth :length/6 color [200 - :length*10 0 255 - :length*20] fw :length if (:branches > 0) [ make "x (rand 95 /10) make "y (rand 95 /10) lt :angle + :x + :y tree (:length * (:ratio + (random 90/100))) (:branches - 1) :angle :ratio + random 20/100 rt (:angle * 2) + :x + :y tree (:length * (:ratio + (random 90/100))) (:branches - 1) :angle :ratio + random 20/100 lt :angle - :x - :y ] pu back :length pd end srand 3 setxy 140 200 tree 50 10 30 0.7

And here's a pine tree, formed by trifuraction.

to pine :length :angle :ratio :ratio2 :limit ifelse (:length > :limit) [ penwidth :length /3 color [80 40 20] fd :length lt :angle pine (:length * :ratio) :angle :ratio :ratio2 :limit rt :angle rt :angle pine (:length * :ratio) :angle :ratio :ratio2 :limit lt :angle pine (:length * :ratio2) :angle :ratio :ratio2 :limit pu back :length pd ] [ penwidth 1 color [0 127 0] fd :length pu back :length pd ] end pine 60 45 0.5 0.75 2

Instead of bifurcating or trifurcating, let's N-furcate.

to npine :length :branches :splits :angle :ratio if (:branches > 0) [ fd :length lt (:angle * :splits) rt (:angle) repeat :splits [ npine (:length * :ratio) (:branches - 1) :splits (:angle) :ratio rt :angle * 2 ] lt (:angle * :splits) lt :angle pu rt 180 fd :length rt 180 pd ] end npine 50 6 4 16 0.7

Here's a more organic/natural feeling tree that's been windswept as it grew.

to tree :size ifelse :size <= 5 [ forward :size back :size ] [ forward :size/5 left 25 tree :size*2/3 right 25 forward :size/5 right 25 tree :size/2 left 25 forward :size/5 forward :size*2/5 right 35 tree :size/2 left 35 back :size ] end tree 300