Lab5

Lab 5 Write-up

Task:

The task for this lab was to create a program that could take a file containing commands for an L-system, and then interpret the commands appropriately. In order to do this it was necessary to read each line of the file separately and convert each line to it’s appropriate variable. The first line is the base, the second line is the symbol, the third line is the rule, the fourth line is the number of iterations, the fifth line is the distance, and the sixth line is the angle.

Storing and Restoring the Turtle State:

In order to store the turtle state, I used the “append” command to add the heading of the turtle, and then the position of the turtle to the list. Then, when taking items off the list using the “pop” command, I first popped the position, since it was the top item on the list, and then I popped the heading, since it was the next item on the list.

Scene A

L-system used:

Base: F-F-F-F

Symbol: F

Rule: FF-F+F-F-FF

Itterations: 3

Distance: 5

Angle: 90

Scene B

L-system used:

Base: F

Symbol: F

Rule: FF-[-F+F+F]+[+F-F-F]

Itterations: 3

Distance: 5

Angle: 22.5

Scene C (found at http://www.jcu.edu/math/vignettes/lsystems.htm)

L-system used:

Base: F

Symbol: F

Rule: F[-FF]F[+FF][F]

Itterations: 3

Distance: 7

Angle: 22.5

Scene D (lines for leaves)

L-system used:

Base: F

Symbol: F

Rule: FF-[-F+F+Flk]+[+F-F-Flk]

Itterations: 3

Distance: 5

Angle: 22.5

Scene E (circles for leaves)

L-system used:

Base: F

Symbol: F

Rule: FF-[-F+F+Flk]+[+F-F-Flk]

Itterations: 3

Distance: 5

Angle: 22.5

Scene F

For scene F, I randomized the color of each branch by changing the color under the F command to “ color(random(), random(), random())”

L-system used:

Base: F

Symbol: F

Rule: FF-[-F+F+F]+[+F-F-F]

Itterations: 3

Distance: 5

Angle: 22.5

Scene G

For Scene G, I randomized the angle of the branches, not by using a Gaussian distribution, but by changing the “ +” and “- ” commands to “ left(random()*2*angle) ” and “ right(random()*2*angle)” respectively

L-system used:

Base: F

Symbol: F

Rule: FF-[-F+F+Flk]+[+F-F-Flk]

Itterations: 3

Distance: 5

Angle: 22.5