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.You are not allowed to attach a file to this page.