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

ろうそくの炎をcurveToで表現してみた。

エフェクト頼みで、curveToではやめた方が良いという結論。
Get Adobe Flash player
by kawamura 15 Oct 2010
    Embed
/**
 * Copyright kawamura ( http://wonderfl.net/user/kawamura )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/foZq
 */

package {
    import flash.display.MovieClip;
    import flash.display.Shape;
    import flash.display.Graphics;
    import flash.display.GradientType;
    import flash.display.SpreadMethod;
    import flash.display.InterpolationMethod;
    import flash.geom.Matrix;
    import flash.filters.BlurFilter;
    import flash.filters.GlowFilter;
    import flash.events.Event;
    import flash.display.Shape;
    import com.bit101.components.PushButton;
    import flash.events.MouseEvent;
    [SWF(backgroundColor = "#000000",frameRate="60")]
    public class FlashTest extends MovieClip {
        private var fire:Shape;
        private var center:Shape;
        private var p:Array=[[0,-150],[5,-110],[15,-76], [29,-45], [27,-26], [25,0]]
        private var g:Graphics;
        private var cnt:Number = 0;
        private var parm_gf:GlowFilter;
        private var parm_bf:BlurFilter
        private var parm_c:BlurFilter
        
        public function FlashTest () {
            // constructor code
            fire=new Shape();
            addChild (fire);
            fire.x = stage.stageWidth * 0.5;
            fire.y = stage.stageHeight * 0.5;
            g = fire.graphics;
            g.beginGradientFill (GradientType.LINEAR,[0xFFEE99 , 0xfffe6e,0x0033FF],[1, 0.6,0.3],[80,100,120],new Matrix(0 , 0.2 ,0.2 , 0 ,0 , 0),SpreadMethod.PAD,InterpolationMethod.LINEAR_RGB,0.0);
            g.moveTo (p[0][0],p[0][1]);
            g.curveTo (p[1][0],p[1][1],p[2][0],p[2][1]);
            g.curveTo (p[3][0],p[3][1],p[4][0],p[4][1]);
            g.curveTo (p[5][0],p[5][1],0,0);
            g.curveTo (-1*p[5][0],p[5][1],-1*p[4][0],p[4][1]);
            g.curveTo (-1*p[3][0],p[3][1],-1*p[2][0],p[2][1]);
            g.curveTo (-1*p[1][0],p[1][1],p[0][0],p[0][1]);
            g.endFill ();
            /**/
            parm_gf=new flash.filters.GlowFilter();
            parm_gf.blurX = 20;
            parm_gf.blurY = 20;
            parm_bf=new flash.filters.BlurFilter();
            parm_bf.blurX = 10;
            fire.filters = new Array(parm_gf,parm_bf);
            //
            center=new Shape();
            addChild (center);
            center.x = fire.x;
            center.y = fire.y;
            var c_g:Graphics = center.graphics;
            c_g.beginGradientFill (GradientType.LINEAR,[0xCC0000 , 0x000000],[ 0.2 , 0.1],[100, 125],new Matrix(0 , 0.2,0.2 , 0 ,0 , 0),SpreadMethod.PAD,InterpolationMethod.LINEAR_RGB,0.0);
            c_g.moveTo (0,-60);
            c_g.curveTo (15,-10,0,0);
            c_g.curveTo (-15,-10,0,-60);
            c_g.endFill ();
            parm_c=new flash.filters.BlurFilter();
            parm_c.blurX = 5;
            center.filters = new Array(parm_c);
            //ローソク部分 よろしくちゃん
            var rousoku:Shape=new Shape();
            var rousoku_g:Graphics=rousoku.graphics;
            rousoku_g.beginFill (0xFF0000);
            rousoku_g.drawRect (-50,0,100,300);
            rousoku.x = stage.stageWidth * 0.5;
            rousoku.y = stage.stageHeight * 0.5 + 10;
            addChild (rousoku);
            //
            var btn:PushButton=new PushButton();
            btn.label="effect";
            addChild(btn);
            btn.x=5;
            btn.y=5;
            btn.addEventListener(MouseEvent.CLICK,clk);
            //
            addEventListener (Event.ENTER_FRAME,ent);
            
        }
        private function clk(evt:MouseEvent):void{
            if(fire.filters.length>0){
                fire.filters = null;
                center.filters = null;
            }else{
                fire.filters = new Array(parm_gf,parm_bf);
                center.filters = new Array(parm_c);
            }
        }

        private function ent (evt:Event):void {
            cnt +=  0.4;
            var d:Number = 0.8 * Math.cos(cnt);
            var dd:Number = 0.8 * Math.cos(cnt + 0.2 * Math.PI);
            g.clear ();
            //
            g.beginGradientFill (GradientType.LINEAR,[0xFFEE99 , 0xfffe6e,0x0033FF],[1, 0.6,0.1],[80,100,120],new Matrix(0 , 0.2 ,0.2 , 0 ,0 , 0),SpreadMethod.PAD,InterpolationMethod.LINEAR_RGB,0.0);
            //
            g.moveTo (p[0][0]-d*0.2,p[0][1]);
            g.curveTo (p[1][0]+d,p[1][1],p[2][0]+d,p[2][1]);
            g.curveTo (p[3][0]-d*0.8,p[3][1],p[4][0]-d*0.8,p[4][1]);
            g.curveTo (p[5][0],p[5][1],0,0);
            g.curveTo (-1*p[5][0],p[5][1],-1*p[4][0]-dd*0.8,p[4][1]);
            g.curveTo (-1*p[3][0]-dd*0.8,p[3][1],-1*p[2][0]+dd,p[2][1]);
            g.curveTo (-1*p[1][0]+dd,p[1][1],p[0][0]-dd*0.2,p[0][1]);
            //
            fire.scaleY=1.0+0.008*Math.sin(cnt);
            center.scaleY=1.0+0.004*Math.sin(cnt);
            if(cnt>2*Math.PI){
                cnt-=2*Math.PI;
            }
        }
    }
}



//