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!
===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 }}
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)