Posted By

allnatural on 03/16/09


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Pingpongbal


Dynamically Draw A Circle


 / Published in: ActionScript 3
 

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

  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. //

Report this snippet  

You need to login to post a comment.