# # Convert an image from color to grayscale, displaying both the original # image and the grayscale version. # from SimpleGraphics import * # Load and display the color image img = loadImage("Brickosaurus.gif") drawImage(img, 0, 0) # Create a blank image with the same size as the color image gray_img = createImage(getWidth(img), getHeight(img)) # For each row in the image... for y in range(0, getHeight(img)): # For each column in row... for x in range(0, getWidth(img)): # Convert the color into gray r, g, b = getPixel(img, x, y) avg = (r + g + b) / 3 # Store the gray pixel into the grayscale image putPixel(gray_img, x, y, avg, avg, avg) # Display the grayscale image drawImage(gray_img, getWidth(img), 0)