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

forked from: カメラの残像をつくってあそぶ

カメラの残像をつくってあそぶ(たまたまできた)
/**
 * Copyright Good ( http://wonderfl.net/user/Good )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/mf4d
 */

// forked from utabi's カメラの残像をつくってあそぶ
// カメラの残像をつくってあそぶ(たまたまできた)

package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.display.BlendMode;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import flash.filters.ColorMatrixFilter;
    import flash.filters.ConvolutionFilter;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import flash.geom.ColorTransform;
    import flash.media.Camera;
    import flash.media.Video;
    
    [SWF(frameRate="20")]
    
    public class AfterImage extends Sprite {
        Wonderfl.capture_delay( 15 );
        private var camera:Camera;
        private var video:Video;
        private var videoWidth:int = 465;
        private var videoHeight:int = 465;
        private var bd:BitmapData;
        private var now:BitmapData;
        private var oldBD:BitmapData;
        private var diffBD:BitmapData;
        private var overlay:BitmapData;
        private var rect:Rectangle;
        private var zeroPoint:Point = new Point(0,0);

        private var blurFilter:BlurFilter = new BlurFilter(3,3);
        private var grayConst:Array = [
            0.3, 0.59, 0.11, 0, 0,
            0.3, 0.59, 0.11, 0, 0,
            0.3, 0.59, 0.11, 0, 0,
            0, 0, 0, 0, 255
        ];
        private var grayFilter:ColorMatrixFilter = new ColorMatrixFilter(grayConst);
        
        private var threshold:uint=0xFF222222;
            
        public function AfterImage() {
            camera = Camera.getCamera();
            if (camera==null) {
            } else {
                start();
            }
        }
        private function start():void {
            camera.setMode(videoWidth, videoHeight,20);
            video = new Video(videoWidth, videoHeight);
            video.attachCamera(camera);
            bd = new BitmapData(videoWidth,videoHeight);
            now = new BitmapData(videoWidth,videoHeight);
            oldBD = new BitmapData(videoWidth,videoHeight);
            diffBD = new BitmapData(videoWidth,videoHeight);
            rect = now.rect;
            
            //this.addChild(video);
            this.addChild(new Bitmap(bd));

            //this.getChildAt(1).y=233;
            this.addEventListener(Event.ENTER_FRAME,onEnterFrame);
        }
        private function onEnterFrame(e:Event):void {
                
            now.draw(video);
           now.applyFilter(now,rect,zeroPoint,grayFilter);
            
            diffBD.draw(now);
            diffBD.draw(oldBD,null,null,BlendMode.DIFFERENCE);
            //diffBD.applyFilter(diffBD, rect,zeroPoint,blurFilter);
            //diffBD.threshold(diffBD, rect, zeroPoint, ">", 0xff222222, 0xffffffff);
            //diffBD.threshold(diffBD, rect, zeroPoint, "<", 0xff111111, 0x00000000);
            
            oldBD.draw(now);
            
            bd.fillRect(bd.rect, 0xFF000000);
            bd.draw(diffBD);
        }
        
    }
}