def rotate90(): # selected image to rotate file = pickAFile() pict1 = makePicture(file) # get the wid and hgt of pict1 wid1 = getWidth(pict1) hgt1 = getHeight(pict1) # create the blank canvas for the rotated image # makeEmptyPicture(widthOfNewImage, heightOfNewImage) pict2 = makeEmptyPicture(hgt1-1, wid1-1) print wid1, hgt1, getWidth(pict2), getHeight(pict2) # copy and rotate the pixels # use x for the columns (determined by the width) # use y for the rows (determined by the height) for x in range (1, wid1+1): for y in range (1, hgt1+1): # get the color value from the pixel in the # original image pixel1 = getPixel(pict1, x, y) color = getColor(pixel1) # determine the column and row in the rotated image x2 = hgt1 + 1 - y y2 = x # put the color in the pixel in the rotated image pixel2 = getPixel(pict2, x2, y2) setColor(pixel2, color) # display the rotated image show (pict2) def rotate270(): # selected image to rotate file = pickAFile() pict1 = makePicture(file) # get the wid and hgt of pict1 wid1 = getWidth(pict1) hgt1 = getHeight(pict1) # create the blank canvas for the rotated image # makeEmptyPicture(widthOfNewImage, heightOfNewImage) pict2 = makeEmptyPicture(hgt1-1, wid1-1) print wid1, hgt1, getWidth(pict2), getHeight(pict2) # copy and rotate the pixels # use x for the columns (determined by the width) # use y for the rows (determined by the height) for x in range (1, wid1+1): for y in range (1, hgt1+1): # get the color value from the pixel in the # original image pixel1 = getPixel(pict1, x, y) color = getColor(pixel1) # determine the column and row in the rotated image # x2 = hgt1 + 1 - y # y2 = x # only need to change this part from rotate90() x2 = y y2 = wid1 + 1 - x # put the color in the pixel in the rotated image pixel2 = getPixel(pict2, x2, y2) setColor(pixel2, color) # display the rotated image show (pict2) def rotate180(): # selected image to rotate file = pickAFile() pict1 = makePicture(file) # get the wid and hgt of pict1 wid1 = getWidth(pict1) hgt1 = getHeight(pict1) # create the blank canvas for the rotated image # makeEmptyPicture(widthOfNewImage, heightOfNewImage) pict2 = makeEmptyPicture(wid1-1, hgt1-1) print wid1, hgt1, getWidth(pict2), getHeight(pict2) # copy and rotate the pixels # use x for the columns (determined by the width) # use y for the rows (determined by the height) for x in range (1, wid1+1): for y in range (1, hgt1+1): # get the color value from the pixel in the # original image pixel1 = getPixel(pict1, x, y) color = getColor(pixel1) # determine the column and row in the rotated image x2 = wid1 + 1 - x y2 = hgt1 + 1 - y # put the color in the pixel in the rotated image pixel2 = getPixel(pict2, x2, y2) setColor(pixel2, color) # display the rotated image show (pict2) def rotate(pict1): # get the wid and hgt of pict1 wid1 = getWidth(pict1) hgt1 = getHeight(pict1) # create the blank canvas for the rotated image # makeEmptyPicture(widthOfNewImage, heightOfNewImage) pict2 = makeEmptyPicture(hgt1-1, wid1-1) print wid1, hgt1, getWidth(pict2), getHeight(pict2) # copy and rotate the pixels # use x for the columns (determined by the width) # use y for the rows (determined by the height) for x in range (1, wid1+1): for y in range (1, hgt1+1): # get the color value from the pixel in the # original image pixel1 = getPixel(pict1, x, y) color = getColor(pixel1) # determine the column and row in the rotated image x2 = hgt1 + 1 - y y2 = x # put the color in the pixel in the rotated image pixel2 = getPixel(pict2, x2, y2) setColor(pixel2, color) # display the rotated image return (pict2) def callRotate(): # selected image to rotate file = pickAFile() opict = makePicture(file) # call the rotate() function npict = rotate(opict) # display the rotated image show (npict) # call the rotate() function npict2 = rotate(npict) # display the rotated image show (npict2) # call the rotate() function npict3 = rotate(npict2) # display the rotated image show (npict3) # call the rotate() function npict4 = rotate(npict3) # display the rotated image show (npict4)