''' Purpose: generate a randomly colored image of appropriate size ''' import random from PIL import Image import image_support # 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 = Image.new( "RGB", 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 img.putpixel( spot, c ) # show image img.show()