<commit_before># Trees
Described here is a primitive, fractal method of generating trees using *Mathematica*.  Trees like this:

![](trees.png)

The algorithm is quite simple:

1. Draw a line segment of [somewhat] random length at a [somewhat] random angle.
1. Decide if the tree is going to bifrucate at this point -- *i.e.* pick random integer between 1 and 2.
1. Call the the same routine which performed both of the above for each of new branches (either 1 or 2).
1. Repeat until the desired depth is achieved.

Most who implement this algorithm are disappointed because the trees do not look realistic:

![](bad_trees.png)

The inevitable zig-zag fest is due to a subtle yet physically important detail: the angle of the branch is not a mere random number, it is a random **deviation from the branch upon which it grows**.  The angle is given by:

![](https://chart.googleapis.com/chart?cht=tx&chl=\\theta_n%20=%20\\theta_{n-1}%20%2b%20random(-\\alpha,%20\\alpha))

**not** by:

![](https://chart.googleapis.com/chart?cht=tx&chl=\\theta_n%20=%20random(-\\alpha,%20\\alpha))

This correction alone turns what wouldn't even pass for drunken lighting into tree-looking objects.  Variation of length and thickness of the branches play an important role as well.

## Algorithm
```Mathematica
branches[x0_, y0_, maximumDepth_, maximumNfrucation_, maximumDeviation_, initialLean_] := Module[{
    x = x0, y = y0,
    depth = maximumDepth,
    Nfrucation = maximumNfrucation,
    deviation = maximumDeviation,
    lean = initialLean,
    angle, nfrucation, r, x1, y1
    },
    If[depth > 0,
    (* Play around with these two to attain the desired tree structure *)
    (* Angle of the branch *)
    angle = lean + deviation*Random[Real, {-.5, .5}];
    (* Length of the branch *)
    r = Log[depth]*Random[Real, {.5, 1}];
    
    (* Number of branches *)<commit_msg>Formula styling.<commit_after># Trees
Described here is a primitive, fractal method of generating trees using *Mathematica*.  Trees like this:

![](trees.png)

The algorithm is quite simple:

1. Draw a line segment of [somewhat] random length at a [somewhat] random angle.
1. Decide if the tree is going to bifrucate at this point -- *i.e.* pick random integer between 1 and 2.
1. Call the the same routine which performed both of the above for each of new branches (either 1 or 2).
1. Repeat until the desired depth is achieved.

Most who implement this algorithm are disappointed because the trees do not look realistic:

![](bad_trees.png)

The inevitable zig-zag fest is due to a subtle yet physically important detail: the angle of the branch is not a mere random number, it is a random **deviation from the branch upon which it grows**.  The angle is given by:

![](https://chart.googleapis.com/chart?cht=tx&chl=\\theta_n%20=%20\\theta_{n-1}%20%2b%20random(-\\alpha,\\,\\alpha))

**not** by:

![](https://chart.googleapis.com/chart?cht=tx&chl=\\theta_n%20=%20random(-\\alpha,\\,\\alpha))

This correction alone turns what wouldn't even pass for drunken lighting into tree-looking objects.  Variation of length and thickness of the branches play an important role as well.

## Algorithm
```Mathematica
branches[x0_, y0_, maximumDepth_, maximumNfrucation_, maximumDeviation_, initialLean_] := Module[{
    x = x0, y = y0,
    depth = maximumDepth,
    Nfrucation = maximumNfrucation,
    deviation = maximumDeviation,
    lean = initialLean,
    angle, nfrucation, r, x1, y1
    },
    If[depth > 0,
    (* Play around with these two to attain the desired tree structure *)
    (* Angle of the branch *)
    angle = lean + deviation*Random[Real, {-.5, .5}];
    (* Length of the branch *)
    r = Log[depth]*Random[Real, {.5, 1}];
    
    (* Number of branches *)
{'fraction_non_alphanumeric': 0.11117064023573534, 'fraction_numerical': 0.018751674256630057, 'mean_word_length': 3.8683181225554106, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6970523', 'n_tokens_mistral': 1184, 'n_tokens_neox': 1098, 'n_words': 467}