def getPicture(): file = pickAFile (); pict = makePicture(file); openPictureTool (pict) def turnRed(): brown = makeColor(122,86,62) file = pickAFile() picture = makePicture(file) for px in getPixels(picture): color = getColor(px) if distance(color,brown) < 25.0: redness = getRed(px)*1.5 setRed(px,redness) show(picture) return(picture) # function to show the problem between = and == def equalExample (val): print val if (val == 10): print "The value is 10" print val def equalExample2 (val): print val #if (val = 10): # print "The value is 10" print val def posterize(picture): #loop through the pixels for p in getPixels(picture): #get the RGB values red = getRed(p) green = getGreen(p) blue = getBlue(p) #check and set red values #if red < 64: # setRed(p, 31) #if red > 63 and red < 128: # setRed(p, 95) #if red > 127 and red < 192: # setRed(p, 159) #if red > 191 and red < 256: # setRed(p, 223) # rewrite above if statements using elif and else if red < 64: setRed(p, 31) elif red < 128: setRed(p, 95) elif red < 192: setRed(p, 159) else: setRed(p, 223) #check and set green values if green < 64: setGreen(p, 31) if green > 63 and green < 128: setGreen(p, 95) if green > 127 and green < 192: setGreen(p, 159) if green > 191 and green < 256: setGreen(p, 223) #check and set blue values if blue < 64: setBlue(p, 31) if blue > 63 and blue < 128: setBlue(p, 95) if blue > 127 and blue < 192: setBlue(p, 159) if blue > 191 and blue < 256: setBlue(p, 223) openPictureTool (picture) def usePosterize (): file = pickAFile (); pict = makePicture(file); posterize (pict) def useSepiaTint (): file = pickAFile (); pict = makePicture(file); sepiaTint (pict) def sepiaTint(picture): #Convert image to grayscale for pix in getPixels (picture): redAmount = getRed (pix) greenAmount = getGreen (pix) blueAmount = getBlue (pix) lum = (redAmount + greenAmount + blueAmount) / 3 negColor = makeColor (lum, lum, lum) setColor(pix, negColor) #grayScaleNew(picture) #loop through picture to tint pixels for p in getPixels(picture): red = getRed(p) blue = getBlue(p) #Note: = red now #tint shadows if red < 63: red = red*1.1 blue = blue*0.9 #tint midtones if red > 62 and red < 192: red = red*1.15 blue = blue*0.85 #tint highlights if red > 191: red = red*1.08 if red > 255: red = 255 blue = blue*0.93 #set the new color values setBlue(p, blue) setRed(p, red) openPictureTool (picture)