topical media & game development

talk show tell print

actionscript-book-AlgorithmicVisualGenerator-com-example-programmingas3-algorithmic-Satellite.ax

actionscript-book-AlgorithmicVisualGenerator-com-example-programmingas3-algorithmic-Satellite.ax [swf] flex


  package 
  {
          import flash.display.Shape;
          
          public class @ax-actionscript-book-AlgorithmicVisualGenerator-com-example-programmingas3-algorithmic-Satellite extends Shape {
                  public var position:Number;
                  public var color:uint;
                  public var radius:Number;
                  public var orbitRadius:Number;
                  
                  public function @ax-actionscript-book-AlgorithmicVisualGenerator-com-example-programmingas3-algorithmic-Satellite(position:Number,color:uint) {
                          this.position = position;
                          this.color = color;
                  }
                  public function draw(useAlphaEffect:Boolean = false):void {
                          var radians:Number = getRadians(position);
                          var posX:Number = Math.sin(radians) * orbitRadius;
                          var posY:Number = Math.cos(radians) * orbitRadius;
                          graphics.clear();
                          graphics.beginFill(color);
                          graphics.drawCircle(posX, posY, radius);
  
                          alpha = useAlphaEffect ? Math.abs(Math.sin(radians)) : 1;
                  }
                  private function getRadians(degrees:Number):Number {
                          return degrees * Math.PI / 180;
                  }
                  private function getDegrees(radians:Number):uint {
                          return Math.round(180 * radians / Math.PI)
                  }                
          }
  }


(C) Æliens 27/08/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.