def mirror_GUI (label, direction): '''Implement the function mirror_vertical or mirro_horizontal 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 mirror_vertical or mirror_horizontal. if direction == 'vertical': label.picture = img_manip.mirror_vertical(label.picture) else: label.picture = img_manip.mirror_horizontal(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_mirror_vertical(): '''Test the function mirror_vertical in img_manip.''' new_pic = create_pic(4, 4) new_pic_mirror_vertical = img_manip.mirror_vertical(new_pic) #Test if the colour in each pixel in new_pic_mirror_vertical is equal to #the colour of the pixel that is its vertical mirror. If not, the boolean #mirrored is made False. mirrored = True width = media.get_width(new_pic_mirror_vertical) height = media.get_height(new_pic_mirror_vertical) middle = width / 2 for x in range(middle): for y in range(height): pix1 = media.get_pixel(new_pic_mirror_vertical, x, y) pix2 = media.get_pixel(new_pic_mirror_vertical, width - x - 1, y) col1 = media.get_color(pix1) col2 = media.get_color(pix2) if col1 != col2: mirrored = False assert mirrored, \ "mirror_vertical failed to mirror the picture vertically."