The task is to continue working with classes while incorporating last week's project and this week's lab into the assignment. We used lsystem2.py from last week's project and it was modified to use dictionaries instead of just lists. We had to update the set method so that the key can be set. The toString, generateString, write, and read methods were also altererd in order to enable the use of dictionaries within the class. Now the class is able to loop through lists of data and create dictionaries so that the user can access the keys in the dictionary and call the replacement strings. Once the new lsystem3.py file was modified and the zturtle2.py file finished from lab, a new program was written in order to create several trees but it also incorporated buildings made up of graphics objects from week 6's project, into the scene. The final scene can be seen below.
Dictionaries allow the user to access values by using a key, while lists are just collections of values that the user must access individually. Dictionaries are useful for this project because once the key is known the replacement string can be easily accessed instead of having to search and access both from within a list.
My algorithm for creating the final scene was to import both lsystem3.py and zturtle2.py into mysceneP10.py. This allowed me to access and use the methods from within both the files in order to use L-systems in order to create a scene of trees. I was able to use and re-use only three L-systems in order to create an entire scene with trees. Also, the use of dictionaries in lystsem3.py allowed me to easily use L-systems with more than one rule. I also imported city2.py into the scene file in order to use my building functions that I created in week6. In my scene file only a main() funciton was needed because the old processString() function is now included in the lsystem method in zturtle2.py. This made the scene file and code much shorter and more concise than last week.
ls1.set('F', [['F', 'F[+F]F[-F][F]'],['F', 'fF[+FL]F[-F][FL]'] ], 5, 10, 10 )
ls2.set('F', [['F', 'fF[+FL]F[-F][FL]']] , 3, 70, 8)
ls3.set('F', [['F', 'fF[+FL]F[-FL][FL]']] , 2, 50, 8)
For my extensions I augmented the L-systems from ABOP in order to create a bamboo looking forest behind two of my buildings. I used a for loop in order to draw the bamboo shoots with as little code as possible. This new use of L-systems gives the scene and interesting new look. The new scene can be seen below.