In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

DiffCamera

DiffCamera.as
Get Adobe Flash player
by kadal 09 Apr 2009
// forked from kadal's MosaicCamera
// forked from kadal's BlurCamera
// forked from kadal's BasicCamera
/* DiffCamera.as */
package {
    import flash.display.Sprite;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.media.Camera;
    import flash.media.Video;
    import flash.events.Event;
    import flash.filters.ColorMatrixFilter;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import net.hires.debug.Stats;

    
    [SWF(backgroundColor="#000000", frameRate=15)]
    
    public class DiffCamera extends Sprite {
        
        private var SW:Number = stage.stageWidth;
        private var SH:Number = stage.stageHeight;
        
        private var myCamera:Camera;
        private var myVideo:Video;
        private var myStage:Sprite = new Sprite();
        private var myDraw:Sprite = new Sprite();

        private var samplingSize:Number = 3;
        private var samplesArray:Array = new Array();

        private var sensitive:Number = 0x202020;

        public function DiffCamera():void {
            myCamera = Camera.getCamera();
            myCamera.setMode(500, 500, 15);
            myVideo = new Video(stage.stageWidth, stage.stageHeight);
            myVideo.attachCamera(myCamera);

            for (var iX:int=0; iX<SW/samplingSize; iX++) {
                samplesArray.push(new Array());
                 for (var iY:int=0; iY<SH/samplingSize; iY++) {
                     samplesArray[iX].push(0);
                 }
            }
            

            addChild(myStage);
            myStage.addChild(myVideo);
            myStage.addChild(myDraw);
            addChild(new Stats());
            
            addEventListener(Event.ENTER_FRAME, xDraw);
        }
        
        public function xDraw(evt:Event):void{

            var myBmd:BitmapData = new BitmapData(SW, SH);
            myBmd.draw(myVideo);

            myBmd.applyFilter(myBmd, new Rectangle(0, 0, SW, SH), new Point(0, 0),
            new ColorMatrixFilter([1/3, 1/3, 1/3, 0, 0, 1/3, 1/3, 1/3, 0, 0, 1/3, 1/3, 1/3, 0, 0, 0, 0, 0, 255, 0]));

            myDraw.graphics.clear();
       
            for (var iX:int=0; iX<SW/samplingSize; iX++) {
                 for (var iY:int=0; iY<SH/samplingSize; iY++) {
                     var pick:int = myBmd.getPixel(iX*samplingSize, iY*samplingSize);
                     if(Math.abs(samplesArray[iX][iY]-pick) > sensitive){
                         myDraw.graphics.beginFill(0xFF0000, 0.5);
                         myDraw.graphics.drawRect(iX*samplingSize, iY*samplingSize, samplingSize, samplingSize)
                         myDraw.graphics.endFill();
                     }
                     samplesArray[iX][iY] = pick;
                 }
            }
            
        }
    }
}