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

AIR Logo Drawing

2010-04-20 23:41:24
Get Adobe Flash player
by civet 08 Jan 2016
//2010-04-20 23:41:24
package {
    import flash.display.Graphics;
    import flash.display.GradientType;
    import flash.display.SpreadMethod;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.filters.DropShadowFilter;
    import flash.geom.Matrix;
    
    public class Main extends Sprite {
    
        public function Main() {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;

            var base:Sprite = createRect(280);
            base.x = 160; 
            base.y = 160;            
            addChild(base);
            base.filters = [new DropShadowFilter(4,45,0x666666,1,8,8)];
            
            var logo:Sprite = createAIRLogo(0xffffff);
            logo.rotation = 15;
            base.addChild(logo);     
        }
        
        private static const TAN_30:Number = Math.tan(30 * Math.PI/180);
        private static const COS_30:Number = Math.cos(30 * Math.PI/180);
        private static const SIN_30:Number = .5;

        public function createAIRLogo(color:uint, r:Number=40):Sprite {
            var ptA:Object = {x: 3 * r * TAN_30, y: r};
            var ptB:Object = {x: 0, y: -2 * r};
            var ptC:Object = {x: -3 * r * TAN_30, y: r};
            var t:Number = r*r / Math.sqrt(5*r*r);            
            var pts:Array = [{x: ptA.x - t, y: ptA.y + 2*t},
                             {x: ptB.x + r, y: ptB.y},
                             {x: ptC.x - t, y: ptC.y - 2*t}];
            var cpts:Array = [{x: r * COS_30, y: -r * SIN_30},
                              {x: -r * COS_30, y: -r * SIN_30},
                              {x: 0, y: r}];

            var logo:Sprite = new Sprite();            
            var g:Graphics = logo.graphics;
            
            g.beginFill(color, 1);
            g.moveTo(pts[0].x, pts[0].y);
            arcTo(g, pts[0].x, pts[0].y, r, 180, 180 + 63.4);//trace(90 - Math.atan(0.5) /Math.PI * 180);
            g.curveTo(cpts[0].x, cpts[0].y, pts[1].x, pts[1].y);
            arcTo(g, pts[1].x, pts[1].y, r, 180, 0);
            g.curveTo(cpts[1].x, cpts[1].y, pts[2].x, pts[2].y);
            arcTo(g, pts[2].x, pts[2].y, r, 180, 90 + 26.6);//trace(Math.atan(0.5) /Math.PI * 180);
            g.curveTo(cpts[2].x, cpts[2].y, pts[0].x, pts[0].y);

            g.drawCircle(0, 0, r);
            
            return logo;
        }

        /**
         * Draw regular arc segments
         * This function is base on source code by Ric Ewing; which can be found at:
         * http://www.adobe.com/devnet/flash/articles/adv_draw_methods.html
         */
        public function arcTo(target:Graphics, x:Number, y:Number, radius:Number, arc:Number, startAngle:Number=0):void {
            var segAngle:Number, theta:Number, angle:Number, angleMid:Number, segs:Number;
            var ax:Number, ay:Number, bx:Number, by:Number, cx:Number, cy:Number;

            // if only draw regular arc, let yRadius = radius
            var yRadius:Number = radius;
            
            if (Math.abs(arc) > 360) arc = 360;
            segs = Math.ceil(Math.abs(arc)/45);
            segAngle = arc/segs;
            theta = -segAngle * Math.PI/180;
            angle = -startAngle * Math.PI/180;
            ax = x - Math.cos(angle) * radius;
            ay = y - Math.sin(angle) * yRadius;

            if (segs > 0) {
            for (var i:uint = 0; i<segs; i++) {
                     angle += theta;
                     angleMid = angle - theta/2;
                     bx = ax + Math.cos(angle) * radius;
                     by = ay + Math.sin(angle) * yRadius;
                     cx = ax + Math.cos(angleMid) * (radius/Math.cos(theta/2));
                     cy = ay +  Math.sin(angleMid) * (yRadius/Math.cos(theta/2));
                     target.curveTo(cx, cy, bx, by);
            }
            }
        }

        private function createRect(size:Number):Sprite {
            var rect:Sprite = new Sprite();
            var colors:Array = [0xff0000, 0x000000];
            var alphas:Array = [1, 1];
            var ratios:Array = [0x33, 0xFF];
            var mat:Matrix = new Matrix();
            mat.createGradientBox(size *3, size *3, 0, -size *2, -size *2);    
            rect.graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, mat, SpreadMethod.PAD);
            rect.graphics.drawRect(-size/2, -size/2, size, size);
            return rect;
        }
    }
}