Revision: 36893
Updated Code
at July 12, 2011 23:08 by MaRmAR
Updated Code
[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 vectors
for (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));
  }
}
Revision: 36892
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 29, 2010 21:30 by MaRmAR
Initial Code
[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 vectors
for (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));
  }
}
Initial URL
Initial Description
Copy&paste into new document and move your mouse.
Initial Title
AS3: Circle pie
Initial Tags
Initial Language
ActionScript 3