Develop three algorithms for lightening, darkening, and color filtering as three related Python functions, lighten, darken, and colorFilter. The first two functions should expect an image and a positive integer as arguments. The third function should expect an image and a tuple of integers (the RGB values) as arguments. The following session shows how these functions can be used with the hypothetical images image1, image2, and image3, which are initially transparent: >>> image1 = Image(100, 50) >>> image2 = Image(100, 50) >>> image3 = Image(100, 50) >>> lighten(image1, 128) # Converts to gray >>> darken(image2, 64) # Converts to dark gray >>> colorFilter(image3, (255, 0, 0))
def lighten(img, intensity): for pixel in getPixels(img): new_intensity = getRed(pixel) + intensity setColor(pixel, makeColor(new_intensity, new_intensity, new_intensity)) def darken(img, intensity): for pixel in getPixels(img): new_intensity = getRed(pixel) - intensity setColor(pixel, makeColor(new_intensity, new_intensity, new_intensity)) def colorFilter(img, color): for pixel in getPixels(img): setColor(pixel, color)