Sam Arthur's Project 8 - Unique Trees and Shapes
Skip to end of metadata
Go to start of metadata

In project 8, we used classes with inheritance to create objects that we could use in a scene and in mosaics. The goal of this project is to learn how to use inheritance by creating different shape classes.

In the first part, I created a Tree shape class, which was similar to the Square and Triangle classes, except it created objects with variation like randomly oriented branches using an L-system. Since the tree class is a shape, I put in shapes.Shape in the argument so that it would have the same methods as the parent, Shape. I added methods setIterations and read so that the Tree object could have a variable number of iterations and could read a file to create an L-system. The draw method overrode the Shape class' method draw, so that it uses the Lsystem to build the string and assigns the string to self.string, and then calls for Shape's draw function. With this new class I made a test function, main2(), which draws 3 trees from the Tree class. 

Image 1

Image 1 shows the result of running the test function that drew three trees from the tree class. The trees are different because they used L-systems that had multiple replacements for one rule.

In the second part in the file, I created three other shape child classes. I created a compass needle shape by filling only one part of object. I also created hexagon and octagon shapes which were only partially filled.

Code Snippet 1

Code Snippet 1 shows the use of a string in the hexagon class that would directly be used by the turtle interpreter. It contains brackets '{}' that were only surrounding part of the 'F' and '+', which meant that only half of the hexagon would be filled.

Image 2

Image 2 shows the result of running the test function which is a result of using the draw() method on each shape class.

In a new file,, I imported the shapes from the file. I used these shapes to create an indoor scene with two vases that contain plants and a picture that contains a hexagon, octagon, compass and two trees.

Image 3

Image 3 shows the result of running the scene function.

In the fourth part of the project, I created a tile function which draws a tile design at x,y with a side length equal to scale. In the same file, I created a mosaic, which used a nested for loop to create an array of tiles Nx by Ny at x,y with each tile having a length equal to the scale.

Image 4

Image 4 shows the result of running the mosaic function at -300,-200 with length equal to 50, dx=5 and dy=4. The result is a 5 by 4 pattern of tiles.

As an extension, I created a mosaic with triangle-shaped tiles. First, I added a new function, triangletile(), which would create a triangle shaped tile with a slightly different pattern inside. Then I added another function, trianglemosaic() which created a mosaic with tiles of the triangles created in the triangletile() function. It used two nested for loops. The first set of for loops created the even rows of triangles. The second nested for loop created the odd rows of triangles in the mosaic. It used an if statement so that only the odd Nx and Nys would draw a triangle tile.

Code Snippet 2

Code Snippet 2 shows the two sets of for loops that I used to create the pattern. I had to scale the x and y parts y different factors (0.5,root3 and (root3)/2)) in order to create an even pattern of triangles.

Image 5

Image 5 shows the extension that I undertook, a mosaic of triangle tiles with Dx=8 and Dy=12.

I learned how to use child classes, which would inherit the methods from the parent class. I also learned how to make dynamic L-systems as done in the "tree" class. I found it interesting that I could create mosaics using the objects that I created.