CS 107: Pictures and Sounds: Programming with Multimedia

Kalamazoo College

Spring 2008

Problem Set from Chapter 4


  1. Problems 4.2, 4.3.

  2. Problem 3.2. (Yes, look back at this problem from chapter 3.)

  3. Consider the following code to scale a picture to 1/4 its original size. Is there a difference between this code and the code that was actually in the Mini-Lab? Which pixels do each of them use to get the color to copy into the new picture? Are they the same?
      def quarter(picture):
        newWidth = getWidth(picture)/2
        newHeight = getHeight(picture)/2
        canvas = makeEmptyPicture(newWidth, newHeight)
        for x in range(2, getWidth(picture)+1, 2):
          for y in range(2, getHeight(picture)+1, 2):
            p = getPixel(picture,x,y)
            c = getColor(p)
            setColor(getPixel(canvas, x/2, y/2),c)
        return canvas