#this turns a picture into a sepia-ttinted version. #note that this function alters the picture itself, #rather than return a sepia-tinted picture #as a value, so it is a little different from #the suggested organization in the assignment. #This also lets you set the percentage for #altering red and blue components of dark, midtone, #and bright pixels. def sepia_tint(p,shadow,midtone,highlight): for px in getPixels(p): r=getRed(px) g=getGreen(px) b=getBlue(px) av=(r+g+b)/3 setGreen(px,av) setBlue(px,av) if av<64: setRed(px,min(255,(1+shadow)*av)) setBlue(px,(1-shadow)*av) elif av>=192: setRed(px,min(255,(1+highlight)*av)) setBlue(px,(1-highlight)*av) else: setRed(px,min(255,(1+midtone)*av)) setBlue(px,(1-midtone)*av) #This lets the user pick an image file and #returns a sepia-tinted version. def sepia_demo(): q=makePicture(pickAFile()) sepia_tint(q,0.1,0.15,0.08) show(q)