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

なんとなくビデオエフェクト

よくわからんエフェクトができた
Get Adobe Flash player
by ll_koba_ll 22 Feb 2009
// forked from ll_koba_ll's 動体検知
// write as3 code here..
// よくわからんエフェクトができた
package {

    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.media.Camera;
    import flash.media.Video;
    import flash.filters.*;

    [SWF(frameRate="10", backgroundColor="#000000")]
    public class VideoEffect extends Sprite
    {
        
        private var camera:Camera;
        private var video:Video;
        private var button:Sprite;
        private var bmd:BitmapData;

        private var now:BitmapData;
        private var before:BitmapData;
        private var rect:Rectangle;
        private var pt:Point;

        private var blur:BlurFilter;
        private var cf:ColorMatrixFilter;
        private var mtx1px:Matrix;
        
        public function VideoEffect()
        {
            addEventListener(Event.ADDED_TO_STAGE, init);
        }

        private function init(e:Event = null):void
        {
            
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;

            camera = Camera.getCamera();

            if (camera != null)
            {
                setupCamera();
            }
                   
            bmd = new BitmapData(camera.width*2, camera.height*2 ,true,0x00ffffff);
            var bmp:DisplayObject =  addChild(new Bitmap(bmd));
            bmp.scaleX = 1.5;
            bmp.scaleY = 1.5;

            addEventListener(Event.ENTER_FRAME, loop);

            now = new BitmapData(camera.width*2, camera.height*2);
            before = new BitmapData(camera.width*2, camera.height*2);
            rect = new Rectangle(0, 0, camera.width*2, camera.height*2);
            pt = new Point(0, 0);
            blur = new BlurFilter(4,4,4);
            cf = new ColorMatrixFilter([-1, 0, 0, 0, 255, 
                                        0, -1, 0, 0, 255,
                                        0, 0, -1, 0, 255,
                                        0, 0, 0, 255, 0] );
            mtx1px = new Matrix();
            mtx1px.translate(1,1);
        }


        private function setupCamera():void
        {
            video = new Video(camera.width*2, camera.height*2);
            video.attachCamera(camera);
        }


        private function loop(e:Event):void
        {
            now.lock();
            before.lock();
            bmd.lock();
            
            now.draw(video);
            now.draw(before, new Matrix(), new ColorTransform(), BlendMode.DIFFERENCE);
            var ret:uint = now.threshold(now, rect, pt, ">", 0xFF111111, 0xFFffffff);
            before.draw(video, mtx1px);
            bmd.draw(now);
            bmd.applyFilter(bmd, bmd.rect, pt, blur);
            bmd.applyFilter(bmd, bmd.rect, pt, cf);
            
            now.unlock();
            before.unlock();
            bmd.unlock();

        }
    }
}