Dynamically Draw A Circle


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



Copy this code and paste it in your HTML
  1. /
  2. function magicTrigFunctionX (pointRatio){
  3. return Math.cos(pointRatio*2*Math.PI);
  4. }
  5. function magicTrigFunctionY (pointRatio){
  6. return Math.sin(pointRatio*2*Math.PI);
  7. }
  8. //
  9. function drawCircle(centerX, centerY, radius, sides){
  10. //
  11. // Move the pen to the first point on the circle.
  12. this.moveTo(centerX + radius, centerY);
  13. //
  14. for(var i=0; i<=sides; i++){
  15. var pointRatio = i/sides;
  16. var xSteps = magicTrigFunctionX(pointRatio);
  17. var ySteps = magicTrigFunctionY(pointRatio);
  18. var pointX = centerX + xSteps * radius;
  19. var pointY = centerY + ySteps * radius;
  20. this.lineTo(pointX, pointY);
  21. }
  22. }
  23. //
  24. lineStyle(0);
  25. //
  26. drawCircle(250, 250, 200, 100);
  27. //

URL: http://www.pixelwit.com/blog

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.