Gerard-Meier

Random wormhole position test

Jun 1st, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package
  2. {
  3.     import flash.display.Sprite;
  4.     import flash.events.Event;
  5.     import flash.geom.Point;
  6.    
  7.     public class Main extends Sprite
  8.     {
  9.         public var starSystems:Array = new Array();
  10.        
  11.         public function Main():void
  12.         {
  13.             // Create new starsystems:
  14.             for (var i:int = 0; i < 5; ++i) {
  15.                 addChild(starSystems[i] = new StarSystem(i, this));
  16.             }
  17.            
  18.             // Add a bunch of neighbours:
  19.             (starSystems[0] as StarSystem).addNeighbourIndex(1);
  20.             (starSystems[0] as StarSystem).addNeighbourIndex(2);
  21.            
  22.             (starSystems[1] as StarSystem).addNeighbourIndex(1);
  23.             (starSystems[1] as StarSystem).addNeighbourIndex(2);
  24.            
  25.             (starSystems[2] as StarSystem).addNeighbourIndex(0);
  26.             (starSystems[2] as StarSystem).addNeighbourIndex(1);
  27.            
  28.             (starSystems[3] as StarSystem).addNeighbourIndex(1);
  29.             (starSystems[3] as StarSystem).addNeighbourIndex(2);
  30.            
  31.             (starSystems[4] as StarSystem).addNeighbourIndex(2);
  32.             (starSystems[4] as StarSystem).addNeighbourIndex(3);
  33.            
  34.             // What it looks like in ascii art:
  35.             //
  36.             //     0-----1------2--- 4
  37.             //     |     |      |    |
  38.             //      ------------|    |
  39.             //           3------|-----
  40.            
  41.             // Random radii:
  42.             for each(var star:StarSystem in starSystems) {
  43.                 star.largeRadius = Math.random() * 40 + 10;
  44.             }
  45.            
  46.             var radii:Array = new Array();
  47.            
  48.             for each(var star2:StarSystem in starSystems) {
  49.                
  50.                
  51.                 outerLoop:
  52.                 do {
  53.                     star2.x = Math.random() * 300;
  54.                     star2.y = Math.random() * 300;
  55.                    
  56.                     for each(var meh:StarSystem in radii) {
  57.                         var a:Point = new Point(star2.x, star2.y);
  58.                         var b:Point = new Point(meh.x, meh.y);
  59.                        
  60.                         trace(a.length, "<", (meh.largeRadius + star2.largeRadius / 2));
  61.                        
  62.                         if (Point.distance(a, b) < (meh.largeRadius + star2.largeRadius)) {
  63.                             trace("again");
  64.                             continue outerLoop;
  65.                         }
  66.                     }
  67.                    
  68.                     radii.push(star2);
  69.                     break;
  70.                 } while (true);
  71.             }
  72.            
  73.             for each(var star3:StarSystem in starSystems) {
  74.                 star3.draw();
  75.             }
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment