# A function to halve a pictures with a size of 400x400 and place it into a new picture of size 200x200 

def halfAndCopy():

  # Ask for the media folder
  setMediaPath()

  # Get the square sized flower picture and show it
  sourceFile = 'lionfish.jpg' #set the source file name
  sourceFullName = getMediaPath(sourceFile) #set the source file location
  print sourceFullName #print the source file location
  sourcePict = makePicture(sourceFullName) #make a picture from the source file
  show(sourcePict) #show that picture

  # Get an empty 400x200 picture and show it
  targetPict = makeEmptyPicture(200,200) #create the empty picture to build the new picture in
  show(targetPict) #show the empty picture

  # Scale the picture and copy into left side of the empty picture
  sourceX = 1 #set the source picture X co-ordinate to read from.
  for targetX in range(1, getWidth(sourcePict)/2+1): #loop for half of the columns in the source picture
    sourceY = 1 #set the source picture Y co-ordinate to read from.
    for targetY in range(1, getHeight(sourcePict)/2+1): #loop for half of the rows in the source picture
      color = getColor(getPixel(sourcePict, sourceX, sourceY)) #get the color of the source picture pixel at the X and Y co-ordinates
      setColor(getPixel(targetPict, targetX, targetY), color) #set the color of the pixel in the target picture
      sourceY = sourceY + 2 #increment the source Y co-ordinate to read 2 rows down
    sourceX = sourceX + 2 #increment the source X co-ordinate to read 2 columns across

    repaint(targetPict) #repaint the new picture every time a new column is created

  return targetPict #return the whole picture when finished
