Audrey Lyman Project 2
Skip to end of metadata
Go to start of metadata

Audrey Lyman, Spring Semester, CS151, Project 2: A Shape Collection

The main purpose of this task was to learn how to manipulate python functions into creating basic shapes that can be used in a larger function (to create more complex shapes and scenes). Almost every picture of a scene can be broken down into a collection of shapes that came together to create that scene. Therefore, in this project we worked backwards and defined the simple shapes first in order to then piece together a larger scene. 

In lab, we learned how to create basic shapes (blocks and triangles), which can be used for a wide variety of functions. The first task was like a warm up for using functions in other programs: we were asked to call shapes that were defined in other programs from the one we were currently in, and then had to make sure the call worked by creating one of the simple shapes. I also imported multiple python programs to be used in the program: "turtle" and "random."

The second task asked us to expand our "shape library" (shapes.py file) by creating more slightly more complex shapes so that they could be called in later programs. The shapes had to be able to draw anywhere and to any degree of size or scale. My shapes.py file contained shapes that could all (for the most part) be either filled in or outlined. These shapes included: blocks, equilateral and isosceles triangles, parallelograms, circles, and a cross. The parallelogram's parameters included its coordinates, width, length, and one angle of the shape. The second angle was found by (180-angle), and a for loop replicated the code:

for i in range(2):
turtle.forward( width )
turtle.left( 180 - angle )
turtle.forward( length )
turtle.left( angle )

The isosceles triangles are all 90-45-45 degree triangle, with a scale of 5-5-7. The circle merely requested it's coordinates and radius. The cross incorporated a for loops inside of a for loop to eliminate more lines of code:

for i in range(2):
for i in range(2):
turtle.left(90)
turtle.forward(1*scale)
turtle.right(90)
turtle.forward(1*scale)
for i in range(2):
turtle.left(90)
turtle.forward(1*scale)

Screen shots of outlined parallelograms (Figure 1) and filled in isosceles triangles (Figure 2) are shown below (randomly sized, colored, and positioned):


Figure 1Figure 2

I then used these shapes to create simple pictures of houses and trees (both pine and "maple"esque) for the third task, and to use in later tasks for more complex scenes. The maple trees (Figure 3) are simply a block function for the trunk, filled in with brown via the turtle color function, and hundreds of randomly assorted circles for the foliage, which were filled in with green via the same turtle color function. The pine trees (Figure 4) also use the brown block for the trunk, but isosceles triangles make up the rest of the tree. Each triangle is one scale degree above the previous. Figure 5 is of randomly assorted houses, composed of a block function for the main house structure and an equilateral triangle for the roof. The triangle was scaled to the width of the block so that the roof would fit to the house.

   !houses.png|thumbnail,border=1,width=200!Figure 3Figure 4Figure 5

The fourth task asked us to create a scene from somewhere around Colby. My main scene is of the Lorimer Chapel on a winter evening, with snow falling and multiple trees near the building (Figures 6 and 7):

 
Figure 6Figure 7

First, I made the background sky a royal blue color using a very large block filled in with the blue color. The snow was created by using a "for" loop to randomly put hundreds of white circles, called from my shapes.py program file, across a large dimension, as shown in the code below:

for i in range(500*scale):
shapes.circle(random.randint(x-1000*scale, y+1000*scale),
random.randint(x-200*scale, y+500*scale),
random.uniform(.1*scale, 5*scale)
)

shapes.circle calls the circle function I had previously made in the program file called "shapes;" random is a python program where random.randint selects a random integer from the given range (x,y) and random.uniform selects a random float number (including a decimal) from the range. I multiplied my ranges by the scale of the picture in order to keep the circles uniform across any scale. Figure 7 is scaled .5 to Figure 6, but it is not noticeable (except that I decreased the number of circles that had to be made the second time).

The main, largest portion of the chapel is a simple block function, filled in a dark brown. I then made the white doors and pillars to the chapel with more, smaller blocks that were filled in white and outlined black, constructed with two different sets of code so that they would be more defined. Again, all the dimensions were multiplied by the scale in order to manipulate the size of the image.

The roof was then made by using an isosceles triangle filled in with a lighter brown color. The white roof over the entranceway was made with yet another, smaller isosceles triangle. The steeple was made from two filled in blocks on top of each other (the previous y coordinate is the y coordinate for the next block in order to layer shapes on top of each other). I called my cross function from my shapes file to put on top of the chapel, to give it the religious appearance. 

Finally, in order to create the nature scenery around the chapel, I began by making a large, white block under the chapel's coordinates. I then called my tree functions from shapes and used for loops to create multiple trees across the lawn. The maple trees have "snow" on them, which was done by changing approximately a third of the circle's color to white instead of green and limiting their dimensions to higher up on the tree. In Figure 6, the maple trees were called first in the program, which is why they are more prevalent in the scene. However, I changed the order of the for loops in Figure 7 because I preferred this look more. 

The fifth and final task required us to create another Colby scene, which I did of a hallway corner composed of two doors. This picture was difficult because I was looking for the 3D affect via parallelograms. 


Figure 8Figure 9

random.randint(x-200*scale, y+500*scale), random.uniform(.1*scale, 5*scale) )
Throughout these tasks, I learned how to create both basic and complex shapes, and then more complex scenes, using python functions. I undertook many of the extensions, including for loops in the coding (as previously stated), using the random package, incorporating multiple parameters into my shapes, and creating more shapes than necessary. This project really helped me to understand how complex ideas can be achieved via simplistic methods. I got comfortable with many aspects of python, for example: for loops, creating and using functions, comment lines, calling functions from other files by importing packages and programs from elsewhere, creating a (false) 3D affect from basic shapes, and scaling any scene by multiplying every dimension by a scale parameter.

Labels