Danqing's project 8
Skip to end of metadata
Go to start of metadata

In this lab we learned how to use 'class' object to improve our 'lsystem' functions. Class object is a good way to make our code more simple. 

For the first required image, I draw a forest with lsystem and class.

I used lsystem provided on the website, and arrange them in 3 rows and 8 columns. I used random location and color to make this forest more interesting. I will discuss more about the code in extension part. 
For the second required image, I used class to show 2 new lsystems. Their number of iteration is from 1-3, since larger iteration number will make the image too big. 

One is what I created last week, and the other is from the ABOP book. 


In required image 1, I used random object to make my forest more interesting. My code is shown below.

for j in range(3):

        for i in range(8):


            if rf==0:



            elif rf==1:



            elif rf==2:



            elif rf==3:








            for n in range( r.randint(20, 40)):




I learned from the provided class test code to give my trees random position, and I used random to determine what kind of tree will be drawn. I found that if a systemCL.txt lsystem is drawn with 4 iteration it will be too big, so I modified the random code. 

Otherwise, I add berries to my lsystem. The 'elif' function is just like what I did last week, except that I removed the random color methods so that I can determine the color of berries in lsystems. I also add another color purple to TurtleInterpreter class. 

Then I add _str_ method to Lsystem class. The result is shown above. 
I also learned to use the 'write' method in turtle object and write the lsystem nearby the image.

Well, the image is not about base string, but with a iteration number 3, since in this lsystem image of base string is nothing...

I create 2 new shapes in my TurtleInterpreter function. One is T for a triangle, and the other is V for a star. I created a new lsystem with star shapes and it is shown above. The iteration number is from 1 to 3. 

In this week's lab, I understand that class is another good way to access complex function with simple code. Now I can build my own class for use.