def collage(picture):
  h=getHeight(picture)
  w=getWidth(picture)
  newPic=makePicture(pickAFile())
  xoff=requestInteger("X offset")
  yoff=requestInteger("Y offset")
  W=getWidth(newPic)
  H=getHeight(newPic)
  for x in range (1,W):
    for y in range(1,H):
      if(x+xoff<w and y+yoff<h):
        pixel1=getPixel(newPic,x,y)
        clr=getColor(pixel1)
        pixel2=getPixel(picture,x+xoff,y+yoff)
        setColor(pixel2,clr)


def mirror3(pic):
  pxl=getPixels(pic)
  w=getWidth(pic)
  h=getHeight (pic)
  for x in range (1,w/2):
    for y in range (1,h/2):
      clr=getColor(getPixel(pic,x,y))
      newPxl=getPixel(pic,w-x,h-y)
      setColor(newPxl,clr)

def mirror2(pic):
  pxl=getPixels(pic)
  w=getWidth(pic)
  h=getHeight (pic)
  for x in range (1,w/2):
    for y in range (1,h):
      clr=getColor(getPixel(pic,x,y))
      newPxl=getPixel(pic,w-x,y)
      setColor(newPxl,clr)


def mirror(pic):
  pxl=getPixels(pic)
  w=getWidth(pic)
  h=getHeight (pic)
  for x in range (1,w):
    for y in range (1,h/2):
      clr=getColor(getPixel(pic,x,y))
      newPxl=getPixel(pic,x,h-y)
      setColor(newPxl,clr)

def chromakey (background):
  bgh=getHeight(background)
  bgw=getWidth (background)
  greenPic=makePicture (pickAFile())
  xoff=requestInteger("X offset")
  yoff=requestInteger ("Y offset")
  for p in getPixels (greenPic):
    r=getRed (p)
    g=getGreen (p)
    b=getBlue (p)
  if(r+b>g):
    x=getX(p)
    y=getY(p)
    if (y+yoff<bgh) and (x+xoff<bgw):
      newColor=getColor(p)
      bgPixel=getPixel (bg,x+xoff,y+yoff)
      setColor (bgPixel,newColor)


def sketchlike (picture):
  pixels=getPixels (picture)
  for pixel in pixels:
    r=getRed (pixel)
    g=getGreen (pixel)
    b=getBlue (pixel)
    greyness=(r+g+b)/3
    whiteness=makeColor (255,255,255)
    blackness=makeColor (0,0,0)
    if (greyness<127.5):
      setColor (pixel,whiteness)
    else:
      setColor (pixel,blackness)


def nored (picture):
 pixels=getPixels (picture)
 for pixel in pixels:
  setRed(pixel,0)


def noblue (picture):
 pixels=getPixels (picture)
 for pixel in pixels:
  setBlue(pixel,0)


def nogreen (picture):
 pixels=getPixels (picture)
 for pixel in pixels:
  setGreen(pixel,0)



def greenish (picture):
 pixels=getPixels (picture)
 for pixel in pixels:
    r=getRed (pixel)
    g=getGreen (pixel)
    b=getBlue (pixel)
    if (g<200):
      g=g+55
    newColor=makeColor(r,g,b)
    setColor (pixel,newColor)


def blueish (picture):
 pixels=getPixels (picture)
 for pixel in pixels:
    r=getRed (pixel)
    g=getGreen (pixel)
    b=getBlue (pixel)
    if (b<190):
      b=b+65
    newColor=makeColor(r,g,b)
    setColor (pixel,newColor)


def redish (picture):
 pixels=getPixels (picture)
 for pixel in pixels:
    r=getRed (pixel)
    g=getGreen (pixel)
    b=getBlue (pixel)
    if (r<200):
      r=r+55
    newColor=makeColor(r,g,b)
    setColor (pixel,newColor)


def blackout (picture):
  pixels=getPixels (picture)
  for pixel in pixels:
    r=getRed (pixel)
    g=getGreen (pixel)
    b=getBlue (pixel)
    blackish=0
    newColor=makeColor (blackish,blackish,blackish)
    setColor (pixel,newColor)


def whiteout (picture):
  pixels=getPixels (picture)
  for pixel in pixels:
    r=getRed (pixel)
    g=getGreen (pixel)
    b=getBlue (pixel)
    blackish=255
    newColor=makeColor (blackish,blackish,blackish)
    setColor (pixel,newColor)


def grayscale (picture):
  pixels=getPixels (picture)
  for pixel in pixels:
    r=getRed (pixel)
    g=getGreen (pixel)
    b=getBlue (pixel)
    grey=(r+g+b)/3
    newColor=makeColor(grey,grey,grey)
    setColor (pixel,newColor)


def invert (picture):
  pixels=getPixels (picture)
  for pixel in pixels:
    r=getRed (pixel)
    g=getGreen (pixel)
    b=getBlue (pixel)
    r=255-r
    g=255-g
    b=255-g
    newColor=makeColor (r,g,b)
    setColor (pixel,newColor)



#opening the file to edit or view

file=pickAFile()
make=makePicture(file)
show(make)

#choosing the filter to use
choice=requestInteger("Choose a filter...\n1=invert  2=grayscale  3=whiteout  4=blackout 5=redish\n6=blueish  7=greenish  8=no green  9= no red  10=no blue\n11=make lighter  12=black and white  13=chromakey  14=mirror  15=mirror2\n16=mirror3  17=collage")
if (choice==1):
 invert(make)
if (choice==2):
  grayscale(make)
if (choice==3):
  whiteout(make)
if (choice==4):
  blackout (make)
if (choice==5):
  redish (make)
if (choice==6):
  blueish (make)
if (choice==7):
  greenish (make)
if (choice==8):
  nogreen(make)
if (choice==9):
  nored(make)
if (choice==10):
  noblue(make)
if (choice==11):
  lighter(make)
if (choice==12):
  sketchlike(make)
if (choice==13):
  chromakey(make)
if (choice==14):
  mirror(make)
if (choice==15):
  mirror2(make)
if (choice==16):
  mirror3(make)
if (choice==17):
  collage(make)


#repaint the picture
repaint (make)


#saving the picture
fileName=requestString("Save picture as...")
if (fileName!=''):
  folder=pickAFolder()
  pathway=folder + "\\" + fileName + ".jpg"
  printNow (pathway)
  writePictureTo (make,pathway)