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

F5 KScope 1 Webcam

Get Adobe Flash player
by nutsu 25 Dec 2008
// forked from nutsu's F5 KScope0
// write as3 code here..
package{
    import flash.display.*;
    import flash.events.*;
    import flash.geom.Matrix;
    import flash.media.Camera;
    import flash.media.Video;
    import frocessing.FC;
    import frocessing.core.F5Graphics2D;

    [SWF(frameRate="30", backgroundColor="#000000")] 
    public class F5KScope1Webcam extends Sprite
    {
        private var _hw:Number;
        private var _hh:Number;
        private var _r:Number;
        private var fg:F5Graphics2D;
        private var bd:BitmapData;
        private var _display:DisplayObject;
        private var camera:Camera;
        private var video:Video;
        
        public function F5KScope1Webcam() 
        {
            stage.align = StageAlign.TOP_LEFT;
            addEventListener( Event.ADDED_TO_STAGE, setup );
        }

        private function setup(e:Event):void
        {
            removeEventListener( Event.ADDED_TO_STAGE, setup );
            _hw = stage.stageWidth*0.5;
            _hh = stage.stageHeight*0.5;
            _r  = _hw/Math.cos(Math.PI/6);
            fg = new F5Graphics2D(graphics);
            fg.noStroke();
            
            camera = Camera.getCamera();  
            camera.setMode(320, 240, 30);
            if( camera==null )
                return;
            video = new Video(320, 240);
            video.attachCamera(camera);
            bd = new BitmapData( 320, 240, false, 0xff000000 );
            _display = video;

            var m:Shape = new Shape();
            m.graphics.beginFill(0xffffff);
            m.graphics.drawEllipse( 0, 0, _hw * 2, _hw * 2 );
            m.graphics.endFill();
            mask = m;
            
            addEventListener( Event.ENTER_FRAME, draw );
        }

        private function draw(e:Event):void
        {
            bd.draw( _display );
            fg.beginDraw();
            fg.translate( _hw, _hh );
            drawKScope( bd );
            fg.endDraw();
        }

        private function drawKScope( bd:BitmapData ):void
        {
            var a:Number  = Math.PI / 3;
            var u:Number = 0.5;
            var v:Number = 1;
            fg.beginShape( FC.TRIANGLE_FAN );
            fg.texture( bd );
            fg.vertex( 0, 0, u, v );
            u = v = 0;
            for ( var i:int = 0; i <= 6; i++ )
            {
                fg.vertex( _r * Math.cos( a * i ), _r * Math.sin( a * i ), u, v );
                u = ( u == 1 ) ? 0 : 1;
            }
            fg.endShape();
        }
    }
}