Example #1
0
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)
Example #2
0
def test_mirror_horizontal():
    '''Test the function mirror_horizontal in img_manip.'''
    
    new_pic = create_pic(4, 4)
    new_pic_mirror_horizontal = img_manip.mirror_horizontal(new_pic)
    
    #Test if the colour in each pixel in new_pic_mirror_horizontal is equal to 
    #the colour of the pixel that is its horizontal mirror. If not, the boolean 
    #mirrored is made False.
    mirrored = True
    width = media.get_width(new_pic_mirror_horizontal)
    height = media.get_height(new_pic_mirror_horizontal)
    middle = width / 2
    for x in range(width):
        for y in range(middle):
	    pix1 = media.get_pixel(new_pic_mirror_horizontal, x, y)
	    pix2 = media.get_pixel(new_pic_mirror_horizontal, x, height - y - 1)
	    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."