# Posted By

MaRmAR on 11/29/10

# Statistics

Viewed 50 times
Favorited by 2 user(s)

# AS3: Circle pie

/ Published in: ActionScript 3

Copy&paste into new document and move your mouse.

Copy this code and paste it in your HTML
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;
22. Ã‚Â
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. }