# a function that returns a "blank" picture object, 
# height pixels tall and width pixels wide 
def initializeCollage(height, width):
  ep = makeEmptyPicture(width, height)
  return ep
  # or
  # return makeEmptyPicture(width, height)


# a function that saves the collage as a jpeg file
def saveCollage(collage, filename):
  writePictureTo(collage, filename)


# uses the pixels of the given picture to put a scaled 
# (1.0 = same saze as original) version of the picture 
# on the collage, with top left corner at column x, row y. 
def addPictureToCollage(picture, collage, x, y, scaleFactor):
  # calculate the width of the picture *in* the collage
  scaledWidth = int(getWidth(picture) * scaleFactor)
  scaledHeight = int(getHeight(picture) * scaleFactor)

  # get the collage width/heigh
  collageWidth = getWidth(collage)
  collageHeight = getHeight(collage)

  # the next two tests could (should) be combined into one.
  if x < 1 or y < 1:
     print "Error: Picture doesn't fit in collage!"
     return

  if x+scaledWidth > collageWidth or y+scaledHeight > collageHeight:
     print "Error: Picture doesn't fit  in collage!"
     return

  # fill all the pixels of the picture *in* the collage (based on scaling)
  for col in range(scaledWidth):
    for row in range(scaledHeight):
      src = getPixel(picture, int(col/scaleFactor)+1, int(row/scaleFactor)+1)
      dst = getPixel(collage, x+col, y+row)
      setColor(dst, getColor(src))


# a function that returns a new picture object corresponding 
# to the original image rotated 90 degrees to the right 
def rotatePictureClockwise(picture):
  # broke this down too simplify our thinking.
  width = getWidth(picture)
  height = getHeight(picture)
  newWidth = height
  newHeight = width
  newPicture = makeEmptyPicture(newWidth, newHeight)

  # col and row is the original column and row
  for col in range(width):
    for row in range(height):
      src = getPixel(picture, col+1, row+1)

      # the new row is the old column
      # the new column is the new width minus the old row
      # (if this is confusing draw it out on a piece of paper)
      dst = getPixel(newPicture, newWidth - row, col+1)
      setColor(dst, getColor(src))

  return newPicture