# #CS 1301 - Jay Summet - Donated to the public domain Nov 2008. # #Example of a special effect that fades an image to black and then stores #an animated gif of it. # # from myro import * #fadePicture # # This function takes a picture, and darkens it. def fadePicture(picture, amount): for pixel in getPixels(picture): r = getRed(pixel) g = getGreen(pixel) b = getBlue(pixel) r = r - amount g = g - amount b = b - amount #The set functions will limit negative values to zero for us! setRed(pixel,r) setGreen(pixel,g) setBlue(pixel,b) # Test for fadePicture ##p = loadPicture("class1.jpg") ##show(p) ## ##fadePicture(p, 100) ##show(p, "faded") #Fade-To-Black: # It gradually fades a picture, darker and darker, until # all the pixels are black. It returns a list of pictures # where the first picture is the original image, and each # subsequent picture is a darker version of the one that # came before it. def fadeToBlack(picture,frames,amount): outputList = [] outputList.append(picture) #Do our work on a copy of the original. cp = copyPicture(picture) for i in range(frames): #User Output so they know we are still working print "fade number: ", i #fade the picture fadePicture(cp, amount) outputList.append(cp) cp = copyPicture(cp) #return the list: return(outputList) p = loadPicture("class1.jpg") myList = fadeToBlack(p,5, 25) print "len of myList:", len(myList) print "Showing pictures!" for i in myList: show(i) wait(1) print "saving to an animated gif!" savePicture(myList, "fade_to_black.gif")