CS1315 Summer 2007 - Homework 1, Turtles (2% of your final grade)
Please Fill In the Information Below
Name
GTID
GTMail Address @mail.gatech.edu
Section
Instructor Cedric Stallworth
TA
Collaboration Statement
(select the one that applies to your work on this assignment, delete the other one)
"I worked on the homework assignment alone, using only course materials."
"I worked on this homework with
,
used solutions or partial solutions provided by
,
and referred to
.”
Keep in mind that you are only allowed to work with other students currently in CS1315. Do give
credit though using the collaboration statement. The professors and the current TA's should be
treated as course material and need not be listed in the collaboration statement.
If you seek help from someone outside of the course (ie. Not the professor or TA), you MUST
receive approval from the professor.
If you do not have a collaboration statement on your assignment, you will receive a grade of zero
for this assignment.
Homework Turn In Policy
For the chance to receive full credit, turn this homework in as HW1 before Friday, May 25, 2007
at 11:45PM.
For a chance to receive 80% credit, turn this homework in as HW1Late between Friday, May 25,
2007 at 11:45PM and Saturday, May 26 at 11:45PM. Also email your TA to notify him/her that
your homework was late.
Anything turned in after Saturday, May 26 at 11:45PM will NOT be accepted and a grade of zero
will be given for this assignment.
Concepts
In your own words, explain the parameters of each function. Then tell what the functions do with
respect to turtles.
1) makeWorld (w, h) : w is h is
2) makeTurtle( w ) : w is
3) turn( a ): a is
4) turnLeft ( ):
5) turnRight ( ):
6) forward( p ): p is
7) backward( p ): p is
8) moveTo( x, y ): x is y is
9) turnToFace( x, y): x is y is
10) penUp( ):
11) penDown( ):
12) drop( p ): p is
13) setShellColor( c ): c is
14) setBodyColor( c ): c is
15) setPenColor( c ): c is
16) getXPos ( ):
17) getYPos( ):
18) setName( n ): n is
19) getName( ):
20) getHeading( )
21) setHeading(x , y): x is y is
22) getTurtleList( w ): w is
In your own words, explain what the following commands do in Jython.
1) def
2) for
3) if
4) print
5) import time
6) time.sleep
7) #
8) setMediaPath( )
Quick Overview
Your assignment is to write a simple program that posterizes a picture that you pass it. Read on
for more details....
Details, Details
1. Your function should be named posterizeMe (case sensitive) and your file should be
named hw1.py
2. Your function should take in a picture as an input
3. For every pixel in the picture: (in this order!)
If the original green value of the pixel is greater than or equal to 100, set the new green
value of the pixel to 255
If the original green value of the pixel is less than 100, swap the values of the red and
green for that pixel (e.g., make the new green equal to the old red, and the new red equal
to the old green)
If the original red value of the pixel is greater than 70 and less than or equal to 150, set
the new red value of the pixel to the original blue value
If the original blue value is greater than 109, set the new blue value to 109.
If the original blue value is less than or equal to 109, set the new red value to the
absolute value (hint: function abs) of the original green value minus the original red value.
Hint: the first line of your program should look like this:
def posterizeMe(picture):
A few Questions.....
Once you have finished testing your code and see that it works, copy the following lines of code
and paste them at the end of your python file. Answer the questions in the space after the #.
These are just comments and won't affect the way your code runs.
# If your picture had a pixel color pure red (RGB = 255,0,0)
# and another pure blue (0,0,255),
# what value will be in those pixels
# after your function runs?
#
#
# It is important to store the original red, green, and blue
# values before you start. Why?
#
#
# What sorts of keywords usually signify that an indention is coming up. Give 3 examples.
#
#
# What does it mean to pass a parameter into a function?
#
#
How the TA will grade
Your TA, after loading your code into JES will type the following:
>>> file = pickAFile()
>>> pic = makePicture(file)
>>> posterizeMe(pic)
Then your ta will show the picture again and observe the changes. Your ta will
also read over the answers to your questions.
At last extra credit
2 Points extra credit: run this function on a picture of your choosing and save the result to
your computer and then post it here with the filename being your-prismID.jpg (for
example: gtg184q.jpg). Hint: look up the keyword writePictureTo to find out how to save a
picture from JES. Also remember to take out the writePictureTo line before you turn the
assigment in. title.
Questions?
Links to this Page
Assignments last edited on 28 November 2006 at 8:33 pm by lawn-128-
61-116-220.lawn.gatech.edu
Assignments - Spring 2007 last edited on 15 April 2007 at 9:15 am by
user-11210g9.dsl.mindspring.com