// t41.c
// v0.1 KHL 2009-04-21
// gcc -o t41 t41.c -lm -lgd ; ./t41
// static drawing, though slow to compute
// earth and toroid around orbit

#define TITLE    "Orbit map, 500km minor radius"
#define GIFOUT   "t41.gif"
#define RADIUS   500.00
#define SQUARE    10.00
#define SCALE    0.5

#include "tor00.hc"

int main () {
   int     diam = (int) ( 2.0 * SCALE * RADIUS );
   double  rmax = (RADIUS/SQUARE)-0.51 ;
   int     ymax = (int) rmax ;
   int     xmax   ;
   int     delta = (int) ( SCALE * SQUARE + 0.001 );
   int     sq    = (delta / 2) - 1 ;
   int     num = 0 ;
   int     xp, yp ;
   int     ycent = YCENTER - 25 ;

   displaystart();
   torstart();
   gdImageGifAnimBegin( im1, gifout, 1, -1 ) ; // no repeat
   // gdImageGifAnimBegin( im1, gifout, 1,  4 ) ; // repeat 4 times
   // gdImageGifAnimBegin( im1, gifout, 1,  0 ) ; // continuous repeat
   framestart(    90, TITLE );

   gdImageFilledEllipse( im, XCENTER, ycent, diam, diam, white );

   for( yp = -ymax ; yp <= ymax ; yp++ ) {
      xmax = (int) sqrt( rmax*rmax - (double) (yp*yp) );
      int y = yp*delta + ycent ;
      for( xp = -xmax ; xp <= xmax ; xp++ ) { 
         int x = xp*delta + XCENTER ;
         num++ ;
         gdImageFilledRectangle( im, x-sq, y-sq, x+sq, y+sq, black );
      }
  }
  sprintf( bottom, "%6d orbits,%3.0fkm spacing between orbits", num, SQUARE );

  frameend();
  displayend();
  return 0;
}
