[7849] | 1 | package charts.Elements {
|
---|
| 2 | import charts.Elements.PointDotBase;
|
---|
| 3 | import flash.display.BlendMode;
|
---|
| 4 | import flash.display.Graphics;
|
---|
| 5 | import flash.display.Sprite;
|
---|
| 6 |
|
---|
| 7 | public class Star extends PointDotBase {
|
---|
| 8 |
|
---|
| 9 | public function Star( index:Number, style:Object ) {
|
---|
| 10 |
|
---|
| 11 | super( index, style );
|
---|
| 12 |
|
---|
| 13 | this.visible = true;
|
---|
| 14 |
|
---|
| 15 | this.graphics.clear();
|
---|
| 16 | this.graphics.lineStyle( style.width, style.colour, 1);// style.alpha );
|
---|
| 17 | var rotation:Number = isNaN(style['rotation']) ? 0 : style['rotation'];
|
---|
| 18 |
|
---|
| 19 | this.drawStar( this.graphics, style['dot-size'], rotation );
|
---|
| 20 |
|
---|
| 21 | var haloSize:Number = style['halo-size']+style['dot-size'];
|
---|
| 22 | var s:Sprite = new Sprite();
|
---|
| 23 | s.graphics.lineStyle( 0, 0, 0 );
|
---|
| 24 | s.graphics.beginFill( 0, 1 );
|
---|
| 25 | this.drawStar(s.graphics, haloSize, rotation );
|
---|
| 26 | s.blendMode = BlendMode.ERASE;
|
---|
| 27 | s.graphics.endFill();
|
---|
| 28 | this.line_mask = s;
|
---|
| 29 |
|
---|
| 30 | this.attach_events();
|
---|
| 31 |
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | private function calcXOnCircle(radius:Number, degrees:Number):Number
|
---|
| 35 | {
|
---|
| 36 | return radius * Math.cos(degrees / 180 * Math.PI);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | private function calcYOnCircle(radius:Number, degrees:Number):Number
|
---|
| 40 | {
|
---|
| 41 | return radius * Math.sin(degrees / 180 * Math.PI);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | private function drawStar( graphics:Graphics, radius:Number, rotation:Number ):void
|
---|
| 45 | {
|
---|
| 46 | var angle:Number = 360 / 5;
|
---|
| 47 |
|
---|
| 48 | // Start at top point (unrotated)
|
---|
| 49 | var degrees:Number = -90 + rotation;
|
---|
| 50 | for (var i:int = 0; i <= 5; i++)
|
---|
| 51 | {
|
---|
| 52 | var x:Number = this.calcXOnCircle(radius, degrees);
|
---|
| 53 | var y:Number = this.calcYOnCircle(radius, degrees);
|
---|
| 54 |
|
---|
| 55 | if (i == 0)
|
---|
| 56 | graphics.moveTo(x, y);
|
---|
| 57 | else
|
---|
| 58 | graphics.lineTo(x, y);
|
---|
| 59 |
|
---|
| 60 | // Move 2 points clockwise
|
---|
| 61 | degrees += (2 * angle);
|
---|
| 62 | }
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|