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: お絵描きアプリもどき ネオン管っぽくしてみた

// forked from munegon's code on 2008-12-18
// write as3 code here..
package {
    
    import flash.display.*;
    import flash.events.*;
    import flash.ui.Keyboard;
    import flash.filters.*;
    import flash.geom.*;
    
    public class DrawApp extends Sprite {
        private var canvas_bd:BitmapData;
        private var canvas_sp:Sprite;
        private var blur:BlurFilter;
        
        private var index:int;
        private var color:int;
        private var colors:Array = [0xcc0000, 0xcccc00, 0x00cc00, 0x00cccc, 0x0000cc, 0xcc00cc ];
        
        public function DrawApp() {
            addEventListener( Event.ADDED, added );
            blur = new BlurFilter(3,3);                          
        }
        
        private function added( e:Event ):void {
            if ( e.target == this ) {
                removeEventListener( e.type, arguments.callee );
                
                setup();   
            }    
            addEventListener(Event.ENTER_FRAME, enterFrame);
        }
        
        private function setup():void {
            canvas_bd = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0x000000 );
            addChild( new Bitmap( canvas_bd ) );
            
            canvas_sp = new Sprite();
            addChild( canvas_sp );
            
            index = 0;
            color = colors[ index ];
            
            stage.addEventListener( MouseEvent.MOUSE_DOWN, startDraw );
            stage.addEventListener( KeyboardEvent.KEY_UP, keyUpHandler );
        }
        
        private function keyUpHandler( e:KeyboardEvent ):void {
            switch ( e.keyCode ) {
                case Keyboard.LEFT:
                    index = ( colors.length + index - 1 ) % colors.length;
                    color = colors[ index ];
                    break;
                case Keyboard.RIGHT:
                    index = ( index + 1 ) % colors.length;
                    color = colors[ index ];
                    break;
            }
        }
        
        private function startDraw( e:MouseEvent ):void {

            index = ( colors.length + index - 1 ) % colors.length;
            color = colors[ index ];

            var g:Graphics = canvas_sp.graphics;
            
            g.clear();
            g.lineStyle( 5, color, 0.8 );
            g.moveTo( e.stageX, e.stageY );
            
            var up:Function = function( e:MouseEvent ):void {
                stage.removeEventListener( MouseEvent.MOUSE_MOVE, move );
                stage.removeEventListener( MouseEvent.MOUSE_UP, up );
                
                //canvas_bd.draw( canvas_sp,null, null, BlendMode.ADD);
                g.clear();
            }
            var move:Function = function( e:MouseEvent ):void {
                g.lineTo( e.stageX, e.stageY );
            }
            
            stage.addEventListener( MouseEvent.MOUSE_MOVE, move );
            stage.addEventListener( MouseEvent.MOUSE_UP, up );
        }

        private function enterFrame(e:Event):void
        {
canvas_bd.draw( canvas_sp,null, null, BlendMode.ADD);
            canvas_bd.applyFilter(canvas_bd, canvas_bd.rect, new Point(), blur);            
        }
        
    
    }
}