Posted By

adrianparr on 12/06/11


Tagged

pi load circle chart Fill progress as3 pie segment animate


Versions (?)

AS3 Pie Chart


 / Published in: ActionScript 3
 

URL: http://snipplr.com/view.php?codeview&id=45022

Credit goes to http://snipplr.com/users/MaRmAR/

  1. [SWF(width=400,height=400,backgroundColor=0xEFEFEF,frameRate=30)]
  2.  
  3. const TWO_PI:Number = Math.PI * 2;
  4.  
  5. var resolution:Number = 50;
  6. var step:Number = TWO_PI / resolution;
  7. var maxIndex:int = 0;
  8.  
  9. var coords:Vector.<Number> = new Vector.<Number>();
  10. var drawCommands:Vector.<int> = new Vector.<int>();
  11.  
  12. for (var i:Number = 0; i <TWO_PI + step; i += step){
  13. coords.push(100 * Math.cos(i));
  14. coords.push(100 * Math.sin(i));
  15. drawCommands.push(GraphicsPathCommand.LINE_TO);
  16. }
  17.  
  18. var circleSegment:Shape = new Shape();
  19. circleSegment.rotation = -90;
  20. circleSegment.x = circleSegment.y = 200;
  21. addChild(circleSegment);
  22.  
  23. addEventListener(Event.ENTER_FRAME, onLoop);
  24. function onLoop(evt:Event):void {
  25. with (circleSegment.graphics) {
  26. clear();
  27. beginFill(0x000000);
  28. maxIndex = Math.ceil((mouseX / stage.stageWidth)  * drawCommands.length) * 2;
  29. drawPath(drawCommands, coords.slice(0, maxIndex));
  30. }
  31. }

Report this snippet  

You need to login to post a comment.