def horizontal_reflection_GUI (label): '''Implement the function horizontal_reflection from img_manip.''' #Clear all the temp pics in front of the current pic current_pic global temp_label global current_pic temp_label = temp_label[0:current_pic+1] #Implement the function horizontal_reflection. label.picture = img_manip.horizontal_reflection(label.picture) #Keep a copy of the current pic for the functions Undo and Redo temp_label.append(label.picture) current_pic += 1 #update the label update_label(label)
def test_horizontal_reflection(): '''Test the function horizontal_reflection in img_manip.''' new_pic = create_pic(4, 4) new_pic_reflected = img_manip.horizontal_reflection(new_pic) #Test if the colour of each pixel in new_pic_horizontal_reflection is equal to #the colour of the corresponding pixel in new_pic. If not, the boolean #reflected is made False. reflected= True width = media.get_width(new_pic) height = media.get_height(new_pic) for x in range(width): for y in range(height): pix1 = media.get_pixel(new_pic, x, y) pix2 = media.get_pixel(new_pic_reflected, width - x - 1, y) col1 = media.get_color(pix1) col2 = media.get_color(pix2) if col1 != col2: reflected = False assert reflected, \ "horizontal_reflection failed to reflect the image horizontally."