plants are recursive!

using L-Systems to generate
realistic plants

by Sher Minn Chong / @piratefsh at !!Con

Sher Minn

Malaysian

front-end web engineer

Recurse Center alum

plants & recursion

plants

recursion

```javascript // recursive fibonacci function function fib(n){ if(n == 0){ return 0; } if(n == 1){ return 1; } return fib(n-2) + fib(n-1); } // call it fib(4) ```

repetition in a self-similar way

example

koch snowflake

recursion in nature

Aristid Lindenmayer

algae cell growth

L-Systems

a string rewriting system

axiom

A

rules

A → AB

B → A

axiom

A

rules

A → AB

B → A

n string
0A
1AB
2ABA
3ABAAB
4 ABAABABA

describing recursive patterns

string → drawing?

symbol do thing

F

draw a line

+

rotate clockwise by angle

-

rotate counterclockwise by angle

describing plants

symbol do thing

F

draw a line

+

rotate clockwise by angle

-

rotate counterclockwise by angle

[

save current state

]

restore saved state

introducing randomness

taking L-Systems further

image from The Algorithmic Beauty of Plants book
image from The Algorithmic Beauty of Plants book
Y = -FX-Y
X = X+YF+
simple rules beautiful paterns

resources

Algorithmic Beauty of Plants

Modelling Plants with L-Systems

L-Systems Turtle Graphics Renderer

demo code

end!

tweet at me
@piratefsh

demo: https://git.io/vwhe1 | slides: https://git.io/vwhvN