CS 107: Pictures and Sounds: Programming with Multimedia

Kalamazoo College

Spring 2008

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.

  2. Copy this function that takes an object (something on a green/blue background) and a background (such as the moon or the jungle) as parameters, and moves the object in the background along row #10.
    def moveObjectInScene(object, scene):
      canvas = duplicatePicture(scene)
      show(canvas)
      row = 10
    
      for count in range(1, getWidth(scene)-getWidth(object), 10):
        copyInto(object, canvas, count, row)
        repaint(canvas)
        time.sleep(.1)
        # "erase" the object
        littleCanvas = cropPicture(scene, count, row, getWidth(object), getHeight(object))
        copyInto(littleCanvas, canvas, count, row)
    
         

  3. Create a new picture from a green or blue screen picture that is much smaller than the background you want to use. You can take a larger picture and use your quarter function from a previous lab to get a smaller picture or you can use the crop function from JES and MediaTools to create just a portion of the green or blue screen image.

  4. 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 10, 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.

  5. 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 copyInto statements. The first line should use the crop command 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 copyInto statement so that it copies the picture returned by the chromakey function into the canvas instead of the object itself.

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

Print your results

  1. Print the functions in this file and hand it in.