# # Convert an image from color to grayscale, displaying both the original # image and the grayscale version. # from SimpleGraphics import * # # Load and display the image. # orig = loadImage("Flowers.gif") drawImage(orig, 0, 0) # # Create a new image to store the grayscale data. # gray = createImage(getWidth(orig), getHeight(orig)) # For each row in the image... for y in range(0, getHeight(orig)): # For each column in the row... for x in range(0, getWidth(orig)): # Average the red, green and blue values. r, g, b = getPixel(orig, x, y) avg = (r + g + b) / 3 # Store average red, average green and average blue into the grayscale # image. putPixel(gray, x, y, avg, avg, avg) # Display the grayscale image. drawImage(gray, getWidth(orig), 0)