# Recipe 43: Chromakey: Replace all blue with the new background

def chromakey(source, bg):
  # Source should have something in front of blue, bg is the new background
  # Both pictures have to be of the same size!

  for x in range(1, getWidth(source)+1):
    for y in range(1, getHeight(source)+1):
      p = getPixel(source,x,y)

      # Define blue: If the greenness < blueness
      if (getGreen(p)+10) < (getBlue(p)):
        # if theres alot of blue 
        if ((getBlue(p)) > 100):
           # Then grab the pixel from the new background
           setColor(p, getColor(getPixel(bg,x,y)))


  return source