Drawing a Half-Circle

Actionscript:
  1. graphics.beginFill(0xFF0000);
  2. halfCircle(graphics, 200,200, 100);
  3. // original circle function by senocular (www.senocular.com) from here http://www.actionscript.org/forums/showthread.php3?s=&threadid=30328
  4. function halfCircle(g:Graphics, x:Number,y:Number,r:Number):void {
  5.     var c1:Number=r * (Math.SQRT2 - 1);
  6.     var c2:Number=r * Math.SQRT2 / 2;
  7.     g.moveTo(x+r,y);
  8.     g.curveTo(x+r,y+c1,x+c2,y+c2);
  9.     g.curveTo(x+c1,y+r,x,y+r);
  10.     g.curveTo(x-c1,y+r,x-c2,y+c2);
  11.     g.curveTo(x-r,y+c1,x-r,y);
  12.     // comment in for full circle
  13.     /*g.curveTo(x-r,y-c1,x-c2,y-c2);
  14.     g.curveTo(x-c1,y-r,x,y-r);
  15.     g.curveTo(x+c1,y-r,x+c2,y-c2);
  16.     g.curveTo(x+r,y-c1,x+r,y);*/
  17. };

A quick way to draw a half-circle... I used to use this to draw circles in flash before the Graphics.drawCircle() method.

This entry was posted in Graphics and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Posted December 15, 2009 at 1:50 pm | Permalink

    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/

  2. Usama Ahmed
    Posted December 21, 2009 at 3:14 am | Permalink

    Thank you. It worked for me

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*