''' Purpose: generate a randomly colored image of appropriate size ''' import random from PIL import Image from image_support import get_blank_image, set_pixel, show # specify background color RGB_alice_blue = ( 240, 248, 255 ) # get desired width and height reply = input( "Enter width and height of interest: " ) w, h = reply.split() w, h = int( w ), int( h ) # specify image dimension size = ( w, h ) # get appropriately sized and colored image img = get_blank_image( size, RGB_alice_blue ) # overwrite the image pixels in a rightward sweep for x in range( 0, w ) : for y in range( 0, h ) : # for a given x process the y's from top to bottom # use x and y combination as spot on the image spot = ( x, y ) # generate a random color for the spot r = random.randrange( 0, 256 ) g = random.randrange( 0, 256 ) b = random.randrange( 0, 256 ) c = ( r, g, b ) # set the img pixel at spot to color c set_pixel( img, spot, c ) # show image show( img )