Attachment 't42.c'

Download

   1 // t42.c
   2 // v0.1 KHL 2009-04-21
   3 // gcc -o t42 t42.c -lm -lgd ; ./t42
   4 // static drawing, though slow to compute
   5 // earth and toroid around orbit
   6 
   7 #define TITLE    ""
   8 #define GIFOUT   "t42.gif"
   9 #define RADIUS   500.00
  10 #define SQUARE    10.00
  11 #define SCALE    0.5
  12 
  13 #include "tor00.hc"
  14 
  15 
  16 // oregon data -----------------
  17 
  18 int     orpoint         ;
  19 double  orscale         ;
  20 double  orcentx, orcenty ;  // oregon center
  21 double  orx[3000]       ;  // point array for oregon overlay
  22 double  ory[3000]       ;  // point array for oregon overlay
  23 gdPoint ors[3000]       ;  // scaled point array for oregon overlay
  24 
  25 FILE    *orfile;                            // oregon outline data file
  26 
  27 
  28 // read in oregon outline data ---------------------
  29 
  30 #define  OR_FILE     "OR.xy"
  31 #define  ORWIDE       645.0                 // Oregon width for scaling data
  32  
  33 FILE    *orfile;                            // oregon outline data file
  34 
  35 // ------------------------------------------------------------------------
  36 
  37 void or_readin() {
  38    double  orx1, ory1   ;
  39    double  orxmin= 1000.0 ;
  40    double  orxmax=-1000.0 ;
  41    double  orymin= 1000.0 ;
  42    double  orymax=-1000.0 ;
  43    int     orcnt;
  44 
  45    orfile  = fopen( OR_FILE, "r" );
  46    orpoint = 0 ;
  47    while( EOF != fscanf( orfile, "%lf%lf\n", &orx1, &ory1 ) ) {
  48       orx[orpoint] = orx1 ;
  49       ory[orpoint] = ory1 ;
  50       orpoint++ ;
  51       if ( orxmin > orx1 ) { orxmin = orx1 ; } 
  52       if ( orxmax < orx1 ) { orxmax = orx1 ; } 
  53       if ( orymin > ory1 ) { orymin = ory1 ; } 
  54       if ( orymax < ory1 ) { orymax = ory1 ; } 
  55    }
  56    orscale =  ORWIDE / ( orxmax - orxmin ) ;     // kilometers per input point
  57    orcentx = ( orxmin + orxmax ) / 2.0 ;
  58    orcenty = ( orymin + orymax ) / 2.0 ;
  59    
  60    // scale and normalize data to kilometers
  61    for( orcnt = 0; orcnt<orpoint ; orcnt++ ) {
  62       orx[orcnt] = orscale*( orx[orcnt] - orcentx );
  63       ory[orcnt] = orscale*( ory[orcnt] - orcenty );
  64    }
  65    fclose( orfile );
  66 }
  67 
  68 // draw oregon outline  ---------------------
  69 
  70 void draworegon( int xcent, int ycent, double scale ) {
  71 
  72    int     orcnt ;
  73 
  74    for( orcnt = 0 ; orcnt < orpoint ; orcnt++ ) {
  75       ors[orcnt].x = xcent + scale*orx[orcnt]  ;
  76       ors[orcnt].y = ycent - scale*ory[orcnt]  ;
  77       printf( "%5d%8d%8d%9.3f%9.3f\n",
  78          orcnt, ors[orcnt].x, ors[orcnt].y, orx[orcnt], ory[orcnt] ) ;
  79    }
  80    gdImageFilledPolygon( im, ors, orpoint, green ) ;
  81 }
  82 
  83 // ------------------------------------------------------------------------
  84 
  85 int main () {
  86    int     diam = (int) ( 2.0 * SCALE * RADIUS );
  87    double  rmax = (RADIUS/SQUARE)-0.51 ;
  88    int     ymax = (int) rmax ;
  89    int     xmax   ;
  90    int     delta = (int) ( SCALE * SQUARE + 0.001 );
  91    int     sq    = (delta / 2) - 1 ;
  92    int     num = 0 ;
  93    int     xp, yp ;
  94    int     ycent = YCENTER - 25 ;
  95    int     xcent = XCENTER ;
  96    double  scale = SCALE   ;                // pixels per kilometer
  97 
  98    or_readin();
  99 
 100    displaystart();
 101    torstart();
 102    gdImageGifAnimBegin( im1, gifout, 1, -1 ) ; // no repeat
 103    // gdImageGifAnimBegin( im1, gifout, 1,  4 ) ; // repeat 4 times
 104    // gdImageGifAnimBegin( im1, gifout, 1,  0 ) ; // continuous repeat
 105    framestart(    90, TITLE );
 106 
 107    gdImageFilledEllipse( im, xcent, ycent, diam, diam, white );
 108 
 109    for( yp = -ymax ; yp <= ymax ; yp++ ) {
 110       xmax = (int) sqrt( rmax*rmax - (double) (yp*yp) );
 111       int y = yp*delta + ycent ;
 112       for( xp = -xmax ; xp <= xmax ; xp++ ) { 
 113          int x = xp*delta + xcent ;
 114          num++ ;
 115          gdImageFilledRectangle( im, x-sq, y-sq, x+sq, y+sq, black );
 116       }
 117    }
 118    draworegon ( xcent, ycent, scale );
 119 
 120    sprintf( bottom, "" );
 121 
 122    frameend();
 123    displayend();
 124    return 0;
 125 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2009-05-12 03:45:56, 11.6 KB) [[attachment:ap01.c]]
  • [get | view] (2009-05-12 20:57:15, 11.1 KB) [[attachment:ap02.c]]
  • [get | view] (2021-06-19 05:05:20, 853.5 KB) [[attachment:ap02.png]]
  • [get | view] (2009-05-11 08:39:41, 1.4 KB) [[attachment:t01.c]]
  • [get | view] (2009-05-11 02:49:58, 14.3 KB) [[attachment:t01.gif]]
  • [get | view] (2009-05-11 08:39:31, 4.0 KB) [[attachment:t04.c]]
  • [get | view] (2009-05-11 02:50:13, 24.3 KB) [[attachment:t04.gif]]
  • [get | view] (2009-05-11 08:39:10, 4.0 KB) [[attachment:t08.c]]
  • [get | view] (2009-05-11 02:50:25, 29.6 KB) [[attachment:t08.gif]]
  • [get | view] (2009-05-11 02:53:25, 34.8 KB) [[attachment:t12.gif]]
  • [get | view] (2009-05-11 08:38:55, 4.0 KB) [[attachment:t16.c]]
  • [get | view] (2009-05-11 02:53:12, 38.0 KB) [[attachment:t16.gif]]
  • [get | view] (2009-05-11 08:38:44, 4.0 KB) [[attachment:t20.c]]
  • [get | view] (2009-05-11 02:52:57, 39.6 KB) [[attachment:t20.gif]]
  • [get | view] (2009-05-11 08:38:32, 4.0 KB) [[attachment:t24.c]]
  • [get | view] (2009-05-11 02:52:39, 44.0 KB) [[attachment:t24.gif]]
  • [get | view] (2009-05-11 08:37:48, 4.0 KB) [[attachment:t25.c]]
  • [get | view] (2009-05-11 02:52:29, 41.5 KB) [[attachment:t25.gif]]
  • [get | view] (2009-05-11 08:38:21, 3.4 KB) [[attachment:t26.c]]
  • [get | view] (2009-05-11 02:52:12, 28.0 KB) [[attachment:t26.gif]]
  • [get | view] (2009-05-11 08:37:25, 2.5 KB) [[attachment:t27.c]]
  • [get | view] (2009-05-11 02:51:59, 25.8 KB) [[attachment:t27.gif]]
  • [get | view] (2009-05-11 08:37:13, 2.5 KB) [[attachment:t28.c]]
  • [get | view] (2009-05-11 02:51:34, 18.5 KB) [[attachment:t28.gif]]
  • [get | view] (2009-05-11 08:37:01, 1.4 KB) [[attachment:t41.c]]
  • [get | view] (2009-05-11 02:51:19, 11.4 KB) [[attachment:t41.gif]]
  • [get | view] (2009-05-11 08:36:46, 3.6 KB) [[attachment:t42.c]]
  • [get | view] (2009-05-11 02:50:49, 5.3 KB) [[attachment:t42.gif]]
  • [get | view] (2009-05-11 08:36:31, 13.4 KB) [[attachment:tor00.hc]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.