L-System test 2

Stochastic, context sensitive and parametric L-System with 2D turtle graphics.

Turtle states:

rotation angle
angle in degrees. This value is used to modify the forward direction.
forward direction
angle in degrees
step size
step size, [1..]
stroke
stroke weight, [1..]

Turtle commands: (symbols)

F
draw forward one step or by the value optionally specified in parameter 0
f
draw forward half a step or by the value optionally specified in parameter 0
M
move forward one step or by the value optionally specified in parameter 0
m
move forward half a step or by the value optionally specified in parameter 0
P
draw to position specified in parameters 0 (x) and 1 (y)
p
move to position specified in parameters 0 (x) and 1 (y)
Q
draw relative by value specified in parameters 0 (x) and 1 (y)
q
move relative by value specified in parameters 0 (x) and 1 (y)
A
set the rotation angle to the value of parameter 0
R
rotate the turtle by the angle specified in parameter 0
+
rotate the turtle right by the angle from the current state or by the angle optionally specified in parameter 0
-
rotate the turtle left by the angle from the current state or by the negative value of angle optionally specified in parameter 0
S
multiply the stroke weight by 2 or set it to the value optionally specified in parameter 0
s
divide the stroke weight by 2
T
increase the stroke weight by 1
t
decrease the stroke weight by 1
D
multiply the step size by 2 or set it to the value optionally specified in parameter 0
d
divide the step size by 2
E
increase the step size by 1
e
decrease the step size by 1
c
set stroke color to grey value [0..1] specified in parameter 0 or rgb values [0..1] specified in parameters 0..2
^
push the turtle state to the stack
v
pop the turtle state from the stack

Production rule definition: (one line per rule)

left side modules :=
{ symbol, [ "<", parameter name, { ",", ... }, ">" ] }
right side modules :=
{ symbol, [ "<", value expression, { ",", ... }, ">" ] }
fix start or end := "0"
previous context := [ fix start or end ], left side modules
next context := left side modules, [ fix start or end ]
rule :=
[ selection probability, "ps:" ] ,
[ group probability, "pg:" ] ,
[ previous context, "{" ], left side modules, [ "}", next context] ,
[ ":", condition expression ] ,
"->" ,
right side modules

Additional definitions: (one line per definition)

• "name: ", string
instance name, used for load/save as a unique identifier
• "matchLongest:", bool (* = true *)
if true and more than rule matches, favor the longest match(es)
• "randomSeed:", string (* = "0" *)
seed for the pseudo random number generator

Generally:

• Each rule has a "selection probability" which determines if it's considered at all.
• If more than one rule matches, a rule is selected randomly.
For that, all the "group probability" values are stacked in a sequence of intervals starting at zero.
A random value between zero and the the highest value is generated to select the matching interval and therefore the matching rule.
• Each parameter name might only by used once per predecessor and rule.
• Parameters are specified between <>.
• Left and right context are separatated with { and }.
• '0' fixes contexts to start or end.
• Whitespaces are skipped.

Production rule definitions:

Increase the number of loops (#loops) and observe the Result string.

Additional definitions:

name: my L-System test
matchLongest: true
randomSeed: my random seed

Predefined systems:

Turtle parameters:
Step:
Angle:
L-System parameters:
#loops:
Storage:




L-System parameters:
Axiom:
Rules:
Result string: