Alyssa's Week 9 Assignment

Project 9: Forests of Trees

By: Alyssa Belisle

15 April 2008

Task

The task was to use classes in order to read in L-systems to create trees. The class holds all the components of the L-system and reads and writes all the information to a file. We are to build L-systems into strings and then manipulate them in order to make new scenes and trees. Five fields, including a distance, base string, iterations, angle, and rules field are used to store values into the class. Then the methods are called and written and then a test function ends the lsystem2.py file. Then parse.py is run and trees are created. The next part of the task is to use different L-systems to make a scene of trees. This is done by processing different strings created by the L-system components. The final scene can be seen below.


Fields in the L-System object

The object has fields for the base string, the rules, iterations, the angle, and the distance. The base string field holds a string. The rules fields holds a list of the L-System rules. The iterations field holds an integer. The angle field holds a floating point, and the distance field also holds a floating point.


Algorithm

To create my final scene I used a modified parse.py file that I named myscene.py. In this file I modified the main() function so that different L-Systems would be drawn to create six different trees of various sizes and at various locations. I used the pop() and append() methods to save the turtle location when it began to draw each tree and then I moved the turtle by specific amounts in order to locate the trees at different positions within the window that was created. The turtle.Tracer(False() function was used so that the whole scene would be drawn at once and the user would not have to wait for the turtle to draw all the objects in the scene.


L-Systems Used

ls1.set( 'F', [ ['F', 'fF[+FL]F[-F][F]'] ], 4, 22.5, 8 )
ls2.set( 'F', [ ['F', 'fF[+F]F[-FL][F]'] ], 4, 30, 10 )
ls3.set( 'F', [ ['F', 'fF[+FL]F[-FL][FL]'] ], 2, 50, 8 )
ls6.set( 'F', [ ['F', 'fF[+FL]F[-FL][FL]'] ], 2, 50, 8 )
ls4.set( 'F', [ ['F', 'fF[+FL]F[-F][FL]'] ], 3, 70, 8 )
ls5.set( 'F', [ ['F', 'fF[+F]F[-F][F]'] ], 4, 10, 15 )


The final scene

Extensions

My extensions include further modifying the parse.py file in order to draw a new L-System that creates an interesting tree. This is the myscene2.py file. I altered the L-System several times to draw trees with and without leaves. These trees can be seen below.




My other extension was to use the newly created tree with leaves in order to create a new scene of trees. This is the myscene3.py file and the image can be seen below.


Back to homepage