• 2016
• 2015
• November
• October
• September
• May
• April
• March
• 2014
• 2013
• 2012
• 2011

# Blog 2015 November Blog from November, 2015

Yusheng's project 9

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

Extension:

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)

Yusheng's Project 7

In this project, we are getting our first exposure to L-system and properly-formatted text files. One interesting aspect of L-systems was iterations, which allowed us to draw complicated fractals and realistic plants.

The first task is to create an abstract image with three l-systems. All l-systems graphs shown. Through creating a new function that allow my shape to be drawn in any (x,y) with any scale, color, and pen width. The result are shown as image 1.

required image 1

The second task is to create a grid of nine trees, where the number of iteration increased left to right and the angle changed from top to bottom. In this task, I used  two different loops. I also put three parameters to the function, which define the location I draw the graph and the scale of graph.

For the extension part, I created a season theme throughout the grid. For top to bottom, three lines of trees represent the spring, auto and winter. In spring, the brach of tree has leaves. In automn, the tree has fruit on each of its brach and In winter, all leaves and fruits fall off.

required image 2

The third task is to use different l-systems graphs to create a simple scene. The "sun" on the right of the sky is created by myself and I found the "snow" and two kinds of "tree" l-system in ABOP website.

required image 3

Extension:

1.I imported l-systems to my project 2 image.

2. I add 5 parameters to the show function in abstract.py file, in which filename defines the name of the file I inputed, d defines the scale of the graph, a defines the angle, x and y defines the position of graph, color defines the color string.

3. I created a season theme throughout the grid.

4. I added x, y and scale parameters to the function in task 2. you can see in the right corner, I draw the grid with smaller scale.

5. I created three different l-system graph in task 1 and the sun in task3