For this week's project, we were able to use some of the functions from our last lab and Project 4. I copied the code that enables us to read in lines from a text file, as well as the code from lab that places that information into variables and tells us how to execute the information in those lines. We were also able to use part of our drawShape function, which now included commands to store and restore the turtle, which is where things got more complicated. First, I created an empty list called "memory," which was used to remember where the turtle was last located. Each time the loop reads a "[" in my string, it stores at the end my "memory" list the position of the turtle by using memory.append( heading() ) and memory.append( position() ). Each time the loop reads a "]" in my string, it would bring the turtle back to the position last stored and "pop" (delete) the last elements of the list. Along with the variables 'F', '+', '-', 'L', and 'O', which controlled the distance, right(angle), left(angle), and leaves, respectively, the storing and restoring of the turtle position made it fairly easy to create our tree/plant structures.
The L-system and image for my first picture:
F-F-F-F
F
FF-F+F-F-FF
3
5
90
I messed around with that basic image, and thought it looked pretty cool with 45 degree angles instead of right angles. For some reason turtleWait() and tracer(False) wouldn't work here - the TA's tried to help me fix it, but not luck - so I did my best to capture the image at the very end. I think it's just about right, though maybe a second or two early and the pen is still showing. Here's the L-system and image:
F-F-F-F
F
FF-F+F-F-FF
3
5
90
Here's the L-system and image for my most basic tree structure:
F
F
F[+F]F[-F]F
4
7
25.7
That one was pretty boring, so I decided that I would make one for each season as my extensions. Here's my Spring tree, enhanced with a leaf that I created in my rffoster_shapes file and imported into my lsystem file. Here's the L-system and image:
F
F
F[+F]FL[-F]F
4
7
25.7
For my Summer tree, I simply added more leaves to my string to create a fuller, healthier looking tree:
F
F
F[+FL]FL[-FL]F
4
7
25.7
For the last, and definitely the most interesting, image, I went back to my leaf shape and changed the color to brown. I then createda second leaf with a yellow-orange color and added it as a new variable ('O') to my for loop. Here's the L-system and image:
F
F
F[+FO]F[-FL]F
4
7
25.7