Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package
- {
- import flash.display.Sprite;
- import flash.events.Event;
- import flash.geom.Point;
- public class Main extends Sprite
- {
- public var starSystems:Array = new Array();
- public function Main():void
- {
- // Create new starsystems:
- for (var i:int = 0; i < 5; ++i) {
- addChild(starSystems[i] = new StarSystem(i, this));
- }
- // Add a bunch of neighbours:
- (starSystems[0] as StarSystem).addNeighbourIndex(1);
- (starSystems[0] as StarSystem).addNeighbourIndex(2);
- (starSystems[1] as StarSystem).addNeighbourIndex(1);
- (starSystems[1] as StarSystem).addNeighbourIndex(2);
- (starSystems[2] as StarSystem).addNeighbourIndex(0);
- (starSystems[2] as StarSystem).addNeighbourIndex(1);
- (starSystems[3] as StarSystem).addNeighbourIndex(1);
- (starSystems[3] as StarSystem).addNeighbourIndex(2);
- (starSystems[4] as StarSystem).addNeighbourIndex(2);
- (starSystems[4] as StarSystem).addNeighbourIndex(3);
- // What it looks like in ascii art:
- //
- // 0-----1------2--- 4
- // | | | |
- // ------------| |
- // 3------|-----
- // Random radii:
- for each(var star:StarSystem in starSystems) {
- star.largeRadius = Math.random() * 40 + 10;
- }
- var radii:Array = new Array();
- for each(var star2:StarSystem in starSystems) {
- outerLoop:
- do {
- star2.x = Math.random() * 300;
- star2.y = Math.random() * 300;
- for each(var meh:StarSystem in radii) {
- var a:Point = new Point(star2.x, star2.y);
- var b:Point = new Point(meh.x, meh.y);
- trace(a.length, "<", (meh.largeRadius + star2.largeRadius / 2));
- if (Point.distance(a, b) < (meh.largeRadius + star2.largeRadius)) {
- trace("again");
- continue outerLoop;
- }
- }
- radii.push(star2);
- break;
- } while (true);
- }
- for each(var star3:StarSystem in starSystems) {
- star3.draw();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment