Debian Codegraph @

texmf-dist/doc/latex/metaplot/examples/metacontour_main.cc

raw
1 /* MetaContour, version 0.1 -------------------------------------- */
2 /* Copyright(C) 2004, Brooks Moses */
3 /* */
4 /* This version of MetaContour is made available under the Gnu */
5 /* Public License; see below for details. */
6 /* */
7 /* This is a very pre-release version of MetaContour, distributed */
8 /* primarily as an example of a use of MetaPlot. It can be */
9 /* compiled with gcc using the line: */
10 /* */
11 /* g++ metacontour.cc cpoint.cc metacontour_main.cc */
12 /* */
13 /*-----------------------------------------------------------------*/
14
15 // This program is free software; you can redistribute it and/or
16 // modify it under the terms of the GNU General Public License
17 // as published by the Free Software Foundation; either version 2
18 // of the License, or (at your option) any later version.
19 //
20 // This program is distributed in the hope that it will be useful,
21 // but WITHOUT ANY WARRANTY; without even the implied warranty of
22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 // GNU General Public License for more details.
24 //
25 // You should have received a copy of the GNU General Public License
26 // along with this program; if not, write to the Free Software
27 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28
29
30 #include<string>
31 #include<vector>
32 #include<iostream>
33 #include<cmath>
34 #include"metacontour.h"
35 using namespace std;
36
37 int main() {
38 int il = 21;
39 int jl = 11;
40 double pi = atan(1.0)*4.0;
41
42 cparray GridData(il,jl);
43
44 for (int i=0; i<il; i++) {
45 double theta = 2.0 * pi * double(i) / (il-1.0);
46 for (int j=0; j<jl; j++) {
47 double r = 1.5 * (double(j)/(jl-1.0))*(double(j)/(jl-1.0)) + 0.03;
48
49 double x = - r * cos(theta);
50 double y = r * sin(theta);
51
52 double z = (-0.5 * log(r)) + x;
53
54 GridData(i,j) = cpoint(0.5*(x+1.0),0.5*(y+1.0),z);
55 }
56 }
57
58 vector<double> ContourList(31);
59
60 cout << "color contourcolor[];\n";
61 for (int k=0; k<31; k++) {
62 ContourList[k] = 0.1 * k - 1.0;
63 cout << "contourcolor[" << k << "] = " << (1.0 - k/50.0) << "white;\n";
64 }
65
66 string PlotName = "contplotA";
67
68 MetapostContours testplot(GridData, ContourList, PlotName);
69
70 cout << '\n' << testplot.Grid();
71 cout << testplot.LinePlot();
72 cout << testplot.FillPlot();
73
74 }
75