Description Usage Arguments Details Value See Also Examples
Generate L-systems.
1 2 3 4 5 6 7 8 9 10 11 |
axiom |
A string of symbols representing the initial state of the system. |
rules |
A list of named strings forming the rules. |
n |
The number of iterations. |
angle |
The angle in radians which determines the change in direction for every "+" or "-". |
initial_angle |
The initial angle of the first line in radians. |
draw_f |
A character vector of symbols the replace with "F" in the instructions. |
return_string |
Logical. If |
extra_info |
Logical. If |
remove_duplicates |
Logical. If |
List of valid instructions:
F
Draw a line in the current direction.
+
or -
Turn by angle.
[
or ]
Save or load current state.
@
Multiply the line length by the following numerical argument.
!
Flip the angle direction.
Depending on the value of return_string
either the string of
instructions after n
iterations or a data frame of class "l_system" with
the columns x0, y0, x1, and y1 determining the endpoints of the line
segments. Includes additional columns if extra_info
is TRUE
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | # plant:
l_plant <- l_system(
axiom = "X",
rules = list(
X = "F+[[X]-X]-F[-FX]+X",
F = "FF"
),
n = 7,
angle = pi * 0.15,
initial_angle = pi * 0.45
)
plot(l_plant, col = colorRampPalette(c("#008000", "#00FF00"))(100))
# dragon curve:
l_dragon <- l_system(
axiom = "FX",
rules = list(
X = "X+YF+",
Y = "-FX-Y"
),
n = 12,
angle = pi / 2,
initial_angle = 0
)
plot(l_dragon, col = rainbow(nrow(l_dragon)))
# sierpinski triangle:
l_triangle <- l_system(
axiom = "F-G-G",
rules = list(
F = "F-G+F+G-F",
G = "GG"
),
n = 6,
angle = radians(120),
initial_angle = radians(60),
draw_f = "G"
)
plot(l_triangle)
# changing line length, flipping angle, and using extra_info = TRUE
# to vary color and line thickness:
l_tree <- l_system(
axiom = "X",
rules = list(X = "F[+@.7X]F![-@.6X]F"),
n = 10,
angle = radians(22.5),
extra_info = TRUE
)
plot(
l_tree,
col = ifelse(l_tree$depth < 6, "sienna", "forestgreen"),
lwd = l_tree$depth / max(l_tree$depth) * -2 + 3
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.