当前位置: 代码迷 >> Web前端 >> as代码写的风轮成效
  详细解决方案

as代码写的风轮成效

热度:248   发布时间:2012-11-01 11:11:32.0
as代码写的风轮效果
package com.nkknight.chapter1
{
        import flash.display.Bitmap;
        import flash.display.BitmapData;
        import flash.display.BlendMode;
        import flash.display.GradientType;
        import flash.display.Shader;
        import flash.display.Shape;
        import flash.display.Sprite;
        import flash.display.StageAlign;
        import flash.display.StageScaleMode;
        import flash.events.Event;
        import flash.events.MouseEvent;
        import flash.filters.GradientBevelFilter;
        import flash.geom.Matrix;
        import flash.geom.Point;
        import flash.geom.Rectangle;
        
        [SWF(backgroundColor="0x000000", width="1024", height="768", frameRate="24")]
        public class DrawGrandientFill2 extends Sprite
        {
                private var colors:Array = [0xffffff,0x888888,0x000000];
                private var alphas:Array = [1,1,1];
                private var ratios:Array = [0,127,255];
                
                private var left:Shape;
                private var top:Shape;
                private var right:Shape;
                private var bottom:Shape;
                
                private var sprite:Sprite;
                
                private var bitmap:BitmapData;
                
                private var oneM:Matrix;
                private var tM:Matrix;
                private var tM2:Matrix;
                
                private var itemWidth:Number = 200;
                private var itemHeight:Number = 50;
                
                public function DrawGrandientFill2()
                {
                        super();
                        stage.align = StageAlign.TOP_LEFT;
                        stage.scaleMode = StageScaleMode.NO_SCALE;
                        
                        init();
                }
                
                private function init():void
                {
                        bitmap = new BitmapData(itemWidth * 2, itemWidth * 2, false, 0x000000);
                        oneM = new Matrix();
                        oneM.rotate(Math.PI / 180);
                        tM = new Matrix();
                        tM.translate(itemWidth, itemWidth);
                        tM2 = new Matrix();
                        tM2.translate( - itemWidth, -itemWidth);
                        
                        render();
                        
                        sprite = new Sprite();
                        sprite.graphics.beginBitmapFill(bitmap, tM2, true);
                        sprite.graphics.drawRect( - itemWidth, -itemWidth, itemWidth*2, itemWidth*2);
                        sprite.x = 300;
                        sprite.y = 300;
                        addChild(sprite);
                        
                        this.addEventListener(Event.ENTER_FRAME, onEnter);
                }
                
                private function onEnter(evt:Event):void
                {
                        sprite.rotation += 5;
                        sprite.x = stage.mouseX;
                        sprite.y = stage.mouseY;
                }
                
                private function render():void
                {
                        drawLeft();
                        drawTop();
                        drawRight();
                        drawBottom();
                }
                
                private function drawLeft():void
                {
                        left = new Shape();
                        
                        var temp:Matrix = new Matrix();
                        temp.createGradientBox(itemWidth, itemHeight, 0, -itemWidth, -itemHeight /2);
                        
                        left.graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, temp, "pad", "rgb", 1);
                        left.graphics.drawRect(-itemWidth, -itemHeight / 2, itemWidth, itemHeight);
                        
                        bitmap.draw(left, tM, null, BlendMode.ADD, null, false);
                        left.graphics.endFill();
                        left = null;
                }
                private function drawTop():void
                {
                        top = new Shape();
                        
                        var temp:Matrix = new Matrix();
                        temp.createGradientBox(itemHeight, itemWidth, Math.PI / 2, -itemHeight / 2, -itemWidth);
                        top.graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, temp, "pad", "rgb", 1);
                        top.graphics.drawRect( -itemHeight / 2, - itemWidth, itemHeight, itemWidth);
                        
                        bitmap.draw(top, tM, null, BlendMode.ADD, null, false);
                        top.graphics.endFill();
                        top = null;
                }
                
                private function drawRight():void
                {
                        right = new Shape();
                        
                        var temp:Matrix = new Matrix();
                        temp.createGradientBox(itemWidth, itemHeight, 0, 0, - itemHeight /2);
                        right.graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, temp, "pad", "rgb", -1);
                        right.graphics.drawRect(0, -itemHeight / 2, itemWidth, itemHeight);
                        
                        bitmap.draw(right, tM, null, BlendMode.ADD, null, false);
                        right.graphics.endFill();
                        right = null;
                }
                
                private function drawBottom():void
                {
                        bottom = new Shape();
                        
                        var temp:Matrix = new Matrix();
                        temp.createGradientBox(itemHeight, itemWidth, Math.PI / 2, -itemHeight / 2, 0);
                        bottom.graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, temp, "pad", "rgb", -1);
                        bottom.graphics.drawRect( - itemHeight / 2, 0, itemHeight,itemWidth);
                        
                        bitmap.draw(bottom, tM, null, BlendMode.ADD, null, false);
                        bottom.graphics.endFill();
                        bottom = null;
                }
        }
}

?

?

  相关解决方案