#This is designed to alter the Cookie Monster picture #that we've often viewed in class, but it's been implemented #as a generic function that takes all the pixels in an image #that are close enough to blue and reddens them. #How "close to blue" a pixel is will be measured by the built-in #distance function that measures the distance between colors. #The threshold distance is supplied as a parameter to the function. #The result is an altered picture in which every "blue enough" pixel #has its red component interchanged with its blue component. #You may need to play around with the green component to get just the #right effect. def blue_to_red(p,threshold): for px in getPixels(p): if distance(getColor(px),blue)<=threshold: r=getRed(px) b=getBlue(px) setRed(px,b) setBlue(px,r)