# # Convert an image from color to grayscale, displaying both the original # image and the grayscale version. # from SimpleGraphics import * # Load the image and draw it orig = loadImage("Flowers.gif") drawImage(orig, 0, 0) # Create a new blank result image result = createImage(getWidth(orig), getHeight(orig)) # For every pixel in the image for y in range(0, getHeight(orig)): for x in range(0, getWidth(orig)): # Compute the gray value r, g, b = getPixel(orig, x, y) average = (r + g + b) / 3 # Store the gray value putPixel(result, x, y, average, average, average) # Draw the result image drawImage(result, getWidth(orig), 0)