1 //--------------------------------------------------------------------------
2 // Copyright (C) 2004 Andrew Ross
3 // Copyright (C) 2004 Alan W. Irwin
4 //
5 // This file is part of PLplot.
6 //
7 // PLplot is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU Library General Public License as published by
9 // the Free Software Foundation; version 2 of the License.
10 //
11 // PLplot is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Library General Public License for more details.
15 //
16 // You should have received a copy of the GNU Library General Public License
17 // along with PLplot; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 //--------------------------------------------------------------------------
20 //
21 //--------------------------------------------------------------------------
22 // Implementation of PLplot example 12 in C++.
23 //--------------------------------------------------------------------------
24
25 #include "plc++demos.h"
26
27 #ifdef PL_USE_NAMESPACE
28 using namespace std;
29 #endif
30
31 class x12 {
32 public:
33 x12( int, char ** );
34 void plfbox( PLFLT, PLFLT );
35 private:
36 plstream *pls;
37
38 static const PLFLT y0[];
39
40 static PLFLT pos[], red[], green[], blue[];
41 };
42
43 const PLFLT x12::y0[10] = { 5., 15., 12., 24., 28., 30., 20., 8., 12., 3. };
44
45 PLFLT x12:: pos[] = { 0.0, 0.25, 0.5, 0.75, 1.0 };
46 PLFLT x12:: red[] = { 0.0, 0.25, 0.5, 1.0, 1.0 };
47 PLFLT x12:: green[] = { 1.0, 0.5, 0.5, 0.5, 1.0 };
48 PLFLT x12:: blue[] = { 1.0, 1.0, 0.5, 0.25, 0.0 };
49
x12(int argc,char ** argv)50 x12::x12( int argc, char **argv )
51 {
52 int i;
53 char string[20];
54
55 pls = new plstream();
56
57 // Parse and process command line arguments.
58
59 pls->parseopts( &argc, argv, PL_PARSE_FULL );
60
61
62 // Initialize plplot.
63
64 pls->init();
65
66
67
68 pls->adv( 0 );
69 pls->vsta();
70 pls->wind( 1980.0, 1990.0, 0.0, 35.0 );
71 pls->box( "bc", 1.0, 0, "bcnv", 10.0, 0 );
72 pls->col0( 2 );
73 pls->lab( "Year", "Widget Sales (millions)", "#frPLplot Example 12" );
74
75 pls->scmap1l( true, 5, pos, red, green, blue, NULL );
76
77 for ( i = 0; i < 10; i++ )
78 {
79 //pls->col0(i + 1);
80 pls->col1( i / 9.0 );
81 pls->psty( 0 );
82 plfbox( ( 1980. + i ), y0[i] );
83 sprintf( string, "%.0f", y0[i] );
84 pls->ptex( ( 1980. + i + .5 ), ( y0[i] + 1. ), 1.0, 0.0, .5, string );
85 sprintf( string, "%d", 1980 + i );
86 pls->mtex( "b", 1.0, ( ( i + 1 ) * .1 - .05 ), 0.5, string );
87 }
88 //pls->end();
89 delete pls;
90 }
91
plfbox(PLFLT x0,PLFLT y0)92 void x12::plfbox( PLFLT x0, PLFLT y0 )
93 {
94 PLFLT *x = new PLFLT[4];
95 PLFLT *y = new PLFLT[4];
96
97 x[0] = x0;
98 y[0] = 0.;
99 x[1] = x0;
100 y[1] = y0;
101 x[2] = x0 + 1.;
102 y[2] = y0;
103 x[3] = x0 + 1.;
104 y[3] = 0.;
105 pls->fill( 4, x, y );
106 pls->col0( 1 );
107 pls->lsty( 1 );
108 pls->line( 4, x, y );
109
110 delete[] x;
111 delete[] y;
112 }
113
114
115
main(int argc,char ** argv)116 int main( int argc, char **argv )
117 {
118 x12 *x = new x12( argc, argv );
119
120 delete x;
121 }
122
123
124 //--------------------------------------------------------------------------
125 // End of x12.cc
126 //--------------------------------------------------------------------------
127