## 12 February 2010

### Math, charts and Algorithmists

One of my favorite ActionScript bloggers must be The Algorithmist because he is also an mathematician and you can learn a lot about programming by understanding the problem; sometimes reading/repeating Flash tutorials is just not enough.

Even very old stuff on blog are useful, check download section and, for example as2 wedge class file. This is not open source file, so you'll have to download it by yourself. This is a pie-shaped wedge drawing class using a quad. Bezier as a primitive.

In order to create entire pie like image shows use next code:

`var xC:Number = 100;var yC:Number = 100;var rad1:Number = 50;var start1:Number = -Math.PI/2;var end1:Number = Math.PI/4;var mc1:MovieClip = this.createEmptyMovieClip("mc1", 1);var wedge1:Wedge = new Wedge(rad1, xC, yC, start1, end1);wedge1.draw(mc1, 1, 0x000000, 0x0000ff, 50);var rad2:Number = 50;var start2:Number = Math.PI/4;var end2:Number = 3*Math.PI/4;var mc2:MovieClip = this.createEmptyMovieClip("mc2", 2);var wedge2:Wedge = new Wedge(rad2, xC, yC, start2, end2);wedge2.draw(mc2, 1, 0x000000, 0x660066, 50);var rad3:Number = 50;var start3:Number = 3*Math.PI/4;var end3:Number = Math.PI;var mc3:MovieClip = this.createEmptyMovieClip("mc3", 3);var wedge3:Wedge = new Wedge(rad3, xC, yC, start3, end3);wedge3.draw(mc3, 1, 0x000000, 0x666600, 50);var rad4:Number = 50;var start4:Number = Math.PI;var end4:Number = 3*Math.PI/2;var mc4:MovieClip = this.createEmptyMovieClip("mc4", 4);var wedge4:Wedge = new Wedge(rad4, xC, yC, start4, end4);wedge4.draw(mc4, 1, 0x000000, 0x222200, 50);`

However if you want to create interactive charts you should probably use something like Open Flash Charts or Flex Charts.

*_*

Steven said...

For AS3, I think you're looking for something like this for drawing partial circles:
http://www.flashandmath.com/howtos/circlefill/

Steven said...

Another AS3 Wedge. This one loops less than the one from FlashAndMath, but I don't think it's as accurate.
http://theflashblog.com/?p=430