In this mini-lab we will experiment with combining the
chromakey function with our movement functions to move
images in scenes.
import time # This function moves the object across row 20 of the scene def moveObjectInScene(objectPicture, backgroundScene): canvas = duplicatePicture(backgroundScene) show(canvas) row = 20 for count in range(0, getWidth(backgroundScene)-getWidth(objectPicture), 10): copyPictureInto(objectPicture, canvas, count, row) repaint(canvas) # Comment out time.sleep function call if results are too slow time.sleep(.1) # "erase" the object by getting the piece of background that lines # up with the position of the object picture in the scene littleCanvas = cropPicture(backgroundScene, count, row, getWidth(objectPicture), getHeight(objectPicture)) copyPictureInto(littleCanvas, canvas, count, row)
moveObjectInScenefunction by calling it with your two pictures as the parameters.
moveObjectInSceneby calling it with a background, and the small picture you created in the previous step. If you don't like the picture moving at row 20, you may change the variable row to a better row. Just make sure that there is enough room on the background for the entire object.
moveObjectInScenefunction. These lines should be added directly inside the for loop, before the
copyPictureIntostatements. The first line should use the
cropPicturefunction to get the portion of the background that the object will be over. The second line should call the
chromakeyfunction with the background portion and the object. (Note: The two pictures should be the same size) The last change is to modify the
copyPictureIntostatement so that it copies the picture returned by the chromakey function into the canvas instead of the object itself.