Skip to content

Instantly share code, notes, and snippets.

@disjukr
Created October 17, 2012 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save disjukr/3907281 to your computer and use it in GitHub Desktop.
Save disjukr/3907281 to your computer and use it in GitHub Desktop.
drawCircle
function drawCircle( graphics:Graphics, x:Number, y:Number, radius:Number ):void
{
var k:Number = 4 / 3 * ( Math.SQRT2 - 1 );
var a:Number, b:Number, c:Number, d:Number, e:Number;
var ax:Number, bx:Number, cx:Number, dx:Number, ex:Number;
var ay:Number, by:Number, cy:Number, dy:Number, ey:Number;
e = radius;
d = k * radius;
c = 0;
b = -d;
a = -e;
ax = a + x;
bx = b + x;
cx = c + x;
dx = d + x;
ex = e + x;
ay = a + y;
by = b + y;
cy = c + y;
dy = d + y;
ey = e + y;
graphics.moveTo( cx, ay );
graphics.cubicCurveTo( dx, ay, ex, by, ex, cy );
graphics.cubicCurveTo( ex, dy, dx, ey, cx, ey );
graphics.cubicCurveTo( bx, ey, ax, dy, ax, cy );
graphics.cubicCurveTo( ax, by, bx, ay, cx, ay );
/*
//ccw in flash screen coordinate
graphics.cubicCurveTo( bx, ay, ax, by, ax, cy );
graphics.cubicCurveTo( ax, dy, bx, ey, cx, ey );
graphics.cubicCurveTo( dx, ey, ex, dy, ex, cy );
graphics.cubicCurveTo( ex, by, dx, ay, cx, ay );
*/
}
function drawCircleUsingQuadraticBezier( graphics:Graphics, x:Number, y:Number, radius:Number ):void
{
var pi:Number = Math.PI;
var a:Number, b:Number, c:Number, d:Number, e:Number, f:Number, g:Number;
var ax:Number, bx:Number, cx:Number, dx:Number, ex:Number, fx:Number, gx:Number;
var ay:Number, by:Number, cy:Number, dy:Number, ey:Number, fy:Number, gy:Number;
g = radius;
f = Math.sin( pi / 4 ) * radius;
e = Math.tan( pi / 8 ) * radius;
d = 0;
c = -e;
b = -f;
a = -g;
ax = a + x;
bx = b + x;
cx = c + x;
dx = d + x;
ex = e + x;
fx = f + x;
gx = g + x;
ay = a + y;
by = b + y;
cy = c + y;
dy = d + y;
ey = e + y;
fy = f + y;
gy = g + y;
graphics.moveTo( dx, ay );
graphics.curveTo( ex, ay, fx, by );
graphics.curveTo( gx, cy, gx, dy );
graphics.curveTo( gx, ey, fx, fy );
graphics.curveTo( ex, gy, dx, gy );
graphics.curveTo( cx, gy, bx, fy );
graphics.curveTo( ax, ey, ax, dy );
graphics.curveTo( ax, cy, bx, by );
graphics.curveTo( cx, ay, dx, ay );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment