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

From Coder Merlin
(Created page with "DRAFT ICON = Emergence & Lindenmayer Systems (Part 4) = thumb|Fractal Tree == Prerequisites == * Project-2513|Emergence & Lin...")
 
Line 53: Line 53:
** '''Push''' adds the specified element to the collection
** '''Push''' adds the specified element to the collection
** '''Pop''' removes the ''most recently added'' element  
** '''Pop''' removes 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

Revision as of 23:21, 12 February 2019

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

DRAFT ICON

Emergence & Lindenmayer Systems (Part 4)[edit]

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]

Continue with the previous project.

Enter into the Sources directory of the new project.

cd ~/projects/IgisShell-LSystems/Sources/IgisShell/

First Steps[edit]

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 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)

Exercises[edit]

  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

Key Concepts[edit]

  • 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 the most recently added element
  • LIFO means Last in, first out