Alyssa's Week 5 Assignment

Project 5: Turtles Climbing Trees

By: Alyssa Belisle

11 March 2008

Task 1

The first task was to create an lsystem.py file from the stringfun.py file created in lab. Then the drawShapes() function from last week's project was to be copied into the new file. This function was to be modified so that it could read in a string and not just a character. Then an L-system file was to be downloaded and saved. Then a variable needed to be created in order to hold the list of lines and then each element in the list needed to be put into the variables called base, symbol, rule, N, distance, and angle. Once these were put into variables and converted into the correct data type their values were to be printed. Then a for loop was to be used in order to process the string taken from the file and then the replace function is to be used in order to create a new string. This new string was to be sent to the drawShapes() function which needed to be modified once again. Two new parameters were to be added and three new elif cases were to be added to code for the new characters, 'F', '+', '-'. After these modifications are made the program is to be run and systemA is to be read by the lsystem.py file. Finally, the L-system was to be edited or one from the ABOP book was to be used. This creates scene5A.

See Scene A!!!


Task 2

The next task was to modify the drawShapes() function again in order to code for the '[' and ']' characters. The '[' character stores the current turtle state while the ']' restores the turtle state. After these modifications are made, the systemB file is to be downloaded and then modified. This creates scene5B.

See Scene B!!!


Task3

The final task was to add an 'L' character to the drawShape() function so that when called, leaves would be drawn on the trees. However, we needed to be sure to store and reset the position of the turtle, and to set the color to green and turn it back to black after the turtle is finished drawing the leaf. Then an 'L' was added to the replacement rule in systemB and the tree was drawn with leaves. This creates sceneC5.

See Scene C!!!


How to store and restore the turtle state.

The turtle state is stored by using the '[' character. This character is coded by using the append(position()) and append(heading()) functions. The turtle state is restored by using the ']' character. This character is coded by picking the turtle up, then using the setheading(pop()) and goto(pop()) functions and then the turtle is put down at its original position.


Extensions

A Tree With Shapes

This image was created by augmenting the systemB.txt file that was downloaded for this assignment. The base string was changed while the symbol for replacement was left alone. Then the rule was kept that same except that shapes were added to it, and the number of iterations remained the same. The distance to travel and the angle to turn by were increased. This creates a tree with shapes.

See The Shape Tree!!!


Another L-system

This image was created by using my own L-system.

See The Crazy Tree!!!


The Augmented ABOP Tree

This image was created by augmenting an L-system from the ABOP book site. A diamond shape was added to the rule line and a tree formed by diamonds was therefore created.

See the Diamond Tree!!!


Back to homepage