Attachment 'sh01.c'

Download

   1 // sh01.c
   2 //
   3 // compile with:       cc -o sh01 sh01.c -lgd -lpng -lm
   4 //
   5 // uses the libgd library.  for documentation see the file:
   6 //   /usr/share/doc/gd-*/index.html  
   7 //   or the website:   http://www.libgd.org/reference
   8 //  
   9 // you will need truetype fonts.  if you don't have them, you can
  10 // copy ../fonts/truetype/.. from openoffice.org to /usr/share/
  11 // libgd origin at upper left
  12 
  13 #include "gd.h"
  14 #include "math.h"
  15 #include "string.h"
  16 #include <stdio.h>
  17 #include <stdlib.h>
  18 
  19 #define  PNGFMT      "sh01.png"
  20 
  21 #define  X0          300          // start of deploy
  22 
  23 #define  Y0          300      
  24 #define  S0L0        20
  25 #define  S1L0        20
  26 #define  SFX0         0
  27 #define  SX0         10
  28 #define  SD0         20
  29 
  30 #define  Y1          580
  31 #define  S0L1        15
  32 #define  S1L1        25
  33 #define  SFX1         5
  34 #define  SX1         10
  35 #define  SD1         30
  36 
  37 #define  Y2          860
  38 #define  S0L2        10
  39 #define  S1L2        30
  40 #define  SFX2        10
  41 #define  SX2         10
  42 #define  SD2         40
  43 
  44 #define  Y3          1140
  45 #define  S0L3        10
  46 #define  S1L3        30
  47 #define  SFX3        40
  48 #define  SX3         50
  49 #define  SD3        120
  50 
  51 #define  SH          100          // height of shell
  52 #define  SHNUM       20
  53 #define  SHTHICK     9
  54 #define  SHEDGE      1
  55 
  56 #define  XSIZE       2560         // display window in pixels
  57 #define  YSIZE       1280
  58 
  59 #define  PI          3.14159265358979324
  60 #define  D2R         (PI/180.0)
  61 #define  R2D         (180.0/PI)
  62 #define  FNT         "DejaVuMonoSans"
  63 
  64 // draw a shell =============================================================
  65 
  66 void  tshell( gdImagePtr im, int xl, int yc, int l, int col) {
  67    // xl  == left side of the shell
  68    // yc  == center of the shell
  69    // l   == length of the shell from center
  70    // col == shell color
  71 
  72    double hh = (double) SH;
  73    double ll = (double) l;
  74    double  r = 0.5*( ll + hh*hh/ll ) ;
  75    double an = R2D*asin( hh / r );
  76    int    ri = (int) r ;
  77    int    ex = xl + l + SHTHICK/2 - ri ;
  78 
  79    // printf( "%5d%5d%5d%8d%5d%12.3f\n", xl, yc, l,  ri, ex, an );
  80 
  81    gdImageSetThickness( im, SHTHICK );
  82    gdImageArc(  im, ex, yc, 2*ri, 2*ri, 360-an, 360+an, col );
  83    // gdImageSetThickness( im, SHEDGE  );
  84    // gdImageLine( im, xl, yc+SH-SHTHICK, xl, yc-SH, col );
  85 }
  86 
  87 // draw a stack of shells ===================================================
  88 
  89 void  tstack( gdImagePtr im, int ycl, int s0l, int s1l, int sfx,
  90              int sx, int sd, int col0, int col1, int col2, int col3 ) {
  91 
  92    // printf( "\n%8d%8d%8d%12d%8d\n", ycl, s0l, s1l, sx, sd );
  93 
  94    int i ;
  95    for( i = SHNUM-1 ; i >= 0 ; i-- ) {
  96       tshell( im, i*sd+X0+sfx+sx, ycl, s1l, col1) ;
  97       tshell( im, i*sd+X0+sfx   , ycl, s0l, col0) ;
  98    }
  99 
 100    // base
 101    for( i = -3 ; i < 0 ; i++ ) {
 102       tshell( im, i*SHTHICK+X0, ycl, S0L0, col2) ;
 103    }
 104    gdImageFilledRectangle( im, X0-30, ycl-SH, X0-10, ycl+SH, col2 );
 105    gdImageFilledRectangle( im, X0-80, ycl-SH, X0-30, ycl+SH, col3 );
 106    gdImageFilledRectangle( im, X0-170, ycl-SH, X0-80, ycl+SH, col2 );
 107    gdImageFilledArc( im, X0-270, ycl, 250, 100, 270, 450, col2, gdArc );
 108 }
 109 
 110 // ==========================================================================
 111 
 112 int main() {
 113 
 114    FILE     *pngout              ; // file handle for png output frame
 115    char     labstring[80]        ; // used for labelling
 116    int      fs                   ; // large font size
 117 
 118    gdImagePtr im = gdImageCreateTrueColor(XSIZE, YSIZE );
 119 
 120    // allocate standard colors
 121    int black = gdImageColorAllocate(im,   0,   0,   0);
 122    int white = gdImageColorAllocate(im, 255, 255, 255);
 123    int sun1  = gdImageColorAllocate(im,  51,  51, 102);
 124    int red   = gdImageColorAllocate(im, 255,   0,   0);
 125    int green = gdImageColorAllocate(im,   0, 255,   0);
 126    int dgreen= gdImageColorAllocate(im,   0, 128,   0);
 127    int blue  = gdImageColorAllocate(im,   0,   0, 255);
 128    int gray  = gdImageColorAllocate(im, 128, 128, 128);
 129    int dgray = gdImageColorAllocate(im,  48,  48,  48);
 130    int yelo  = gdImageColorAllocate(im, 230, 230, 100);
 131    int trans = gdImageColorAllocate(im,   1,   1,   1);
 132 
 133    // white background 
 134    gdImageFilledRectangle( im, 0, 0, XSIZE-1, YSIZE-1, white );
 135    
 136    tstack( im, Y0, S0L0, S1L0, SFX0, SX0, SD0, green, blue, gray, yelo ) ;
 137    tstack( im, Y1, S0L1, S1L1, SFX0, SX1, SD1, green, blue, gray, yelo ) ;
 138    tstack( im, Y2, S0L2, S1L2, SFX2, SX2, SD2, green, blue, gray, yelo ) ;
 139    tstack( im, Y3, S0L3, S1L3, SFX3, SX3, SD3, green, blue, gray, yelo ) ;
 140 
 141    fs= 80 ;
 142    gdImageStringFT( im, NULL,           // imagespace, bounding box
 143       black , FNT, fs, 0.0,             // color, font, fontsize, angle
 144       XSIZE-23*fs, 120,                 // x, y
 145       "Belleville Spring Deployment" ); // text
 146    
 147    fs= 64 ;
 148    gdImageStringFT( im, NULL,           // imagespace, bounding box
 149       black , FNT, fs, 0.0,             // color, font, fontsize, angle
 150       XSIZE-19*fs, 320,                 // x, y
 151       "Two thinsat curvatures,"      ); // text
 152 
 153    gdImageStringFT( im, NULL,           // imagespace, bounding box
 154       black , FNT, fs, 0.0,             // color, font, fontsize, angle
 155       XSIZE-19*fs, 440,                 // x, y
 156       "  compressed together,"       ); // text
 157 
 158    gdImageStringFT( im, NULL,           // imagespace, bounding box
 159       black , FNT, fs, 0.0,             // color, font, fontsize, angle
 160       XSIZE-19*fs, 560,                 // x, y
 161       "   create spring force"       ); // text
 162 
 163    fs= 50 ;
 164    gdImageStringFT( im, NULL,           // imagespace, bounding box
 165       black , FNT, fs, 0.0,             // color, font, fontsize, angle
 166       XSIZE/2-10*fs, 300,               // x, y
 167       "Solid Stack"                  ); // text
 168 
 169    gdImageStringFT( im, NULL,           // imagespace, bounding box
 170       black , FNT, fs, 0.0,             // color, font, fontsize, angle
 171       XSIZE/2-10*fs, 380,               // x, y
 172       "For Launch"                   ); // text
 173 
 174 
 175    // output the frame ------------------------------------------------------
 176 
 177    pngout = fopen( PNGFMT, "wb");
 178    gdImagePngEx( im, pngout, 1 );
 179    gdImageDestroy(im);
 180    fclose(pngout);
 181 }

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] (2013-02-12 15:26:57, 228.9 KB) [[attachment:A0_title.jpg]]
  • [get | view] (2013-02-12 15:35:39, 912.5 KB) [[attachment:B0_serversatV3a.png]]
  • [get | view] (2013-02-12 15:36:48, 1976.2 KB) [[attachment:C0_world_marble.png]]
  • [get | view] (2013-02-12 15:36:23, 1602.0 KB) [[attachment:C3_energy.png]]
  • [get | view] (2013-02-12 15:33:18, 469.6 KB) [[attachment:E0_m288xx.png]]
  • [get | view] (2013-02-12 15:32:48, 59.2 KB) [[attachment:E3_crosser.png]]
  • [get | view] (2013-02-12 15:32:06, 405.6 KB) [[attachment:H0_toroid.png]]
  • [get | view] (2013-02-12 15:34:51, 97.8 KB) [[attachment:I0_echrome.png]]
  • [get | view] (2013-02-12 15:34:08, 356.0 KB) [[attachment:J3_turn_tidal.png]]
  • [get | view] (2013-02-12 15:33:46, 281.9 KB) [[attachment:K0_lighteccentric.png]]
  • [get | view] (2013-02-12 15:31:33, 454.9 KB) [[attachment:M0_temperature.png]]
  • [get | view] (2013-02-12 15:35:14, 101.8 KB) [[attachment:M3_deploy.png]]
  • [get | view] (2013-02-12 15:30:15, 700.1 KB) [[attachment:Q0_phasedarray.png]]
  • [get | view] (2013-02-12 15:29:44, 466.0 KB) [[attachment:Q3_arrayspace.png]]
  • [get | view] (2013-02-12 15:31:06, 488.4 KB) [[attachment:R0_radiation.png]]
  • [get | view] (2013-02-12 15:30:42, 281.4 KB) [[attachment:R3_radiation.png]]
  • [get | view] (2013-02-12 15:27:28, 506.1 KB) [[attachment:S0_costdrop.png]]
  • [get | view] (2013-02-12 15:28:49, 3693.6 KB) [[attachment:U0_radar.png]]
  • [get | view] (2013-02-12 15:27:55, 416.5 KB) [[attachment:U3_rocketbody.png]]
  • [get | view] (2013-02-16 04:59:50, 14.8 KB) [[attachment:a6.c]]
  • [get | view] (2013-02-16 04:59:58, 14.6 KB) [[attachment:a7.c]]
  • [get | view] (2013-02-16 03:52:04, 16.9 KB) [[attachment:ar06.c]]
  • [get | view] (2013-02-15 23:11:57, 1.7 KB) [[attachment:crosser.gp]]
  • [get | view] (2013-02-15 23:11:40, 2.3 KB) [[attachment:crosser.pl]]
  • [get | view] (2013-02-16 04:30:17, 2.0 KB) [[attachment:darkside0.gp]]
  • [get | view] (2013-02-16 15:28:29, 2.3 KB) [[attachment:darkside0.pl]]
  • [get | view] (2013-02-16 03:38:30, 9.3 KB) [[attachment:echrome04.c]]
  • [get | view] (2013-02-16 15:29:15, 5.7 KB) [[attachment:insertrb.pl]]
  • [get | view] (2013-02-16 15:37:24, 1.9 KB) [[attachment:lj2.gp]]
  • [get | view] (2013-02-16 15:37:08, 2.3 KB) [[attachment:lj2.pl]]
  • [get | view] (2013-02-16 04:14:19, 5.1 KB) [[attachment:orbit04w.c]]
  • [get | view] (2013-02-16 04:19:08, 9.1 KB) [[attachment:pa03.c]]
  • [get | view] (2013-02-16 04:19:19, 9.1 KB) [[attachment:pa04.c]]
  • [get | view] (2013-02-12 18:22:40, 5.3 KB) [[attachment:pc02.c]]
  • [get | view] (2013-02-16 15:29:37, 2.0 KB) [[attachment:rb.gp]]
  • [get | view] (2013-02-16 02:50:27, 6.0 KB) [[attachment:sh01.c]]
  • [get | view] (2013-02-13 23:22:32, 13918.1 KB) [[attachment:ss.pdf]]
  • [get | view] (2013-02-13 23:21:58, 23.3 KB) [[attachment:ss.tex]]
  • [get | view] (2013-02-16 04:07:31, 24.1 KB) [[attachment:ss6a.c]]
  • [get | view] (2013-02-16 04:12:13, 3.4 KB) [[attachment:tor08.c]]
 All files | Selected Files: delete move to page

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