4 Conditional L-systems

An L-system with parameters can dispatch on those parameters, picking between rewrites for a single symbol. For example:

#lang lindenmayer racket
 
## axiom ##
A(0)
## rules ##
A(d) : d > 0 -> A(d-1)
A(d) : d = 0 -> F(1/2)[+A(D)]F(1/2)B(0)
B(d) : d > 0 -> B(d-1)
B(d) : d = 0 -> F(1/2)[-B(D)]F(1/2)A(0)
F(a)         -> F(a*R)
## variables ##
D=1
R=1.36
n=20
θ=45
============================================================
(require lindenmayer/turtle)
(provide (all-from-out lindenmayer/turtle) (all-defined-out))
(define (A turtles variables . _) turtles)
(define (B turtles variables . _) turtles)

Has the A and B rules dispatch on the parameter d, to produce:

image

Conditionals are placed before ->, and after a :. Conditions can be joined by an &. Currently supported comparisons are: =< > .