## Digital Tree Generator

Cellular automaton · 4/24/2016Plants need water, sunlight and nutrients to grow. The forest of ASCII trees you see in the background of RattyDuck.com thrives off of git commits. Each time I make a commit to the site's git repository, the trees grow a little. How does this work?

The forest is a cellular automaton with cells that take on states like `\`

, `|`

, and `/`

. The rules of the cellular automaton dictate how the branches of the trees grow. For example, here's a simple rule that causes a vertical branch to grow straight up:

```
→ |
| |
```

When applied iteratively, this rule generates the following tree:

It's not very exciting. Let's add another rule that generates an angled branch on top of a vertical branch:

```
→ \
| |
```

Now we have two competing rules: each rule applies to a single vertical branch. Since both rules could apply in this case, we can flip a coin to decide which rule to use. (Technically speaking, this means our tree generator is a stochastic cellular automaton.) While we're at it, let's throw in a few more rules to grow off of the angled branch:

| \ → \ | | \ \ → \ | | - \ → \ | |

Again, we can select which rule to apply randomly. If we run the tree growing algorithm now, we get the following lopsided tree:

If we want the tree to look more natural, we need to add more rules. Angled branches should be able to grow to the right, for example.

The final version of the tree generator has around 30 rules, including rules for growing "fruit" (represented by `o`

, that grow into `O`

, that ripen into `@`

, that drop `.`

seeds, which fall to the ground and start new trees).

These animations show a sped-up version of the same simulation that grows the forest in the background of my site. This forest grows by one simulation step every time I update, as if being fed from the bits I commit to the site's git repository.