## Posted By

MaRmAR on 11/29/10

## Who likes this?

3 people have marked this snippet as a favorite

# AS3: Circle pie

/ Published in: ActionScript 3

Copy&paste into new document and move your mouse.

`[SWF(width=400,height=400,backgroundColor=0xEFEFEF,frameRate=30)]Ã‚Â const TWO_PI:Number = Math.PI * 2;Ã‚Â var resolution:Number = 50;var step:Number = TWO_PI / resolution;var maxIndex:int = 0;Ã‚Â var coords:Vector.<Number> = new Vector.<Number>();var drawCommands:Vector.<int> = new Vector.<int>();Ã‚Â // populate vectorsfor (var i:Number = 0; i <TWO_PI + step; i += step){Ã‚Â  Ã‚Â  coords.push(100 * Math.cos(i));Ã‚Â  Ã‚Â  coords.push(100 * Math.sin(i));Ã‚Â  Ã‚Â  drawCommands.push(GraphicsPathCommand.LINE_TO);}Ã‚Â var circleSegment:Shape = new Shape();circleSegment.x = circleSegment.y = 200;addChild(circleSegment);Ã‚Â 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));Ã‚Â  Ã‚Â  }}`

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));
}
``````

}*/

import caurina.transitions.Tweener;

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

``````    // count by two, up to coords.length (drawCommands is exactly half the length of coords)