Posted By

MaRmAR on 11/29/10


Tagged

circle chart draw pie segment


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

tspitzr
burnandbass
alptugan


AS3: Circle pie


 / Published in: ActionScript 3
 

Copy&paste into new document and move your mouse.

  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. // populate vectors
  13. for (var i:Number = 0; i <TWO_PI + step; i += step){
  14.     coords.push(100 * Math.cos(i));
  15.     coords.push(100 * Math.sin(i));
  16.     drawCommands.push(GraphicsPathCommand.LINE_TO);
  17. }
  18.  
  19. var circleSegment:Shape = new Shape();
  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.        
  29.         // count by two, up to coords.length (drawCommands is exactly half the length of coords)
  30.         maxIndex =  Math.ceil((mouseX / stage.stageWidth)  * drawCommands.length) * 2;
  31.  
  32.         drawPath(drawCommands, coords.slice(0, maxIndex));
  33.     }
  34. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: burnandbass on December 3, 2010

Here is some mod to make it use Tweener:

Comment:

/*addEventListener(Event.ENTER_FRAME, onLoop); function onLoop(evt:Event):void { with (circleSegment.graphics) { clear(); beginFill(0x000000);

    // count by two, up to coords.length (drawCommands is exactly half the length of coords)
    maxIndex =  Math.ceil((mouseX / stage.stageWidth)  * drawCommands.length) * 2;

    drawPath(drawCommands, coords.slice(0, maxIndex));
}

}*/

and add:

import caurina.transitions.Tweener;

var numProxy:Object = {}; numProxy.numValue = 0

Tweener.addTween(numProxy, {numValue:100, time:6, onUpdate:draww, transition:"easeInQuad"})

function draww(e:Event = null):void{ with (circleSegment.graphics) { clear(); beginFill(0x000000);

    // count by two, up to coords.length (drawCommands is exactly half the length of coords)
    maxIndex =  Math.ceil((numProxy.numValue/100)  * drawCommands.length) * 2;

    drawPath(drawCommands, coords.slice(0, maxIndex));
}

}

You need to login to post a comment.