# Convert a color image into grayscale from SimpleGraphics import * # Load the image from the disk and display it img = loadImage("Brickosaurus.gif") drawImage(img, 0, 0) # For each pixel in the image going down the rows and then across the # columns in each row for y in range(0, getHeight(img)): for x in range(0, getWidth(img)): # Retrieve the red, green and blue values for the current pixel r, g, b = getPixel(img, x, y) # Compute the average avg = (r + g + b) / 3 # Store the gray pixel in the image with average red, average green and # average blue putPixel(img, x, y, avg, avg, avg) # Draw the image after it has been transformed drawImage(img, 0, 0)