1
//--------------------------------------------------------------------------
2
// $Id: x08.java 11301 2010-11-02 17:21:08Z airwin $
3
//--------------------------------------------------------------------------
5
//--------------------------------------------------------------------------
6
// Copyright (C) 2001 Geoffrey Furnish
7
// Copyright (C) 2001, 2002, 2003, 2004 Alan W. Irwin
8
// Copyright (C) 2002 Maurice LeBrun
9
// Copyright (C) 2002 Joao Cardoso
10
// Copyright (C) 2004 Andrew Ross
12
// This file is part of PLplot.
14
// PLplot is free software; you can redistribute it and/or modify
15
// it under the terms of the GNU Library General Public License as published by
16
// the Free Software Foundation; version 2 of the License.
18
// PLplot is distributed in the hope that it will be useful,
19
// but WITHOUT ANY WARRANTY; without even the implied warranty of
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
// GNU Library General Public License for more details.
23
// You should have received a copy of the GNU Library General Public License
24
// along with PLplot; if not, write to the Free Software
25
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26
//--------------------------------------------------------------------------
28
//--------------------------------------------------------------------------
29
// Implementation of PLplot example 8 in Java.
30
//--------------------------------------------------------------------------
32
package plplot.examples;
36
import java.lang.Math;
39
static final int XPTS = 35;
40
static final int YPTS = 46;
42
PLStream pls = new PLStream();
44
static double alt[] = { 60.0, 20.0 };
45
static double az[] = { 30.0, 60.0 };
47
static String[] title =
49
"#frPLplot Example 8 - Alt=60, Az=30",
50
"#frPLplot Example 8 - Alt=20, Az=60",
54
// Initializes color map 1 in HLS space.
55
// Basic grayscale variation from half-dark (which makes more interesting
56
// looking plot compared to dark) to light.
57
// An interesting variation on this:
60
void cmap1_init( int gray )
62
double [] i = new double[2];
63
double [] h = new double[2];
64
double [] l = new double[2];
65
double [] s = new double[2];
66
boolean [] rev = new boolean[2];
68
i[0] = 0.0; // left boundary
69
i[1] = 1.0; // right boundary
73
h[0] = 0.0; // hue -- low: red (arbitrary if s=0)
74
h[1] = 0.0; // hue -- high: red (arbitrary if s=0)
76
l[0] = 0.5; // lightness -- low: half-dark
77
l[1] = 1.0; // lightness -- high: light
79
s[0] = 0.0; // minimum saturation
80
s[1] = 0.0; // minimum saturation
84
h[0] = 240; // blue -> green -> yellow ->
94
rev[0] = false; // interpolate on front side of colour wheel.
95
rev[1] = false; // interpolate on front side of colour wheel.
98
pls.scmap1l( false, i, h, l, s, rev );
101
// Does a series of 3-d plots for a given data set, with different viewing
102
// options in each plot.
104
public static void main( String[] args )
109
public x08( String[] args )
112
final int LEVELS = 10;
114
double[] x = new double[ XPTS ];
115
double[] y = new double[ YPTS ];
116
double[][] z = new double[XPTS][YPTS];
117
double clevel[] = new double[LEVELS];
118
double clev_null [] = new double[0];
121
double zmin = Double.MAX_VALUE, zmax = Double.MIN_VALUE;
125
// Parse and process command line arguments.
127
pls.parseopts( args, PLStream.PL_PARSE_FULL | PLStream.PL_PARSE_NOPROGRAM );
128
boolean rosen = true;
130
// Initialize plplot.
134
for ( i = 0; i < XPTS; i++ )
136
x[i] = (double) ( i - ( XPTS / 2 ) ) / (double) ( XPTS / 2 );
141
for ( j = 0; j < YPTS; j++ )
143
y[j] = (double) ( j - ( YPTS / 2 ) ) / (double) ( YPTS / 2 );
148
for ( i = 0; i < XPTS; i++ )
151
for ( j = 0; j < YPTS; j++ )
156
z[i][j] = Math.pow( 1. - xx, 2. ) + 100 *
157
Math.pow( yy - Math.pow( xx, 2. ), 2. );
158
// The log argument may be zero for just the right grid.
160
z[i][j] = Math.log( z[i][j] );
162
z[i][j] = -5.; // -MAXFLOAT would mess-up up the scale
166
r = Math.sqrt( xx * xx + yy * yy );
167
z[i][j] = Math.exp( -r * r ) * Math.cos( 2.0 * Math.PI * r );
169
if ( zmin > z[i][j] )
171
if ( zmax < z[i][j] )
176
double step = ( zmax - zmin ) / ( LEVELS + 1 );
177
for ( i = 0; i < LEVELS; i++ )
178
clevel[i] = zmin + step * ( i + 1 );
180
pls.lightsource( 1., 1., 1. );
181
for ( k = 0; k < 2; k++ )
183
for ( ifshade = 0; ifshade < 4; ifshade++ )
186
pls.vpor( 0.0, 1.0, 0.0, 0.9 );
187
pls.wind( -1.0, 1.0, -0.9, 1.1 );
189
pls.mtex( "t", 1.0, 0.5, 0.5, title[k] );
192
pls.w3d( 1.0, 1.0, 1.0, -1.5, 1.5, -0.5, 1.5, zmin, zmax,
195
pls.w3d( 1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, zmin, zmax,
197
pls.box3( "bnstu", "x axis", 0.0, 0,
198
"bnstu", "y axis", 0.0, 0,
199
"bcdmnstuv", "z axis", 0.0, 0 );
203
if ( ifshade == 0 ) // diffuse light surface plot
206
// with new interface haven't yet made null work so have
207
// to put in specific zero-length array.
208
pls.surf3d( x, y, z, 0, clev_null );
210
else if ( ifshade == 1 ) // magnitude colored plot
213
pls.surf3d( x, y, z, PLStream.MAG_COLOR, clev_null );
215
else if ( ifshade == 2 ) // magnitude colored plot with faceted squares
218
pls.surf3d( x, y, z, PLStream.MAG_COLOR | PLStream.FACETED, clev_null );
220
else // magnitude colored plot with contours
223
pls.surf3d( x, y, z, PLStream.MAG_COLOR | PLStream.SURF_CONT | PLStream.BASE_CONT, clevel );
232
//--------------------------------------------------------------------------
234
//--------------------------------------------------------------------------