1 // Shade plot demo.
2 
3 // Copyright (C) 1993-2001 Maurice LeBrun
4 // Copyright (C) 2000-2018 Alan W. Irwin
5 // Copyright (C) 2004 Rafael Laboissiere
6 // Copyright (C) 2007-2011 Andrew Ross
7 // Copyright (C) 2010 Hezekiah M. Carty
8 
9 #include "plcdemos.h"
10 
11 #define XPTS    35              // Data points in x
12 #define YPTS    46              // Data points in y
13 
14 PLFLT           z[XPTS][YPTS], zmin, zmax;
15 PLFLT_NC_VECTOR zIliffe[XPTS];
16 // Function prototypes
17 
18 static void     plot1( void );
19 static void     plot2( void );
20 static void     plot3( void );
21 //static void     cmap1_init1( void );
22 static void     cmap1_init2( void );
23 
24 
25 //--------------------------------------------------------------------------
26 // main
27 //
28 // Does a variety of shade plots.
29 //--------------------------------------------------------------------------
30 
31 int
main(int argc,char * argv[])32 main( int argc, char *argv[] )
33 {
34     int   i, j;
35     PLFLT xx, yy;
36 
37 // Parse and process command line arguments
38 
39     (void) plparseopts( &argc, argv, PL_PARSE_FULL );
40 
41 // Set up color map 0
42 //
43 //  plscmap0n(3);
44 //
45 // Set up color map 1
46 
47     cmap1_init2();
48 
49 // Initialize plplot
50 
51     plinit();
52 
53 // Calculate z data array that is statically allocated above.
54 
55     for ( i = 0; i < XPTS; i++ )
56     {
57         xx = (PLFLT) ( i - ( XPTS / 2 ) ) / (PLFLT) ( XPTS / 2 );
58         for ( j = 0; j < YPTS; j++ )
59         {
60             yy = (PLFLT) ( j - ( YPTS / 2 ) ) / (PLFLT) ( YPTS / 2 ) - 1.0;
61 
62             z[i][j] = xx * xx - yy * yy + ( xx - yy ) / ( xx * xx + yy * yy + 0.1 );
63         }
64     }
65 
66     // Calculate corresponding Iliffe vector, maximum, and minimum.
67     plStatic2dGrid( (PLFLT_NC_MATRIX) zIliffe, (PLFLT_VECTOR) ( &z[0][0] ), XPTS, YPTS );
68     plMinMax2dGrid( (PLFLT_MATRIX) zIliffe, XPTS, YPTS, &zmax, &zmin );
69 
70     plot1();
71     plot2();
72     plot3();
73 
74     plend();
75     exit( 0 );
76 }
77 
78 //--------------------------------------------------------------------------
79 // cmap1_init1
80 //
81 // Initializes color map 1 in HLS space.
82 //--------------------------------------------------------------------------
83 
84 //static void
85 //cmap1_init1( void )
86 //{
87 //    PLFLT i[4], h[4], l[4], s[4];
88 //
89 //    i[0] = 0;           // left boundary
90 //    i[1] = 0.45;        // just before center
91 //    i[2] = 0.55;        // just after center
92 //    i[3] = 1;           // right boundary
93 //
94 //    h[0] = 260;         // hue -- low: blue-violet
95 //    h[1] = 260;         // only change as we go over vertex
96 //    h[2] = 20;          // hue -- high: red
97 //    h[3] = 20;          // keep fixed
98 //
99 //#if 1
100 //    l[0] = 0.5;         // lightness -- low
101 //    l[1] = 0.0;         // lightness -- center
102 //    l[2] = 0.0;         // lightness -- center
103 //    l[3] = 0.5;         // lightness -- high
104 //#else
105 //    plscolbg( 255, 255, 255 );
106 //    l[0] = 0.5;         // lightness -- low
107 //    l[1] = 1.0;         // lightness -- center
108 //    l[2] = 1.0;         // lightness -- center
109 //    l[3] = 0.5;         // lightness -- high
110 //#endif
111 //    s[0] = 1;           // maximum saturation
112 //    s[1] = 1;           // maximum saturation
113 //    s[2] = 1;           // maximum saturation
114 //    s[3] = 1;           // maximum saturation
115 //
116 //    c_plscmap1l( 0, 4, i, h, l, s, NULL );
117 //}
118 
119 //--------------------------------------------------------------------------
120 // cmap1_init2
121 //
122 // Initializes color map 1 in HLS space.
123 //--------------------------------------------------------------------------
124 
125 static void
cmap1_init2(void)126 cmap1_init2( void )
127 {
128     PLFLT i[4], h[4], l[4], s[4];
129 
130     i[0] = 0;           // left boundary
131     i[1] = 0.45;        // just before center
132     i[2] = 0.55;        // just after center
133     i[3] = 1;           // right boundary
134 
135     h[0] = 260;         // hue -- low: blue-violet
136     h[1] = 260;         // only change as we go over vertex
137     h[2] = 20;          // hue -- high: red
138     h[3] = 20;          // keep fixed
139 
140 #if 1
141     l[0] = 0.6;         // lightness -- low
142     l[1] = 0.0;         // lightness -- center
143     l[2] = 0.0;         // lightness -- center
144     l[3] = 0.6;         // lightness -- high
145 #else
146     plscolbg( 255, 255, 255 );
147     l[0] = 0.5;         // lightness -- low
148     l[1] = 1.0;         // lightness -- center
149     l[2] = 1.0;         // lightness -- center
150     l[3] = 0.5;         // lightness -- high
151 #endif
152     s[0] = 1;           // saturation -- low
153     s[1] = 0.5;         // saturation -- center
154     s[2] = 0.5;         // saturation -- center
155     s[3] = 1;           // saturation -- high
156 
157     c_plscmap1l( 0, 4, i, h, l, s, NULL );
158 }
159 
160 //--------------------------------------------------------------------------
161 // plot1
162 //
163 // Illustrates a single shaded region.
164 //--------------------------------------------------------------------------
165 
166 static void
plot1(void)167 plot1( void )
168 {
169     PLFLT shade_min, shade_max, sh_color;
170     PLINT sh_cmap   = 0;
171     PLINT min_color = 0, max_color = 0;
172     PLFLT sh_width, min_width = 0., max_width = 0.;
173 
174     pladv( 0 );
175     plvpor( 0.1, 0.9, 0.1, 0.9 );
176     plwind( -1.0, 1.0, -1.0, 1.0 );
177 
178 // Plot using identity transform
179 
180     shade_min = zmin + ( zmax - zmin ) * 0.4;
181     shade_max = zmin + ( zmax - zmin ) * 0.6;
182     sh_color  = 7;
183     sh_width  = 2.;
184     min_color = 9;
185     max_color = 2;
186     min_width = 2.;
187     max_width = 2.;
188 
189     plpsty( 8 );
190     plshade( (PLFLT_MATRIX) zIliffe, XPTS, YPTS, NULL, -1., 1., -1., 1.,
191         shade_min, shade_max,
192         sh_cmap, sh_color, sh_width,
193         min_color, min_width, max_color, max_width,
194         plfill, 1, NULL, NULL );
195 
196     plcol0( 1 );
197     plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 );
198     plcol0( 2 );
199     pllab( "distance", "altitude", "Bogon flux" );
200 }
201 
202 //--------------------------------------------------------------------------
203 // plot2
204 //
205 // Illustrates multiple adjacent shaded regions, using different fill
206 // patterns for each region.
207 //--------------------------------------------------------------------------
208 
209 static void
plot2(void)210 plot2( void )
211 {
212     PLFLT        shade_min, shade_max, sh_color;
213     PLINT        sh_cmap   = 0;
214     PLINT        min_color = 0, max_color = 0;
215     PLFLT        sh_width, min_width = 0., max_width = 0.;
216     int          i;
217     static PLINT nlin[10]   = { 1, 1, 1, 1, 1, 2, 2, 2, 2, 2 };
218     static PLINT inc[10][2] = { { 450,    0 }, { -450,    0 }, { 0,   0 }, { 900,   0 },
219                                 { 300,    0 }, {  450, -450 }, { 0, 900 }, {   0, 450 },
220                                 { 450, -450 }, {    0,  900 } };
221     static PLINT del[10][2] = { { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 },
222                                 { 2000, 2000 }, { 2000, 2000 }, { 2000, 2000 },
223                                 { 2000, 2000 }, { 2000, 2000 }, { 4000, 4000 },
224                                 { 4000, 2000 } };
225 
226     sh_width = 2.;
227 
228     pladv( 0 );
229     plvpor( 0.1, 0.9, 0.1, 0.9 );
230     plwind( -1.0, 1.0, -1.0, 1.0 );
231 
232 // Plot using identity transform
233 
234     for ( i = 0; i < 10; i++ )
235     {
236         shade_min = zmin + ( zmax - zmin ) * i / 10.0;
237         shade_max = zmin + ( zmax - zmin ) * ( i + 1 ) / 10.0;
238         sh_color  = i + 6;
239         plpat( nlin[i], inc[i], del[i] );
240 
241         plshade( (PLFLT_MATRIX) zIliffe, XPTS, YPTS, NULL, -1., 1., -1., 1.,
242             shade_min, shade_max,
243             sh_cmap, sh_color, sh_width,
244             min_color, min_width, max_color, max_width,
245             plfill, 1, NULL, NULL );
246     }
247 
248     plcol0( 1 );
249     plbox( "bcnst", 0.0, 0, "bcnstv", 0.0, 0 );
250     plcol0( 2 );
251     pllab( "distance", "altitude", "Bogon flux" );
252 }
253 
254 //--------------------------------------------------------------------------
255 // plot3
256 //
257 // Illustrates shaded regions in 3d, using a different fill pattern for
258 // each region.
259 //--------------------------------------------------------------------------
260 
261 static void
plot3(void)262 plot3( void )
263 {
264     static PLFLT xx[2][5] = { { -1.0, 1.0, 1.0, -1.0, -1.0 },
265                               { -1.0, 1.0, 1.0, -1.0, -1.0 } };
266     static PLFLT yy[2][5] = { {  1.0,  1.0, 0.0, 0.0,  1.0 },
267                               { -1.0, -1.0, 0.0, 0.0, -1.0 } };
268     static PLFLT zz[2][5] = { { 0.0, 0.0, 1.0, 1.0, 0.0 },
269                               { 0.0, 0.0, 1.0, 1.0, 0.0 } };
270 
271     pladv( 0 );
272     plvpor( 0.1, 0.9, 0.1, 0.9 );
273     plwind( -1.0, 1.0, -1.0, 1.0 );
274     plw3d( 1., 1., 1., -1.0, 1.0, -1.0, 1.0, 0.0, 1.5, 30, -40 );
275 
276 // Plot using identity transform
277 
278     plcol0( 1 );
279     plbox3( "bntu", "X", 0.0, 0, "bntu", "Y", 0.0, 0, "bcdfntu", "Z", 0.5, 0 );
280     plcol0( 2 );
281     pllab( "", "", "3-d polygon filling" );
282 
283     plcol0( 3 );
284     plpsty( 1 );
285     plline3( 5, xx[0], yy[0], zz[0] );
286     plfill3( 4, xx[0], yy[0], zz[0] );
287     plpsty( 2 );
288     plline3( 5, xx[1], yy[1], zz[1] );
289     plfill3( 4, xx[1], yy[1], zz[1] );
290 }
291