Perl-Based Interpretation
of
Parametric L-Systems

...and other exciting subjects.

The Parser half of the L-system code is now ready. The Parser consists of a Perl program (PARAM.PL) containing the Parser code, and another Perl program containing the L-system definitions (rules, constants, algorithms, pre-defined shapes, etc). Unlike other parsers, this system has the benefit of parsing parametric and stochastic L-systems just as easily as "normal" L-systems. (Context-sensitive L-systems are left as an exercise for the reader. 8-)

The image on the right is a simple "flowchart" showing how the complete system works. The parser is on the left (barely visible Perl code). The interpreter (bottom) takes pre-defined DXF shapes (if any) from a modeller (top) along with turtle information from the Parser and produces a complete DXF model which can then be used in any rendering engine (right). The model here is my rendition of the "lilac" seen on page 92 of The Algorithmic Beauty of Plants (ABOP). The flower model I created in Rhinocerous while the interpreter and parser created the framework for the complete stalk.

Downloads Here are some examples of L-system definitions converted to Perl for the PARAM.PL parser. Download the Parser for more examples.

L-System Definition
#define R 1.456
 w: A(1)
p1: A(s) -> F(s)[+A(s/R)][-A(s/R)]

From p.48 ABOP, ©1990 Springer-Verlag
Perl "Definition"
$R = "1.456";
$constructor = "A(1)";

sub A {
   local($s) = $_[0];
   return "F($s)[+A(".($s/$R).")][-A(".($s/$R).")]";
}
L-System Definition
 w: B(2)A(4,4)
p1: A(x,y) : y <= 3 -> A(x*2,x+y)
p2: A(x,y) :  y > 3 -> B(x)A(x/y,0)
p3:   B(x) :  x < 1 -> C
p4:   B(x) : x >= 1 -> B(x-1)
From p.42 ABOP, ©1990 Springer-Verlag
Perl "Definition"
$constructor = "B(2)A(4,4)";

sub A {
   local($x,$y) = @_;
   if ($y <= 3) { return "A(".($x*2).",".($x+$y).")"; }
   if ($y > 3) { return "B($x)A(".($x/$y).",0)"; }
}

sub B {
   local($x) = $_[0];
   if ($x < 1) { return "C"; }
   if ($x >= 1) { return "B(".($x-1).")"; }
}


Return to the Index

This page is created and maintained by Sean O'Malley. Most texts, code segments, images, and linked files contained on this site are copyright ©2000 by Sean O'Malley and may not be copied, reproduced, or used in any medium without permission.
1