'''lecture_20_list_sidebyside.py Use lists to organize image placement information Oliver W. Layton CS151: Computational Thinking: Visual Media Spring 2021 ''' import display import graphics as gr import lecture_19_solid_colors_sidebyside as solid def sideBySideList(): '''Function to test out placing an image (left) next to its filtered version (right) ''' # Create an image width = 600 height = 400 img = gr.Image(gr.Point(0, 0), width, height) # Make image list, with x, y placement info, how to process it (str), # and the `Image` object # We want a yellow image on the left, a pink one on the right imgParamList = [ [0, 0, 'pink', img], # slot 1 (left) [img.getWidth(), 0, 'yellow', img] # slot 2 (right) ] # Make 1x2 canvas canvas = gr.Image(gr.Point(0, 0), 2*width, height) '''Process is: - Loop thru list, deal with one sublist at a time. - Clone the image object (original image by default). - Apply the solid color depending on the color name in the sublist. - Place it on the canvas. - Display the canvas. ''' for params in imgParamList: # params is a sublist — like imgParamList[0] currImg = img.clone() # img is the original (currently blank) # paint the current image the appropriate color if params[2] == 'yellow': solid.solid_fill(currImg, r=255, g=255) elif params[2] == 'pink': solid.solid_fill(currImg, r=255, b=255) solid.placeImageInCanvas(canvas, currImg, params[0], params[1]) # Update current image parameter list to have the updated image params[-1] = currImg # Display filtered image screen = display.displayImage(canvas, 'My canvas') # Wait for mouse click to close window and end program screen.getMouse() screen.close() # main code if __name__ == '__main__': sideBySideList()