Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
L-system
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Examples of L-systems== ===Example 1: algae=== Lindenmayer's original L-system for modelling the growth of algae. :'''variables''' : A B :'''constants''' : none :'''axiom''' : A :'''rules''' : (A β AB), (B β A) which produces: : ''n'' = 0 : A : ''n'' = 1 : AB : ''n'' = 2 : ABA : ''n'' = 3 : ABAAB : ''n'' = 4 : ABAABABA : ''n'' = 5 : ABAABABAABAAB : ''n'' = 6 : ABAABABAABAABABAABABA : ''n'' = 7 : ABAABABAABAABABAABABAABAABABAABAAB ==== Example 1: algae, explained ==== n=0: A start (axiom/initiator) / \ n=1: A B the initial single A spawned into AB by rule (A β AB), rule (B β A) couldn't be applied /| \ n=2: A B A former string AB with all rules applied, A spawned into AB again, former B turned into A / | | | \ n=3: A B A A B note all A's producing a copy of themselves in the first place, then a B, which turns ... / | | | \ | \ \ n=4: A B A A B A B A ... into an A one generation later, starting to spawn/repeat/recurse then The result is the sequence of [[Fibonacci word]]s. If one counts the length of each string, the [[Fibonacci sequence]] of numbers is obtained (skipping the first 1, due to the choice of axiom): : 1 2 3 5 8 13 21 34 55 89 ... If it is not desired to skip the first 1, axiom ''B'' can be used. That would place a ''B'' node before the topmost node (''A'') of the graph above. For each string, if one counts the ''k''-th position from the left end of the string, the value is determined by whether a multiple of the [[golden ratio]] falls within the interval <math>(k-1, k)</math>. The ratio of A to B likewise converges to the golden mean. This example yields the same result (in terms of the length of each string, not the sequence of ''A''s and ''B''s) if the rule (''A'' β ''AB'') is replaced with (''A'' β ''BA''), except that the strings are mirrored. This sequence is a [[locally catenative sequence]] because <math>G(n)=G(n-1)G(n-2)</math>, where <math>G(n)</math> is the ''n''-th generation. ===Example 2: fractal (binary) tree=== * '''variables''' : 0, 1 * '''constants''': "[", "]" * '''axiom''' : 0 * '''rules''' : (1 β 11), (0 β 1[0]0) The shape is built by [[recursion|recursively]] feeding the axiom through the production rules. Each character of the input string is checked against the rule list to determine which character or string to replace it with in the output string. In this example, a '1' in the input string becomes '11' in the output string, while '<nowiki>[</nowiki>' remains the same. Applying this to the axiom of '0', one gets: {| |- | axiom: || 0 |- | 1st recursion: || 1<nowiki>[0]</nowiki>0 |- | 2nd recursion: || <nowiki>11[1[0]0]1[0]0</nowiki> |- | 3rd recursion: || <nowiki>1111[11[1[0]0]1[0]0]11[1[0]0]1[0]0</nowiki> |- | ... |} It can be seen that this string quickly grows in size and complexity. This string can be drawn as an image by using [[turtle graphics]], where each symbol is assigned a graphical operation for the turtle to perform. For example, in the sample above, the turtle may be given the following instructions: * 0: draw a [[line segment]] ending in a leaf * 1: draw a line segment * <nowiki>[</nowiki>: push position and angle, turn left 45 degrees * <nowiki>]</nowiki>: pop position and angle, turn right 45 degrees The push and pop refer to a [[LIFO (computing)|LIFO]] stack (more technical grammar would have separate symbols for "push position" and "turn left"). When the turtle interpretation encounters a '<nowiki>[</nowiki>', the current position and angle are saved, and are then restored when the interpretation encounters a '<nowiki>]</nowiki>'. If multiple values have been "pushed," then a "pop" restores the most recently saved values. Applying the graphical rules listed above to the earlier recursion, one gets: {{Gallery |width=150 |File:Graftal0.png|Axiom |File:Graftal1.png|First recursion |File:Graftal2.png|Second recursion |File:Graftal3.png|Third recursion |File:Graftal4.png|Fourth recursion |File:Graftal7.png|Seventh recursion, scaled down ten times }} ===Example 3: Cantor set=== [[File:Cantor set in seven iterations.svg|450px|right]] : '''variables''' : A B : '''constants''' : none : '''start''' : A {starting character string} : '''rules''' : (A β ABA), (B β BBB) Let ''A'' mean "draw forward" and ''B'' mean "move forward". This produces the famous [[Cantor set|Cantor's fractal set]] on a real straight line '''R'''. ===Example 4: Koch curve=== A variant of the [[Koch snowflake|Koch curve]] which uses only right angles. : '''variables''' : F : '''constants''' : + − : '''start''' : F : '''rules''' : (F β F+F−F−F+F) Here, F means "draw forward", + means "turn left 90Β°", and − means "turn right 90Β°" (see [[turtle graphics]]). : ''n'' = 0: :: F :: [[File:square koch.svg|Koch Square - 0 iterations]] : ''n'' = 1: :: F+F−F−F+F :: [[File:square koch 1.svg|Koch Square - 1 iterations]] : ''n'' = 2: :: F+F−F−F+F+F+F−F−F+F−F+F−F−F+F−F+F−F−F+F+F+F−F−F+F :: [[File:square koch 2.svg|Koch Square - 2 iterations]] : ''n'' = 3: :: F+F−F−F+F+F+F−F−F+F−F+F−F−F+F−F+F−F−F+F+F+F−F−F+F+ ::F+F−F−F+F+F+F−F−F+F−F+F−F−F+F−F+F−F−F+F+F+F−F−F+F− :: F+F−F−F+F+F+F−F−F+F−F+F−F−F+F−F+F−F−F+F+F+F−F−F+F− :: F+F−F−F+F+F+F−F−F+F−F+F−F−F+F−F+F−F−F+F+F+F−F−F+F+ :: F+F−F−F+F+F+F−F−F+F−F+F−F−F+F−F+F−F−F+F+F+F−F−F+F :: [[File:square koch 3.svg|Koch Square - 3 iterations]] ===Example 5: Sierpinski triangle=== The [[Sierpinski triangle]] drawn using an L-system. : '''variables''' : F G : '''constants''' : + − : '''start''' : F−G−G : '''rules''' : (F β F−G+F+G−F), (G β GG) : '''angle''' : 120Β° Here, F and G both mean "draw forward", + means "turn left by angle", and − means "turn right by angle". <gallery mode="nolines" widths="256px" heights="256px"> File:Sierpinski Triangle (from L-System, 2 iterations).png|n = 2 File:Sierpinski Triangle (from L-System, 4 iterations).png|n = 4 File:Sierpinski Triangle (from L-System, 6 iterations).png|n = 6 </gallery> It is also possible to approximate the [[Sierpinski triangle]] using a [[SierpiΕski arrowhead curve]] L-system. : '''variables''' : A B : '''constants''' : + − : '''start''' : A : '''rules''' : (A β B−A−B), (B β A+B+A) : '''angle''' : 60Β° Here, A and B both mean "draw forward", + means "turn left by angle", and − means "turn right by angle" (see [[turtle graphics]]). [[File:Serpinski Lsystem.svg|centre]] {{center|1=Evolution for ''n'' = 2, ''n'' = 4, ''n'' = 6, ''n'' = 8}} ===Example 6: dragon curve === The [[dragon curve]] drawn using an L-system. : '''variables''' : F G : '''constants''' : + β : '''start''' : F : '''rules''' : (F β F+G), (G β F-G) : '''angle''' : 90Β° Here, F and G both mean "draw forward", + means "turn left by angle", and β means "turn right by angle". [[File:Dragon curve L-system.svg|centre|400px]] {{center|1=Dragon curve for ''n'' = 10}} ===Example 7: fractal plant === {{See also|Barnsley fern}} : '''variables''' : X F : '''constants''' : + − [ ] : '''start''' : -X : '''rules''' : (X β F+[[X]-X]-F[-FX]+X), (F β FF) : '''angle''' : 25Β° First one needs to initialize an empty stack. This follows the LIFO (Last in, First Out) method to add and remove elements. Here, F means "draw forward", β means "turn right 25Β°", and + means "turn left 25Β°". X does not correspond to any drawing action and is used to control the evolution of the curve. The square bracket "[" corresponds to saving the current values for position and angle, so the position and angle are pushed to the top of the stack, when the "]" token is encountered, the stack is popped and the position and angle are reset. Every "[" comes before every "]" token. [[File:Fractal-plant.svg|alt=|left]][[File:Fractal_Farn.gif|alt=]]{{center|1=Fractal plant for ''n'' = 6}}
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)