''' Purpose: support image mirroring transformation ''' def mirror( nspot, nw, nh ) : ''' Returns the correspondent of nspot in its nw x ny image in the unmirrored original ''' # we are trying to find where to look in the original image for our pixel location of interest # in the new image, we are reversing left and right # if we are nx from the left in the new image, we want to be nx from the right in the original image # this will be reversed for flip.py, you'll be reversing up and down nx, ny = nspot # unpack nx, ny # ox needs to be nx from the right hand side of the original image ( our image is nw pixels wide ), nw-1 is our right hand side ox = ( nw - 1 ) - nx oy = ny # since our y value is unchanged, oy = ny ospot = ( ox, oy ) # working backwards, now we know we're calculating ox and oy values return ospot if ( __name__ == '__main__' ) : import url from manip import manip # get web image of interest link = "http://www.cs.virginia.edu/~cs1112/images/mandrill/full.png" original = url.get_image( link ) new_image = manip( original, at=mirror ) # we want to use the same size and color, but only alter the location # so we only have to specify one of the optional parameters for the manip() function new_image.show()