'''lecture_21_list_sidebyside.py Use lists to organize image placement information Oliver W. Layton CS151: Computational Thinking: Visual Media Fall 2020 ''' import display import graphics as gr import lecture_20_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 = 300 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 imgListOfLists = [[0, 0, 'pink', img], # Slot 1: left [width, 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 imgList in imgListOfLists: # imgList is a SUBLIST currImg = imgList[-1].clone() if imgList[2] == 'red': solid.solid_fill(currImg, r=255) elif imgList[2] == 'blue': solid.solid_fill(currImg, b=255) elif imgList[2] == 'yellow': solid.solid_fill(currImg, g=255, r=255) elif imgList[2] == 'pink': solid.solid_fill(currImg, r=255, b=255) solid.placeImageInCanvas(canvas, currImg, imgList[0], imgList[1]) # Update image object in list of lists imgList[-1] = currImg # Display canvas screen = display.displayImage(canvas, 'Our canvas') # Wait for mouse click to close window and end program screen.getMouse() # main code if __name__ == '__main__': sideBySideList()