Lsys {LindenmayeR} | R Documentation |
Rewrite an Axiom Using Production Rules to Give a String Ready for Turtle Graphics
Description
This is the central function for rewriting an initial string of symbols (the axiom) into a new string using production rules. Production rules are very simple: if the symbol is A, turn it into something. If it is B, turn it into something else. Production rules typically contain instructions about moving while drawing, moving w/o drawing, changing direction, or storing the current state for re-use later.
Usage
Lsys(init = NULL, rules = NULL, n = 5, retAll = TRUE, verbose = 1L)
Arguments
init |
A character string giving variables (symbols) to use as the initial string Also known as the axiom. |
rules |
A data frame containing columns "inp" and "out". These contain the input
variables and the corresponding replacement string. See the examples in
|
n |
An integer giving the number of cycles or iterations desired. |
retAll |
Logical. If |
verbose |
An integer giving the level of information desired as the calculation
proceeds. |
Details
The job of this function is to take an input "axiom" and apply the "production
rules" and other paramters to create a new string of drawing instructions. The
"language" or character set of the axiom and production rules are arbitary, and
the internet and literature contains many different examples. The same fractal
could be drawn using completely different sets of symbols. The string produced
by this function is processed by drawLsys
. See there for further
explanation and examples.
Value
If retAll = FALSE
, a character vector of length 1 giving the string
at the end processing. Otherwise, a character vector of length n + 1
containing init
plus the results at the end of each iteration.
See Also
drawLsys
for examples, including plotting.