# A function to halve a given picture of 400x400 size and center it into a new picture with the same size

def halfAndCenter(sourcePict):

  setMediaPath() # Ask for the media folder
  
  sourcePict = makePicture(sourcePict)# make the original picture from the file

  # Get an empty 400x200 picture and show it
  targetPict = makeEmptyPicture(400,400) #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 all pixel columns in sourcePict
    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 all pixel rows in sourcePict
      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 + getWidth(sourcePict)/4, targetY + getHeight(sourcePict)/4), 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

  #Save the final picture to a file
  writePictureTo(targetPict, "modifiedPic.jpg")
