topical media & game development

talk show tell print

animation-ch19-Random7.ax

animation-ch19-Random7.ax [swf] [flash] flex


  package {
          import flash.display.Sprite;
          import flash.events.Event;
          import flash.display.StageAlign;
          import flash.display.StageScaleMode;
  
          public class @ax-animation-ch19-Random7 extends Sprite
          {
                  private var numDots:uint = 300;
                  private var maxRadius:Number = 50;
                  private var iterations:uint = 6;
                  
                  public function @ax-animation-ch19-Random7()
                  {
                          init();
                  }
                  
                  private function init():void
                  {
                          stage.align = StageAlign.TOP_LEFT;
                          stage.scaleMode = StageScaleMode.NO_SCALE;
                          
                          for(var i:uint = 0; i < numDots; i++)
                          {
                                  var dot:animation_ch19_Ball = new animation_ch19_Ball(1, 0);
                                  var xpos:Number = 0;
                                  for(var j:uint = 0; j < iterations; j++)
                                  {
                                          xpos += Math.random() * stage.stageWidth;
                                  }
                                  dot.x = xpos / iterations;
  
                                  var ypos:Number = 0;
                                  for(j = 0; j < iterations; j++)
                                  {
                                          ypos += Math.random() * stage.stageHeight;
                                  }
                                  dot.y = ypos / iterations;
                                  addChild(dot);
                          }
                  }
          }
  }
  


(C) Æliens 04/09/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.