Difference between revisions of "W2514 Emergence & Lindenmayer Systems (Part 4)"

From Coder Merlin
 
(6 intermediate revisions by 2 users not shown)
Line 11: Line 11:


=== Getting Started ===
=== Getting Started ===
Continue with the previous project.
Modify the code from your previous experience.


Enter into the Sources directory of the project.
<syntaxhighlight lang="bash">
cd ~/projects/IgisShell-LSystems/Sources/IgisShell/
</syntaxhighlight>
=== First Steps ===
[[File:Lifo stack.png|thumb|Stack]]
[[File:Lifo stack.png|thumb|Stack]]
'''Turtle''' objects are able to remember their current state and restore that state at a later point.  The state is stored on a stack and is therefore in ''LIFO'' (Last In First Out) order.  A turtle's state includes:
'''Turtle''' objects are able to remember their current state and restore that state at a later point.  The state is stored on a stack and is therefore in ''LIFO'' (Last In First Out) order.  A turtle's state includes:
Line 42: Line 36:
</syntaxhighlight>
</syntaxhighlight>


== Exercises ==
Regardless of what occurs '''between''' a ''push'' and a ''pop'', the turtle will be in the same situation it was in immediately prior to the ''push''.  This enables us to build very complex systems, such as Kev's Wispy Tree.
# Add a Fractal Tree as one of the Lindenmayer Systems in your cycle
# Add a Fractal Plant as one of the Lindenmayer Systems in your cycle
# Add "Kevs Wispy Tree" as one of the Lindenmayer Systems in your cycle


=== Kevs Wispy Tree (Adapted) ===
=== Kev's Wispy Tree<ref>Adapted from http://www.kevs3d.co.uk</ref> (Adapted) ===
* Alphabet: "F", "X", "[", "]", "+", "-", "0", "1", "2", "3"
* Alphabet: "F", "X", "[", "]", "+", "-", "0", "1", "2", "3"
* Axiom: "FX"  
* Axiom: "FX"  
Line 65: Line 56:
** "3" -> Pen color: red:64, green:255, blue:64
** "3" -> Pen color: red:64, green:255, blue:64


Note: Adapted from http://www.kevs3d.co.uk
{{SeeAlso|
[[Category:Lindenmayer system||Recursion||Production rules]]|
}}


== Supplemental Exercises ==
== Exercises ==
# Add buttons to alter the angles used in drawing the L-Systems
{{W2514-Exercises}}
# Construct your own Lindenmayer System and add it to your cycle
 
== Bonus Exercises ==
# Animate the entire production of the Lindenmayer System (not just from generation to generation, but the application of each production rule in sequence)


== Key Concepts ==
== Key Concepts ==
{{KeyConcepts|
* A '''Stack''' is an abstract data-type which is a collection of elements with two principal operations:
* A '''Stack''' is an abstract data-type which is a collection of elements with two principal operations:
** '''Push''' adds the specified element to the collection
** '''Push''' adds the specified element to the collection
** '''Pop''' removes and returns the ''most recently added'' element  
** '''Pop''' removes and returns the ''most recently added'' element  
* '''LIFO''' means '''L'''ast '''i'''n, '''f'''irst '''o'''ut
* '''LIFO''' means '''L'''ast '''i'''n, '''f'''irst '''o'''ut
}}
{{#set: Has primary media type=Text }}
[[Category:Lindenmayer system]]
[[Category:Recursion]]
[[Category:Production rules]]

Latest revision as of 21:12, 25 April 2021

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder
Fractal Tree

Prerequisites[edit]

Research[edit]

  • Read Stacks
  • Review those Lindenmayer Systems that require use of a stack (pop/push). One example is a "Fractal Tree".

Experiment[edit]

Getting Started[edit]

Modify the code from your previous experience.

Stack

Turtle objects are able to remember their current state and restore that state at a later point. The state is stored on a stack and is therefore in LIFO (Last In First Out) order. A turtle's state includes:

  • location
  • angle
  • pen color
  • pen width

Consider a Fractal Tree with the following translation mechanisms:

  • 0: draw a line segment (ending in a leaf)
  • 1: draw a line segment
  • [: push position and angle, turn left 45 degrees
  • ]: pop position and angle, turn right 45 degrees

When encountering a push or pop operation we can use the turtle's functionality as follows:

           case "[":
                turtle.push()
                turtle.left(degrees:45)
           case "]":
                turtle.pop()
                turtle.right(degrees:45)

Regardless of what occurs between a push and a pop, the turtle will be in the same situation it was in immediately prior to the push. This enables us to build very complex systems, such as Kev's Wispy Tree.

Kev's Wispy Tree[1] (Adapted)[edit]

  • Alphabet: "F", "X", "[", "]", "+", "-", "0", "1", "2", "3"
  • Axiom: "FX"
  • Production Rules:
    • "F" -> "0FF-[1-F+F]+[2+F-F]"
    • "X" -> "0FF+[1+F]+[3-F]"
  • Geometric mechanism:
    • "F" -> Forward
    • "X" -> Forward
    • "-" -> Right 25 degrees
    • "+" -> Left 25 degrees
    • "[" -> Push
    • "]" -> Pop
    • "0" -> Pen color: red:140, green:80, blue:60
    • "1" -> Pen color: red:24, green:180, blue:24
    • "2" -> Pen color: red:48, green:220, blue:48
    • "3" -> Pen color: red:64, green:255, blue:64

👀 See Also[edit]

📺 Videos[edit]

Lindenmayer Systems and The Nature of Code
Procedural Plant Generation with L-Systems

📖 Texts[edit]

W2511 Emergence & Lindenmayer Systems (Part 1)
W2512 Emergence & Lindenmayer Systems (Part 2)
W2513 Emergence & Lindenmayer Systems (Part 3)
W2514 Emergence & Lindenmayer Systems (Part 4)

📚 References[edit]

Exercises[edit]

ExercisesExercisesIcon.png
  1. Add a Fractal Tree as one of the Lindenmayer Systems in your cycle
  2. Add a Fractal Plant as one of the Lindenmayer Systems in your cycle
  3. Add "Kevs Wispy Tree" as one of the Lindenmayer Systems in your cycle

Supplemental exercises:

  1. Add buttons to alter the angles used in drawing the L-Systems
  2. Construct your own Lindenmayer System and add it to your cycle
  3. Animate the entire production of the Lindenmayer System (not just from generation to generation, but the application of each production rule in sequence)

Key Concepts[edit]

Key ConceptsKeyConceptsIcon.png
  • A Stack is an abstract data-type which is a collection of elements with two principal operations:
    • Push adds the specified element to the collection
    • Pop removes and returns the most recently added element
  • LIFO means Last in, first out