AS2 Draw Circle

/ Published in: ActionScript
Save to your folder(s)

I recently has to work on an AS2 project (yuk) and create circles dynamically. Here is a handy function for this.

Copy this code and paste it in your HTML
  1. drawCircle(this, 300, 300, 16, 0x0000FF);
  3. function drawCircle(mc:MovieClip, x:Number, y:Number, r:Number, color:Number):Void {
  4. mc.beginFill(color);
  5. mc.moveTo(x+r, y);
  6. mc.curveTo(r+x, Math.tan(Math.PI/8)*r+y, Math.sin(Math.PI/4)*r+x,
  7. Math.sin(Math.PI/4)*r+y);
  8. mc.curveTo(Math.tan(Math.PI/8)*r+x, r+y, x, r+y);
  9. mc.curveTo(-Math.tan(Math.PI/8)*r+x, r+y, -Math.sin(Math.PI/4)*r+x,
  10. Math.sin(Math.PI/4)*r+y);
  11. mc.curveTo(-r+x, Math.tan(Math.PI/8)*r+y, -r+x, y);
  12. mc.curveTo(-r+x, -Math.tan(Math.PI/8)*r+y, -Math.sin(Math.PI/4)*r+x,
  13. -Math.sin(Math.PI/4)*r+y);
  14. mc.curveTo(-Math.tan(Math.PI/8)*r+x, -r+y, x, -r+y);
  15. mc.curveTo(Math.tan(Math.PI/8)*r+x, -r+y, Math.sin(Math.PI/4)*r+x,
  16. -Math.sin(Math.PI/4)*r+y);
  17. mc.curveTo(r+x, -Math.tan(Math.PI/8)*r+y, r+x, y);
  18. mc.endFill();
  19. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.