Draw an Arc inside a Square


/ Published in: ActionScript 3

Draws arc on the inner side of the square (all sides).


Copy this code and paste it in your HTML
  1. var rect:Rectangle = new Rectangle( 100, 100, 200, 150 );
  2. var mc:MovieClip = new MovieClip();
  3.  
  4. // draw Arc 1
  5. mc.graphics.beginFill(0x00FF00, 1);
  6.  
  7. mc.graphics.moveTo(rect.x, rect.y);
  8. mc.graphics.lineTo(rect.x + (rect.width / 2), rect.y);
  9. mc.graphics.curveTo(rect.x, rect.y, rect.x, rect.y + (rect.height / 2));
  10. // draw arc 2
  11. mc.graphics.moveTo(rect.x + rect.width, rect.y);
  12. mc.graphics.lineTo(rect.x + (rect.width / 2), rect.y);
  13. mc.graphics.curveTo(rect.x + rect.width, rect.y, rect.x + rect.width, rect.y + (rect.height / 2));
  14. // draw arc 3
  15. mc.graphics.moveTo(rect.x + rect.width, rect.y + rect.height);
  16. mc.graphics.lineTo(rect.x + rect.width, rect.y + (rect.height / 2));
  17. mc.graphics.curveTo(rect.x + rect.width, rect.y + rect.height, rect.x + (rect.width / 2), rect.y + rect.height);
  18. // draw arc 4
  19. mc.graphics.moveTo(rect.x, rect.y + rect.height);
  20. mc.graphics.lineTo(rect.x, rect.y + (rect.height / 2));
  21. mc.graphics.curveTo(rect.x, rect.y + rect.height, rect.x + (rect.width / 2), rect.y + rect.height);
  22. mc.graphics.endFill();
  23.  
  24. addChild( mc )

URL: http://www.manmeng.net

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.