graphics.beginFill(0xFF0000);
halfCircle(graphics, 200,200, 100);
// original circle function by senocular (www.senocular.com) from here http://www.actionscript.org/forums/showthread.php3?s=&threadid=30328
function halfCircle(g:Graphics, x:Number,y:Number,r:Number):void {
var c1:Number=r * (Math.SQRT2 - 1);
var c2:Number=r * Math.SQRT2 / 2;
g.moveTo(x+r,y);
g.curveTo(x+r,y+c1,x+c2,y+c2);
g.curveTo(x+c1,y+r,x,y+r);
g.curveTo(x-c1,y+r,x-c2,y+c2);
g.curveTo(x-r,y+c1,x-r,y);
// comment in for full circle
/*g.curveTo(x-r,y-c1,x-c2,y-c2);
g.curveTo(x-c1,y-r,x,y-r);
g.curveTo(x+c1,y-r,x+c2,y-c2);
g.curveTo(x+r,y-c1,x+r,y);*/
};
A quick way to draw a half-circle… I used to use this to draw circles in flash before the Graphics.drawCircle() method.
Thank you for source code. With your code i was able to draw half-circles(fill lowlight, fill highlight) for my RoundButtonSkin component.
Mariush T.
http://mariusht.com/blog/
Thank you. It worked for me
I adapted this to draw any of the 8 halfCircles starting from multiples of 45 degrees.
public static function halfCircle(g:Graphics, x:Number,y:Number,r:Number, startAngle:int):void {
var c1:Number=r * (Math.SQRT2 – 1);
var c2:Number = r * Math.SQRT2 / 2;
var start:int = ((startAngle +360) % 360) / 45;
var controlX:Number;
var controlY:Number;
var anchorX:Number;
var anchorY:Number;
for (var i:int = start; i < start + 5; i++) { switch (i % 8) { case 0: controlX = x + r; controlY = y - c1; anchorX = x + r; anchorY = y; break; case 1: controlX = x + r; controlY = y + c1; anchorX = x + c2; anchorY = y + c2; break; case 2: controlX = x + c1; controlY = y + r; anchorX = x; anchorY = y + r; break; case 3: controlX = x - c1; controlY = y + r; anchorX = x - c2; anchorY = y + c2; break; case 4: controlX = x - r; controlY = y + c1; anchorX = x - r; anchorY = y; break; case 5: controlX = x - r; controlY = y - c1; anchorX = x - c2; anchorY = y - c2; break; case 6: controlX = x - c1; controlY = y - r; anchorX = x; anchorY = y - r; break; case 7: controlX = x + c1; controlY = y - r; anchorX = x + c2; anchorY = y - c2; break; } if (i == start) { g.moveTo(anchorX, anchorY); } else { g.curveTo(controlX, controlY, anchorX, anchorY); } } }