CSC111 Homework 3

From CSclasswiki
Jump to: navigation, search
Happy Valentine's Day!

Homework 3 Due Feb 16 by Midnight

Place copies of each program, named with your first initial, last name, and HW3a, HW3b, and the extension '.py' into the class dropbox, by midnight on February 16. Also hand in copies of the new, altered photos, with the same file name as for the python program, but with the extension of '.jpg' (e.g., DThiebautHW3a.jpg).

Problem #1

What you have to do:

CSC111 rose.jpg + CSC111 heart.jpg = CSC111 roseAndHeartsSimple.jpg

Take the image of the heart and copy it over the image of the rose, in the four corners.


  • There are different ways to go about this problem. You have to copy the hear in four places. Having four separate functions that specialize each in one corner is one way to do it. Having only one function that can be told where to place the heart and calling that function four times passing it different locations is another way. Use the method that works best and makes better sense to you.
  • Do one thing at a time, and do not move on to the next until whatever you have written works well.


  • You should have one function called main() which does all the work, and calling main() from the console area in JES (scratchpad area) will display the resulting rose with hearts at the four corners.
  • You should document your code.
    • Your program should start with a header including the name of the program, your name, the date and a description of what your program does.
    • Each function should have a one-line comment following the def statement explaining what the function does
    • Include additional comments where the code becomes harder to read without comments. (This is very subjective, and you will learn how to best add comments with time, by looking at examples and at your own programs.)

Problem #2

CSC111 rose.jpg + CSC111 heart.jpg = CSC111 roseAndHearts.jpg

This time you are asked to flip the heart picture as you copy it over the rose picture so that it always points inward.

Mystery Function

The following function may be helpful. To figure out what it does, first study its code, then run it on a picture of your choice.

def mysteryFunction( pict ):
  height = getHeight( pict )
  for x in range( 1, getWidth( pict )+1 ):
    for y in range( 1, height/2 + 1 ):
      topPixel    = getPixel( pict, x, y )
      bottomPixel = getPixel( pict, x, height-y+1 )
      topColor    = getColor( topPixel )
      bottomColor = getColor (bottomPixel )
      setColor( topPixel, bottomColor )
      setColor( bottomPixel, topColor )


The requirements are the same as for Problem #1.

Lab Solutions

Make sure you study in detail the solutions for Lab 3, available here.