In this lab, we were using multi rule lsystems to make scenes. We also wrote our own lsystems and put them into scenes using different numbers of iterations.
The first thing I had to do was create a _str_ method in the lsystem class which would take the base and the rules and format them into strings that we are used to seeing with "base ->" followed by the base string and "rules ->" followed by the rules. To do this, I used the getBase() method to return the base which I preceded with a string "base ->" and followed it with a "\n" to go to the next line. Next, I looped over all the rules. I added the rules to the string so that it would say "rule" followed by the first element, then an "->" then the rule itself followed by a "\n" to go onto the next line. Next, to complete the task, I first had to edit my interpreter and lsystem files. In the interpreter, I added elif statements to account for new characters such as <, >, g, y, r, and L. After testing to make sure my new additions to the interpreter were working correctly, I went on to make my first scene. To do this, I used the main() method from my interpreter file. I first set the turtle to be facing up, then drew three different trees based on lsystems in three different places. When finished, this file looked like this:
After making that scene, I went on to the next task which was to make a forest out of different lsystem trees. To do this, I used a loop and the random package. I created a for loop that each time through the loop would move the turtle to a random location using the random.randint() function. After moving, it built a tree at that location with a random distance to make the trees different random sizes. After that was finished, that forrest looked like this:
For my task3.py file, I made some changes to specific lsystems that were in ABOP. The original lsystems that I used were systemFL and systemDL. I changed them to be:
rule X F-[[X[F+]]+X]+F[+F][+FX]-X<gL>
rule F FF
rule P I+[P+O]-[<gL>]I+[<gL>][PO]+PO
rule I FS[+<gL>][+F][-<gL>]FS
rule S SFS
rule O <y[++F][+F][F][F][-F]>
after making these lsystems, I used my lsystem class to make lsystems with 3, 5, and 7 iterations of each one. After, I made a scene with these lsystems. That scene looked like this:
For my extensions, in addition to adding an "L" case in my interpreter to make green leaves, I used math and loops in my second scene to make a forest out of a small amount of code. Instead of making many different individual calls to interpreter.main(), I was able to loop over three calls fifteen times to place trees in many different random locations with random sizes as well.
Overall, I learned how much small changes in lsystems can make a big different in the resulting pictures. I also learned how simple it is to add more and more conditions to the interpreter to make certain letters in an lsystem do specific things.