In this week's project, we learned how to create child class out of the parent class. In addition, we learned how to utilise dictionary, which makes a cleaner reference to the rules of our Lsystem.
The first task is to create a tree class which is a child class of shape class. Then we need to write out a test function to draw the tree L-system out. Basically, L-system.txt file is first reader by lsystem.py file and then turtle interpreter will draw the graph according to l-system.
Required image 1
The second task is to create some shape child class that can draw other basic shapes. I create Diamond, Hexagon, Trapezoid classes.Then I write a test function to draw them out. The graph looks like this:
Required image 2
The third task is to create an indoor scene by using the classes in shape.py. The graph I created looks like this :
Required image 3
The forth task is to create a mosaic image by multiplying a pile image. In mosaic.py function, I first write a pile function to draw a single pile graph out, which is a square with a triangle inside. Then I use double loop functions to draw a mosaic image with Nx*Ny pile graph. For the different color, I use random.choice function to choose one unspecified color from a color string sequence.
The graph I created looks like this:
Required image 4
1. The first extension requires us to draw a non-square mosaic. For this extension, I created a extensionmosaic.py file, in which the basic tile is hexagon. In order to make the mosaic graph, I use math.sqrt() function to represent the square root of 3
2.The second extension requires us to draw some interesting graph by adding new element to turtle interpreter vocabulary. I write "L" and "o" that python would draw leaves and berries(as you can see in the third task).
3. The third extension required us to modify turtle interpreter that tree branches would seem like drop down due to gravity. In my turtle_interpreter.py file, I make some changes to "F" character. If the heading angle is bigger than 40 degree, I will divide the heading by 10, so that the heading angle would be smaller(which seems like drop down by gravity) The example graph is below(you can compare to the first task required picture):
4.For this extension, we need to create an animation. I use time module and time.sleep to pause the graph and turtle.clear() to clear the python just drew.
5. This extension required to make more tiles functions and to mosaic functions. I make two new piles functions in morepilemosaic.py. The graph looks like this
6. The final extension requires us to make a shape class where strings are the result of exciting a function. Then I created a class that will generate the string follow the argument I pass to that class. I created a polygon class. In polygon, I add a new parameter "sides". The default value of sides is 3. Then I use loop function to created a L-system string by the number of sides. (you can see polygon class in shapes.py file)