Mini-Lab: Chromakey Animation

 


Introduction

In this mini-lab we will experiment with combining the chromakey function with our movement functions to move images in scenes.



Chromakey Animation

  1. Copy your chromakey function from a previous lab into this lab. Copy the functions copyPictureInto and cropPicture from the Support Code into this lab as well.

  2. Copy this function that inputs a picture of an object (a car, a person, etc) and a background scene (such as the moon, or the quad, or some city) as parameters, and moves the object in the background along row #20.
    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)
    
         

  3. Find a smallish picture with some object in it and a larger picture that would make a good background. (Remember, you can always make a large picture smaller by quartering it or by cropping a section of it.) Test the moveObjectInScene function by calling it with your two pictures as the parameters.
    Does it do what you expect? Why or why not?

  4. Find a green screen picture (a perosn in front of a green screen, from a previous lab). You will want the green screen picture to be much smaller than the background you want to use.

  5. Test moveObjectInScene by 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.

  6. Now we need to call chromakey on the small object to help it blend into the background. To do this we will need to add two new lines in our moveObjectInScene function. These lines should be added directly inside the for loop, before the copyPictureInto statements. The first line should use the cropPicture function to get the portion of the background that the object will be over. The second line should call the chromakey function with the background portion and the object. (Note: The two pictures should be the same size) The last change is to modify the copyPictureInto statement so that it copies the picture returned by the chromakey function into the canvas instead of the object itself.

  7. Test the new function to see that it works.

Submit your results

  1. Submit the file you created in this mini-lab via .