add binary tree l-system from wikipedia
This commit is contained in:
parent
88bc73cdbe
commit
6c8c667042
48
binary_tree.ld
Normal file
48
binary_tree.ld
Normal file
|
@ -0,0 +1,48 @@
|
|||
& Example 2: fractal (binary) tree
|
||||
& from https://en.wikipedia.org/wiki/L-system
|
||||
box states = []
|
||||
|
||||
fn push! () -> {
|
||||
update! (states, append (_, turtle_state ()))
|
||||
}
|
||||
|
||||
fn pop! () -> {
|
||||
let state = do states > unbox > last
|
||||
update! (states, butlast)
|
||||
penup! ()
|
||||
load_turtle_state! (state)
|
||||
}
|
||||
|
||||
fn branch! () -> {
|
||||
pc! (colors :olive)
|
||||
pw! (4)
|
||||
fd! (20)
|
||||
}
|
||||
|
||||
fn one! {
|
||||
(0) -> {
|
||||
branch! ()
|
||||
}
|
||||
(n) -> {
|
||||
one! (dec (n))
|
||||
one! (dec (n))
|
||||
}
|
||||
}
|
||||
|
||||
fn zero! {
|
||||
(0) -> branch! ()
|
||||
(n) -> {
|
||||
one! (dec (n))
|
||||
push! ()
|
||||
lt! (inv (10))
|
||||
zero! (dec (n))
|
||||
pop! ()
|
||||
rt! (inv (10))
|
||||
zero! (dec (n))
|
||||
}
|
||||
}
|
||||
|
||||
zero! (7)
|
||||
|
||||
hideturtle! ()
|
||||
|
Loading…
Reference in New Issue
Block a user