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

ThresholdCamera

ThresholdCamera.as
Get Adobe Flash player
by kadal 09 Apr 2009
// forked from kadal's BlurCamera
// forked from kadal's BasicCamera
/* ThresholdCamera.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.geom.Rectangle;
    import flash.geom.Point;
    import flash.filters.BlurFilter;
    import net.hires.debug.Stats;

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

        private var threshold:Number = 0x444444;

        public function ThresholdCamera():void {
            myCamera = Camera.getCamera();
            myCamera.setMode(500, 500, 30);
            myVideo = new Video(stage.stageWidth, stage.stageHeight);
            myVideo.attachCamera(myCamera);
            
            addChild(myStage);
            myStage.addChild(myBmp);
            addChild(new Stats());
            
            addEventListener(Event.ENTER_FRAME, xDraw);
        }
        
        public function xDraw(evt:Event):void{
            myStage.removeChild(myBmp);
            var myBmd:BitmapData = new BitmapData(SW, SH);
            myBmd.draw(myVideo);

            var d:BitmapData = new BitmapData(myBmd.width, myBmd.height);
            var r:Rectangle = new Rectangle(0, 0, myBmd.width, myBmd.height);
            d.fillRect(r, 0xFFFFFFFF);
            d.threshold(myBmd, r, new Point(0, 0), "<=", threshold, 0xFF000000, 255, false);

            myBmp = new Bitmap(d);
            myStage.addChild(myBmp);
        }
    }
}