Due: Tuesday, February 7, 2017, 11:59 pm
The purpose of this project is to give you chance to break down simple problems (such as drawing a logo) into precise steps that solve the problem (draw the logo). In computer science speak, you will be developing algorithms. In this case you will write your algorithms as sequences of Python turtle commands that make the turtle draw complicated shapes for you.
Create a file called shapeA.py in your Project1
directory. It should follow the same basic format as
simple_turtle.py, so make sure the first and last lines in
shapeA.py are the same as the first and last lines in
simple_turtle.py. Between those lines, put the turtle
commands to draw the shape you just invented. Run the program (i.e.
python shapeA.py in the terminal) and take a picture
of the shape (i.e. Shift-Cmd-4).
Include a picture of this shape in your write-up. This is required image 1
Repeat your process for a second shape, putting its code in a file named shapeB.py.
Include a picture of the new shape in your write-up. This is required image 2.
def triangle(): forward( 100 ) left( 120 ) forward( 100 ) left( 120 ) forward( 100 ) left( 120 )
Note how the commands that make up the function are all tabbed in the same amount relative to the function definition. That is how you tell Python those commands are part of the function triangle. In Python the visual indentation of the text has the semantic meaning that the indented text is part of the function labeled as triangle. Not all programming languages give semantic meaning to the visual organization of the code, but Python does. That means that the way Python code looks also has something to do with how it works.
Your shapeA and shapeB functions should draw the shapeA and shapeB shapes you defined in the prior step. You can copy and paste that code into the functions, tabbing in the code appropriately.
def shapeC(): shapeA() forward( 100 ) shapeB() shapeC() raw_input('Enter to continue')
python shapes.pyin the Terminal). If it doesn't work, then carefully read any error message. It should direct you to the line of the file that failed to work. Some common errors include the following.
Note that Python considers tabs and white space to be different things, which is sometimes hard to debug because all of your code looks correct. If you think your code is correct, then select all of your code (cmd-A) and then choose Text::Entab in TextWrangler to convert all of your white space to tabs or Text::Detab to convert all of your white space to spaces. That will generally correct the problem if the error is mis-matched white space.
It would be better to have a triangle that could be drawn many different sizes. In other words, instead of using a raw, or hard-coded number to indicate the forward distance, it would be better to have the distance be adjustable. In programming terminology, this means we would like to use a variable for the distance instead of a hard-coded number. You can create parameters for functions that allow you to pass information into a function. In the function definition, you put a list of variable names inside the parentheses. You can then use the parameter variables within the function.
When you call a function with parameters, you put the value of the parameters in the parentheses. For example, the following code defines a triangle and then calls it with two different values.
def triangle( distance ): forward( distance ) left( 120 ) forward( distance ) left( 120 ) forward( distance ) left( 120 ) triangle( 50 ) triangle( 100 )
triangle() triangle( 4, 3 )
Include a picture of the new shape in your write-up. This is required image 3.
Each assignment will have a set of suggested extensions. The required tasks constitute about 73% of the assignment, and if you do only the required tasks, do them well, and have a well-written write-up you will earn a B. To earn a higher grade, you need to undertake one or more extensions. The difficulty and quality of the extension or extensions will determine your final grade for the assignment. One complex extension, done well, or 2-3 simple extensions are typical.
The following are a few suggestions on things you can do as extensions to this assignment. You are free to choose other extensions.
You will turn in your code by putting it in a directory in the Courses server. On the Courses server, you should have access to a directory called CS151, and within that, a directory with your user name. Within this directory is a directory named private. Files that you put into that private directory you can edit, read, and write, and the professor can edit, read, and write, but no one else. To hand in your code and other materials, you will create a new directory, such as Project1, and then copy your code into the project directory for that week. Note: This directory will not be available during lab, but will become available during the week before the projects are due.
As with the Personal server, there are two ways to mount the appropriate directory.
You can mount the Colby fileserver root directory by going to the Finder and typing cmd-K, or selecting 'Connect To Server...' from the Go menu. It will bring up a dialog box, into which you want to enter the following.
Then click on the CS151 directory, and then your hand-in directory (it will have your username as its name).
You can mount your personal directory explicitly using the the following path in the 'Connect To Server...' dialog.
Turn in your code by copying your entire Project1 directory from your Personal server to the Courses server. The easiest way to do this is to drag and drop the folder from one Finder (one open to Personal) to another (one open to Courses).
In lab, you made a new wiki page for your
assignment. Put the label
cs151s17project1 in the label
field on the bottom of the page. But give the page a meaningful title
(e.g. Ying's Project 1).
In general, your intended audience for your write-up is your peers not in the class. Your goal should be to be able to use it to explain to friends what you accomplished in this project and to give them a sense of how you did it. Follow the outline below.
© 2017 Ying Li. Page last modified: .