17
Oct
04

Tree Fractal

Tree Fractal – adapted from from Renan Cabrera’s Mathematica code. This is an example of a bracketed Lindenmayer System (L-System). You can also use this technique to make lightning bolts.
(* runtime: 1 second *)
Polar[{x_, y_}, theta_, r_] := {x + r Cos[theta], y + r Sin[theta]};
branch[x_] := x; branch[tree_List] := branch /@ tree;
branch[Line[{p1_, p2_}]] := Module[{r = Sqrt[(p2[[1]] - p1[[1]])^2 + (p2[[2]] - p1[[2]])^2], theta = ArcTan[p2[[1]] - p1[[1]], p2[[2]] - p1[[2]]]}, {Thickness[0.05r], RGBColor[0.5r, 1 - 0.75r, 0], Line[{p2, Polar[p2, theta - Pi/6, 0.8r]}], Line[{p2, Polar[p2, theta + Pi/4, 0.7r]}]}];
Show[Graphics[{Thickness[0.07], RGBColor[0.5, 0.25, 0], NestList[branch, Line[{{0, 0}, {0, 1}}], 12]}], AspectRatio -> 1, Background -> RGBColor[0, 0, 0], PlotRange -> {{-3, 3}, {0, 6}}];

Links

Advertisements

0 Responses to “Tree Fractal”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Welcome !

You will find here some of my favorite hobbies and interests, especially science and art.

I hope you enjoy it!

Subscribe to the RSS feed to stay informed when I publish something new here.

I would love to hear from you! Please feel free to send me an email : bugman123-at-gmail-dot-com

Archives

Blog Stats

  • 548,959 hits

%d bloggers like this: