Created
December 11, 2009 18:51
-
-
Save Aplusplus/254410 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function drawArc(centerX:Number, centerY:Number, startAngle:Number, endAngle:Number, radius:Number, direction:Number) | |
/* | |
centerX -- the center X coordinate of the circle the arc is located on | |
centerY -- the center Y coordinate of the circle the arc is located on | |
startAngle -- the starting angle to draw the arc from | |
endAngle -- the ending angle for the arc | |
radius -- the radius of the circle the arc is located on | |
direction -- toggle for going clockwise/counter-clockwise | |
*/ | |
{ | |
var difference:Number = Math.abs(endAngle - startAngle); | |
/* How "far" around we actually have to draw */ | |
var divisions:Number = Math.floor(difference / (Math.PI / 4))+1; | |
/* The number of arcs we are going to use to simulate our simulated arc */ | |
var span:Number = direction * difference / (2 * divisions); | |
var controlRadius:Number = radius / Math.cos(span); | |
g.moveTo(centerX + (Math.cos(startAngle)*radius), centerY + Math.sin(startAngle)*radius); | |
var controlPoint:Point; | |
var anchorPoint:Point; | |
for(var i:Number=0; i<divisions; ++i) | |
{ | |
endAngle = startAngle + span; | |
startAngle = endAngle + span; | |
controlPoint = new Point(centerX+Math.cos(endAngle)*controlRadius, centerY+Math.sin(endAngle)*controlRadius); | |
anchorPoint = new Point(centerX+Math.cos(startAngle)*radius, centerY+Math.sin(startAngle)*radius); | |
g.curveTo( | |
controlPoint.x, | |
controlPoint.y, | |
anchorPoint.x, | |
anchorPoint.y | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment