For my first Ham Jam (Ham’s yearly soiree) I wanted to contribute to the party atmosphere. Since we had a DJ lined up, a dance floor, webcams, a slew of computers and we are an interactive shop, what could enhance the mood better than an motion-triggered interactive installation?
An external iSight webcam provides the video, a local SWF handles the logic and a projector displays the magic. The Actionscript used to accomplish this combines a few simple concepts:
- Webcam – A WebCam class manages interaction between the Camera class and the rest of the app. The camera’s video feed is passed into a Video object using the attachCamera() method.
- BitmapData – The Video object’s display is then drawn to a BitmapData object using the draw() method. For each frame of the camera’s video feed this BitmapData object is merged with the previous frame’s BitmapData using two filters: a color filter to highlight the pixels that have changed color value; and a blur filter to manage precision (and thus performance). The resulting image is then scanned, pixel by pixel, and pixels above a certain color threshold are recorded in a Point object and pushed into an array.
- Particles – A particle is then created and placed at every Point in the array. The Particle object contains a display object and an update() method with logic that handles how the particle changes and animates over time.
The result is multiple swarms of particles emanating from your shadow as you move in front of the camera. You can check it out for yourself here if you have a webcam, or you can watch the video below. The quality isn’t the best, but considering the lighting conditions it gets the point across: