Will Pepi Project 2 Write Up

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 4.0

For this assignment, I first created a library of shapes with variable location and size values, so that I could call on them to create two scenes from a Maine coastline. I first created two simple shapes and made sure they were drawn correctly no matter what location, orientation, or size values I assigned them. I then created a sailboat shape and a shell shape to actually use in my scenes. For my scenes, I first created a simple, colorless ocean with a boat on the surface, and shells on the sea floor. For my second scene, I introduced both color and waves. 

Task 1

The name of the file with all of my shapes is called "shapelib" so for task one I just wrote " import shapelib" in addition to "import turtle" at the top of a separate file called "Main" so that I could call functions from shapelib at any point in my main file. I then made a function called "coast1" in my main file and called some of the shapes from my shapelib to make sure it worked.

Task 2

For task 2, I created a triangle and a hexagon in my shapelib. They used a "goto" function from my shapelib which made the location at which the shapes were drawn variable. Instead of actual distance values, I used the variable "length" so that the size of the shapes is also variable. In the function definitions, this looked like "def triangle( x, y, length):"

Task 3

For task 3 I created two new, more complicated shapes that would ultimately be used in my Maine coastline scenes. For the sailboat I used the parameters: x, y and scale. I used the triangle function I defined earlier as the sail, and because the triangle function already had parameters, I had to call it this way" triangle( x-65*scale, y-100*scale, 125*scale ) so that the triangle would draw correctly for different boat scales. Otherwise, the code for the boat used only turtle functions and a "goto" function. For the shell, I essentially drew a rectangle from the same starting point over and over again, rotating it by a degree of 10 each time so that the spiral shell shape resulted. 

Task 4

For task 4 all I had to do was draw two lines using the "goto" and "turtle" functions and then call my sailboat and shell functions.

Task 5

For task 5 I called my boat function to draw a sailboat but I used a larger scaled, and I used the function "turtle.left(10)" to rotate the turtle and subsequently the entire boat so it looks like its riding a wave. To make waves I used a "for" "in" function in order to call the code for a right triangle 40 times as pictured below.
Then, in order to fill in the triangles I put the code "turtle.begin_fill()" followed by "turtle.color( 'blue' )" before the above code, and "turtle.end_fill()" after the above code. Then in order to fill in the rest of the sea, I created a large rectangle and filled it in the same way, by sandwiching the code for the shape I wanted to fill with the turtle functions. I then changed the color to brown and called my shells function to draw several shells.

I learned how to creat a library of function and then call them in another file, which will allow my code to be much more organzied in the future. I also learned how to fill shapes and how to use the "for in" function which is very powerful.