Project 9 (Philip Prosapio)
Skip to end of metadata
Go to start of metadata

Philip Prosapio
Spring 2010

Note- My code for this lab is under pwprosap account on the academic server.
Also, all my code should be indented correctly but sometimes this website will shift it a tiny bit.


This weeks lab and project had us making unique L-system trees and shapes by using classes and the inheritance property. We first had to make a Tree class that would use a L-system where the trees were more randomly generated due to the L-system being a multi-rule. We then had to make some extra shape classes that also inherited the original Shape class. Then I had to make an indoor scene that utilized my Tree class and my different shape classes. For the final task we needed to make a Mosaic of tiles that were created out of a combination of the square class and other shape classes.

Solution to Tasks

1) For the first task, I needed to make a file that made a Tree class. In order or this tree to make every tree different, we needed to go back to our read method in and change some code.

elif words[0] == 'rule':

  1. add the rule to the lsystem using the function addRule

The last line is what we needed to change, by changing it to (words[1:]) the colon would make it so it could read any one of the multiple rules. This picture is attached and labelled picture1lab9.png .

2) For task two I needed to create new shape classes that were based off of the original Shape class. A new feature we added onto these classes was the ability to fill the shapes by just adding curly brackets.

Shape._init_(self, distance = distance, color = color, angle = 90,
istring = '

Unknown macro: {FF+F+F-FF+F+FFF}

Sorry that this unknown macro thing popped up.

As you can see, in the last part of this code, the istring has curly brackets surrounding it so that the object would be filled. If I didn't include the curly brackets, then the object wouldn't be filled. The picture of my different shapes is attached and named picture2lab9.png .

3) For the third task I created an indoor scene that was made completely out of the shapes I had created for this project. I added in trees and many of my different objects, but even my little human is made out of the L block that I made as one of my shapes.

  1. These two L's will make my persons body.
    l = multishapes.L2( distance = 50, color='purple')
    l.draw(-10, -70, scale = .1, orientation = 180)
    l = multishapes.L2( distance = 50, color='purple')
    l.draw(-20, -50, scale = .1)

By making two mirror L blocks I placed them together to make a rectangle for the humans body. And the code above shows how I called the objects to be drawn. With the different x and y locations, scale, orientation and distance. The picture of my scene is attached and labelled picture3lab9.png .

4) For the fourth and final task, I needed to make a tile and then place multiple together to create a mosaic. The tile was just a mixture of different shapes that I had created for this project, all bounded by a square. But the interesting part of this code is how I created the mosaic.

  1. This funtion will make a mosiac out of my tiles.
    def mosaic(x, y, scale, Nx, Ny):
    for i in range(Nx):
    for j in range(Ny):
    tile(x+(1.0*scale)*scale*i, y+(1.0*scale)*scale*j, scale)

By using a 'for' loop within a 'for' loop, I was able to make a mosaic that was Nx tiles by Ny tiles that were all scaled to a certain value. The code that I added to the x and y value tells each new tile to be placed the correct distance to the right or above the previous tile. The picture of my 5x4 mosaic is attached and labelled picture4lab9.png .


Extension 1- For the first extension, I fulfilled the extension that requires me to create a new L-system and add characters to the vocabulary that do interesting things. I created a new L-system and added in two new characters, one that changes the color of the line to a random color, and the other that changes the width to a random integer between two set values.

  1. else if c is 'E'
    elif c == 'E':
  2. changes the color to a random color
    turtle.color(random.uniform(0.0,1.0), random.uniform(0.0,1.0),
    random.uniform(0.0,1.0) )
  3. else if c is 'W'
    elif c == 'W':
  4. changes the color to a random color
    turtle.width(random.randint(1, 5))

So each new line in my L-system fractal randomly changes color and width. This picture is attached and labelled picture5lab9.png .

Extension 2- For extension 2, I made another tile function and mixed it with my other tile function into a new mosaic. The new tile was just a compilation of some of my shapes and my L-system fractal from last extension. For this extension I needed to change what my x and y offsets so that every time through the 'for' loops the two different tiles would move to there correct location

for i in range(Nx):
for j in range(Ny):
tile2(x+(1.0*scale)scale*i, y+(1.0*scale)scale*(2*j+1), scale)

The (2*j+1) that I added in makes it so that this tile will jump to every other line and make a complete line of tiles. The picture of my extension mosaic is attached a named picture6lab9.png .

What I Learned
This lab helped enforce the concept of inheritance that we are working on in lectures now. Making the multiple different classes that all inherited from the original Shape class made the concept of inheritance more clear.

Attached Pictures