Kevin Bennett

Spring 2010

For this lab, I used the 3D Turtle module to make 3D shapes and scenes.

The first task was to make some 3D shapes. I made eight: a cube, a triangular prism, a pentagonal prism, a hexagonal prism, an octagonal prism, a sphere, a pyramid, and a filled triangular prism. The shapes were fairly easy to make. The sphere gave me some difficulty because I at first did not realize the starting position of the turtle when drawing a circle, and the pyramid and filled triangular prism just took longer because I had to mentally visualize each turn and position. Here are my shapes in different styles (sans filled triangular prism, which will appear later). The sphere could only be drawn in the normal style because it was drawn by calling turtle.circle, which does not use the forward method in the Interpreter class.

The next task was to create a 3D scene. Mine is a man in a storm, with an umbrella, next to some trees. I initially had some trouble because the ground would appear on top of the other shapes, but I could correct this somewhat by making the ground rectangle go further back in the z direction, pushing the center (which is apparently what determines what shape is drawn on top) backwards. I used the systemZ code for both of my trees, changing the angle and adding apples for one (for this, I changed apples from circles to spheres in the interpreter). The man's head is a sphere, and his torso and legs are two filled triangular prisms. His umbrella is made with two partially-drawn spheres, rotated appropriately. The rain is randomly-placed vertical blue lines.

The third task was to do some extension. I chose to create a pyramid more reminiscent of the step pyramid of Djoser using recursion. In the cube class, I created a method named blockPyramid, which takes an xpos, a ypos, a zpos, and a number of layers as input. The code for my pyramid would be more complicated to describe than it is to read, so here it is:

    def blockPyramid( self, xpos, ypos, zpos, layers ):
        if layers == 0:
            return
        self.draw( xpos=xpos, ypos=ypos, zpos=zpos, orientation=0, roll=0, pitch=0 )
        self.blockPyramid( xpos=xpos + self.distance*0.5, ypos=ypos - self.distance, zpos=zpos + self.distance*0.5, layers=layers - 1 )
        self.blockPyramid( xpos=xpos + self.distance*0.5, ypos=ypos - self.distance, zpos=zpos - self.distance*0.5, layers=layers - 1 )
        self.blockPyramid( xpos=xpos - self.distance*0.5, ypos=ypos - self.distance, zpos=zpos - self.distance*0.5, layers=layers - 1 )
        self.blockPyramid( xpos=xpos - self.distance*0.5, ypos=ypos - self.distance, zpos=zpos + self.distance*0.5, layers=layers - 1 )

This is it with three and four layers. A issue that I encountered was that once you get past 4 layers, it starts to take a long time to draw because it draws so many redundant cubes in the interior of the pyramid.

Then, at the end, I realized my hexagonal prism looks somewhat like a snare drum so I made this picture:

I also wanted to do something that incorporated my awesome snowflake from lab 10 in 3D form, but I didn't have time.

Ultimately, everything that I know about 3D turtle and coding, I learned during this lab, so I'd say I learned something. I also dealt with recursion somewhat and became more comfortable with that.