Beautifl - Flash Gallery

Thumbnail : doraをぱーてぃくるにしてみた
doraをぱーてぃくるにしてみた
ll_koba_ll 2009-09-08 All rights reserved

再生するにはFlash Playerが必要です。デスクトップのブラウザでご覧ください。

// forked from chabudai's doraを描いてみた
package {
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    
    public class BulletDora extends Sprite {
        private var SPEED_FO:Number = 0.8;
        
        private var canvas_bd:BitmapData;
        private var ctf:ColorTransform;
        private var temp:Sprite;
        
        public function BulletDora () {
            addEventListener( Event.ADDED_TO_STAGE, added );
        }
        
        private function added( e:Event ):void {
            if ( e.target == this ) {
                removeEventListener( e.type, arguments.callee );
                
                setup();   
            }    
        }
        
        private function setup():void {
            canvas_bd = new BitmapData( stage.stageWidth, stage.stageHeight, false, 0x000000 );
            addChild( new Bitmap( canvas_bd ) );
            
            ctf = new ColorTransform( SPEED_FO, SPEED_FO, SPEED_FO, 1.0 );
            temp = new Sprite();
            
            addEventListener( Event.ENTER_FRAME, update, false, 10 );
        }
        
        private function update( e:Event ):void {
            for ( var i:int = 0; i < 3; ++i ) {
                fire();
            }
            
            canvas_bd.colorTransform( canvas_bd.rect, ctf );
        }
        
        private function fire():void {
            var x:Number = stage.stageWidth / 2;
            var y:Number = stage.stageHeight / 2;
            var v:Number = 3*Math.random();
            var r:Number = 2*Math.PI * Math.random();
            var vx:Number = v * Math.cos( r );
            var vy:Number = v * Math.sin( r );
            
            var size:Number = 1 + 4*Math.random();
            var color:uint = 0xffffff * Math.random();
            
            var mtx:Matrix = new Matrix();

            /*
              var bullet:Sprite = new Sprite();
              bullet.graphics.beginFill( color );
              bullet.graphics.drawCircle( 0, 0, size );
              bullet.graphics.endFill();
            //*/

            var bullet:Dora = new Dora(1);
            temp.addChild( bullet );
            
            bullet.addEventListener( Event.ENTER_FRAME, function( e:Event ):void {
                v += 0.1;
                r += 0.03;
                vx = v * Math.cos( r );
                vy = v * Math.sin( r );
                x += vx;
                y += vy;
                mtx.tx = x;
                mtx.ty = y;
                
                canvas_bd.draw( bullet, mtx );
                
                if ( ( x < 0 ) || ( y < 0 ) || ( x > stage.stageWidth ) || ( y > stage.stageHeight ) ) {
                    bullet.removeEventListener( e.type, arguments.callee );
                    bullet.graphics.clear();
                    temp.removeChild( bullet );
                    bullet = null;
                }
            }, false, 1 );
        }
    }
}
import flash.display.*;
import flash.geom.*;

class Dora extends Sprite{
    public function Dora(num:int) { 
        var sp:Sprite = new Sprite(); 
        //sp.filters = [new GlowFilter(0xBB44BB,0.4,32,32)];
        addChild(sp);
        
        var head:Sprite = new Sprite();
        var w:Number = 94;
        var h:Number = 82;
        
        //頭を描く
        head.graphics.beginFill(0xffffff * Math.random()); 
        head.graphics.moveTo(-w/2, 0);
        head.graphics.curveTo(-w/2+2, -h/2+1, 0, -h/2);
        head.graphics.curveTo(w/2-2, -h/2+1, w/2, 0);
        head.graphics.curveTo(w/2-1, h/2-1, 0, h/2);
        head.graphics.curveTo(-w/2+1, h/2-1, -w/2, 0);  
        head.graphics.endFill();
        sp.addChild(head);
        
        //顔の輪郭を描く
        var face:Sprite = new Sprite();
        face.y = 7;
        w = 86;
        h = 67;
        face.graphics.beginFill(0x000000); 
        face.graphics.moveTo(-w/2, 0);
        face.graphics.curveTo(-w/2+2, -h/2+1, 0, -h/2);
        face.graphics.curveTo(w/2-2, -h/2+1, w/2, 0);
        face.graphics.curveTo(w/2-1, h/2-1, 0, h/2);
        face.graphics.curveTo( -w/2+1, h/2 - 1, -w / 2, 0);
        sp.addChild(face);
        
        //目を描く
        var lefteye:Sprite = new Sprite();
        lefteye.x = -17.5;
        lefteye.y = -35;
        drawOval(lefteye, 17, 19);
        sp.addChild(lefteye);
        
        var eye1:Sprite = new Sprite();
        eye1.graphics.beginFill(0x000000);
        eye1.graphics.drawEllipse(0, 0, 8, 2);
        eye1.x = -14;
        eye1.y = -27;
        sp.addChild(eye1);
        
        var righteye:Sprite = new Sprite();
        righteye.x = 0.5;
        righteye.y = -35;
        drawOval(righteye, 17, 19);
        sp.addChild(righteye);
        
        var eye2:Sprite = new Sprite();
        eye2.graphics.beginFill(0x000000);
        eye2.graphics.drawEllipse(0, 0, 8, 2);
        eye2.x = 6;
        eye2.y = -27;
        sp.addChild(eye2);
        
        //鼻を描く
        var nose:Sprite = new Sprite();
        nose.x = -5.5;
        nose.y = -20;
        drawOval(nose, 11, 9);
        sp.addChild(nose);
        
        //鼻下を描く
        var noseline:Sprite = new Sprite();
        noseline.graphics.lineStyle(1, 0xFFFFFF);
        noseline.graphics.moveTo( -0.5, -18);
        noseline.graphics.lineTo( -0.5, 24);
        sp.addChild(noseline);
        
        //口を描く
        var mouse:Sprite = new Sprite();
        mouse.graphics.lineStyle(1, 0xFFFFFF);
        mouse.graphics.moveTo( -31, 6);
        mouse.graphics.curveTo( -24, 24, 0, 24);
        mouse.graphics.curveTo(24, 24, 31, 6);
        sp.addChild(mouse);
        
        //ヒゲを描く
        var higeR:Sprite = new Sprite();
        higeR.graphics.lineStyle(1, 0xFFFFFF);
        higeR.graphics.moveTo( -16, -13);
        higeR.graphics.lineTo( -35, -16);
        higeR.graphics.moveTo( -17, -9);
        higeR.graphics.lineTo( -36, -9);
        higeR.graphics.moveTo( -16, -5);
        higeR.graphics.lineTo( -35, -2);
        sp.addChild(higeR);
        
        var higeL:Sprite = new Sprite();
        higeL.graphics.lineStyle(1, 0xFFFFFF);
        higeL.graphics.moveTo( 16, -13);
        higeL.graphics.lineTo( 35, -16);
        higeL.graphics.moveTo( 17, -9);
        higeL.graphics.lineTo( 36, -9);
        higeL.graphics.moveTo( 16, -5);
        higeL.graphics.lineTo( 35, -2);
        sp.addChild(higeL);

        var bmpd:BitmapData = new BitmapData(width, height, true, 0x00ffffff);
        var m:Matrix = new Matrix();
        m.scale(0.5, 0.5);
        m.translate(width/2, height/2);
        
        bmpd.draw(this, m);
        var b:Bitmap = addChild(new Bitmap(bmpd)) as Bitmap;
        removeChild(sp);
        sp = null;
        b.x -= width/2;
        b.y -= height/2;
        
    }
    
    private function drawOval(s:Sprite, w:Number, h:Number):void {
        s.graphics.beginFill(0xFFFFFF, 100); 
        s.graphics.moveTo(0, h/2);
        s.graphics.curveTo(0.5, 0.5, w/2, 0);
        s.graphics.curveTo(w-0.5, 0.5, w, h/2);
        s.graphics.curveTo(w-0.5, h-0.5, w/2, h);
        s.graphics.curveTo(0.5, h-0.5, 0, h/2); 
        s.graphics.endFill();
    }
    
}