forked from: forked from: How can I draw a circle with dashed line/stroke?

by aobyrne forked from forked from: How can I draw a circle with dashed line/stroke? (diff: 13)
Hi! Why don't you use the DrawArc class below?

How can I draw a circle with dashed line/stroke?
Using a for cycle and using the equation of the circle wouldn't it be too slow?
♥0 | Line 68 | Modified 2011-11-19 18:48:51 | MIT License
play

ActionScript3 source code

/**
 * Copyright aobyrne ( http://wonderfl.net/user/aobyrne )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/prPy
 */

// forked from SoWhat1983's forked from: How can I draw a circle with dashed line/stroke?
// Hi! Why don't you use the DrawArc class below?

// forked from maesy's How can I draw a circle with dashed line/stroke?
//How can I draw a circle with dashed line/stroke?
//Using a for cycle and using the equation of the circle wouldn't it be too slow?
package {
    import flash.geom.Point;
    import flash.display.Sprite;
    import flash.display.Shape;
    import flash.display.LineScaleMode;
    import flash.display.CapsStyle;
    import flash.display.JointStyle;

    public class DashedCircle extends Sprite {
        private var shape:Shape;
        private var theRadius:Number = 100;
        private var c:Point=new Point(200,200);
        private var r:Number = 40;
        public function DashedCircle() {
           circle();
        }
        
        private function circle():void{
            shape = new Shape();
            shape.graphics.beginFill(0xFFcccc, 1);
            //Can i set a dashed line style?
//        shape.graphics.lineStyle(2, 0x000000, 1, true, LineScaleMode.NONE, CapsStyle.SQUARE, JointStyle.MITER, 3);
        shape.graphics.drawCircle(c.x, c.y, theRadius);
        shape.graphics.endFill();
//            this.addChild(shape);
//            shape.x = stage.stageWidth/2;
//            shape.y = stage.stageHeight/2;
            
            
            var dashedCircle:Sprite = new Sprite();
            var arcAngle:Number            =  4;
            var dashedLineColor:uint       =  0;
            var dashedLineThickness:Number =  4;
            
            dashedCircle.addChild(shape);
            for(var i:Number=0;i<360/(arcAngle*2);i++){
                var a:drawArc = new drawArc(c.x,c.y,theRadius,i*(arcAngle*2),arcAngle,0x000000,dashedLineThickness,dashedLineColor);
                dashedCircle.addChild(a);
            }
            //dashedCircle.x=dashedCircle.y=stage.stageWidth/2;
            addChild(dashedCircle);
            for(var ii:int=1;ii<10+1;ii++)addChild(new drawArc((r*1.1)*(ii-1), r, r, 0, 18*ii, 0xffffff, 1, 0));
            for(var iik:int=1;iik<10+1;iik++)addChild(new drawArc((r*1.1)*(iik-1), r, r, 0, -18*iik, 0xffffff, 1, 0));
        }
    }
}


import flash.display.*;
class drawArc extends Sprite
{ 
    public function drawArc(baseX:Number, baseY:Number, radius:Number, startAngle:Number, arcAngle:Number, fillColor:uint,lineThickness:Number,lineColor:uint):void {
        
        var yRadius:Number = radius;
        
        var segAngle:Number, theta:Number, angle:Number, angleMid:Number, segs:Number, ax:Number, ay:Number, bx:Number, by:Number, cx:Number, cy:Number, return_arr:Array;
        
        segs = Math.ceil(Math.abs(arcAngle)/45);
        segAngle = arcAngle/segs;
        
        theta = -(segAngle/180)*Math.PI;
        angle = -(startAngle/180)*Math.PI;
        
        // angle += theta;
        
        ax = baseX;
        ay = baseY;
        angleMid = angle-(theta/2);
        bx = ax+Math.cos(angle)*radius;
        by = ay+Math.sin(angle)*yRadius;
        
        with(graphics){
            beginFill(fillColor);
            lineStyle(lineThickness,lineColor);
//            moveTo(0,0); 
//            lineTo(bx, by);
            moveTo(bx, by);
        }
        
        
        if (segs>0) {
            for (var i:int = 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));
                graphics.curveTo(cx, cy, bx, by);
            }
        }
//        graphics.lineTo(0,0); 
    };
}

Forked