Image obtained by using color PostScript driver (psc) and then converted to animated gif using ImageMagick convert tool.

1 #pragma _ipath "./" 2 #include "plcdemos.h" 3 4 #define XPTS 35 /* Data points in x */ 5 #define YPTS 46 /* Data points in y */ 6 7 PLFLT z[XPTS][YPTS], zmin, zmax; 8 9 10 static void plot1 (void); 11 static void plot2 (void); 12 static void f2mnmx (PLFLT *, PLINT, PLINT, PLFLT *, PLFLT *); 13 static void cmap1_init1 (void); 14 static void cmap1_init2 (void); 15 16 17 int 18 main(int argc, char *argv[]) 19 { 20 int i, j; 21 PLFLT xx, yy; 22 23 24 (void) plParseOpts(&argc, argv, PL_PARSE_FULL); 25 26 27 cmap1_init2(); 28 29 30 plinit(); 31 32 33 for (i = 0; i < XPTS; i++) { 34 xx = (double) (i - (XPTS / 2)) / (double) (XPTS / 2); 35 for (j = 0; j < YPTS; j++) { 36 yy = (double) (j - (YPTS / 2)) / (double) (YPTS / 2) - 1.0; 37 38 z[i][j] = xx*xx - yy*yy + (xx - yy)/(xx*xx+yy*yy + 0.1); 39 } 40 } 41 f2mnmx(&z[0][0], XPTS, YPTS, &zmin, &zmax); 42 43 plot1(); 44 plot2(); 45 46 plend(); 47 exit(0); 48 } 49 50 51 static void 52 cmap1_init1(void) 53 { 54 PLFLT i[4], h[4], l[4], s[4]; 55 56 i[0] = 0; i[1] = 0.45; i[2] = 0.55; i[3] = 1; 57 h[0] = 260; h[1] = 260; h[2] = 20; h[3] = 20; 58 #if 1 59 l[0] = 0.5; l[1] = 0.0; l[2] = 0.0; l[3] = 0.5; #else 60 plscolbg(255,255,255); 61 l[0] = 0.5; l[1] = 1.0; l[2] = 1.0; l[3] = 0.5; #endif 62 s[0] = 1; s[1] = 1; s[2] = 1; s[3] = 1; 63 plscmap1l(0, 4, i, h, l, s, NULL); 64 } 65 66 67 static void 68 cmap1_init2(void) 69 { 70 PLFLT i[4], h[4], l[4], s[4]; 71 72 i[0] = 0; i[1] = 0.45; i[2] = 0.55; i[3] = 1; 73 h[0] = 260; h[1] = 260; h[2] = 20; h[3] = 20; 74 #if 1 75 l[0] = 0.6; l[1] = 0.0; l[2] = 0.0; l[3] = 0.6; #else 76 plscolbg(255,255,255); 77 l[0] = 0.5; l[1] = 1.0; l[2] = 1.0; l[3] = 0.5; #endif 78 s[0] = 1; s[1] = 0.5; s[2] = 0.5; s[3] = 1; 79 plscmap1l(0, 4, i, h, l, s, NULL); 80 } 81 82 83 static void 84 plot1(void) 85 { 86 PLFLT shade_min, shade_max, sh_color; 87 PLINT sh_cmap = 0, sh_width; 88 PLINT min_color = 0, min_width = 0, max_color = 0, max_width = 0; 89 90 pladv(0); 91 plvpor(0.1, 0.9, 0.1, 0.9); 92 plwind(-1.0, 1.0, -1.0, 1.0); 93 94 95 shade_min = zmin + (zmax-zmin)*0.4; 96 shade_max = zmin + (zmax-zmin)*0.6; 97 sh_color = 7; 98 sh_width = 2; 99 min_color = 9; 100 max_color = 2; 101 min_width = 2; 102 max_width = 2; 103 104 plpsty(8); 105 plshade1(&z[0][0], XPTS, YPTS, NULL, -1., 1., -1., 1., 106 shade_min, shade_max, 107 sh_cmap, sh_color, sh_width, 108 min_color, min_width, max_color, max_width, 109 plfill, 1, NULL, NULL); 110 111 plcol0(1); 112 plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); 113 plcol0(2); 114 pllab("distance", "altitude", "Bogon flux"); 115 } 116 117 118 static void 119 plot2(void) 120 { 121 PLFLT shade_min, shade_max, sh_color; 122 PLINT sh_cmap = 0, sh_width; 123 PLINT min_color = 0, min_width = 0, max_color = 0, max_width = 0; 124 int i; 125 sh_width = 2; 126 127 pladv(0); 128 plvpor(0.1, 0.9, 0.1, 0.9); 129 plwind(-1.0, 1.0, -1.0, 1.0); 130 131 132 for (i = 0; i < 10; i++) { 133 shade_min = zmin + (zmax - zmin) * i / 10.0; 134 shade_max = zmin + (zmax - zmin) * (i +1) / 10.0; 135 sh_color = i+6; 136 plpsty((i + 2) % 8 + 1); 137 138 plshade1(&z[0][0], XPTS, YPTS, NULL, -1., 1., -1., 1., 139 shade_min, shade_max, 140 sh_cmap, sh_color, sh_width, 141 min_color, min_width, max_color, max_width, 142 plfill, 1, NULL, NULL); 143 } 144 145 plcol0(1); 146 plbox("bcnst", 0.0, 0, "bcnstv", 0.0, 0); 147 plcol0(2); 148 pllab("distance", "altitude", "Bogon flux"); 149 } 150 151 152 #define F(a,b) (f[a*ny+b]) 153 154 static void 155 f2mnmx(PLFLT *f, PLINT nx, PLINT ny, PLFLT *fmin, PLFLT *fmax) 156 { 157 int i, j; 158 159 *fmax = F(0,0); 160 *fmin = *fmax; 161 162 for (i = 0; i < nx; i++) { 163 for (j = 0; j < ny; j++) { 164 *fmax = MAX(*fmax, F(i, j)); 165 *fmin = MIN(*fmin, F(i, j)); 166 } 167 } 168 }
Code description
- 1
- $Id: x15c.c,v 1.16 2004/03/17 16:03:15 rlaboiss Exp $ Shade plot demo. Maurice LeBrun IFS, University of Texas at Austin 31 Aug 1993
- 9
- Function prototypes
- 16
- --------------------------------------------------------------------------*\ * main * * Does a variety of shade plots. \*--------------------------------------------------------------------------
- 23
- Parse and process command line arguments
- 26
- Set up color map 0
- 26
- plscmap0n(3);
- 26
- Set up color map 1
- 29
- Initialize plplot
- 32
- Set up data array
- 50
- --------------------------------------------------------------------------*\ * cmap1_init1 * * Initializes color map 1 in HLS space. \*--------------------------------------------------------------------------
- 56
- left boundary
- 56
- just before center
- 56
- just after center
- 56
- right boundary
- 57
- hue -- low: blue-violet
- 57
- only change as we go over vertex
- 57
- hue -- high: red
- 57
- keep fixed
- 59
- lightness -- low
- 59
- lightness -- center
- 59
- lightness -- center
- 59
- lightness -- high
- 61
- lightness -- low
- 61
- lightness -- center
- 61
- lightness -- center
- 61
- lightness -- high
- 62
- maximum saturation
- 62
- maximum saturation
- 62
- maximum saturation
- 62
- maximum saturation
- 66
- --------------------------------------------------------------------------*\ * cmap1_init2 * * Initializes color map 1 in HLS space. \*--------------------------------------------------------------------------
- 72
- left boundary
- 72
- just before center
- 72
- just after center
- 72
- right boundary
- 73
- hue -- low: blue-violet
- 73
- only change as we go over vertex
- 73
- hue -- high: red
- 73
- keep fixed
- 75
- lightness -- low
- 75
- lightness -- center
- 75
- lightness -- center
- 75
- lightness -- high
- 77
- lightness -- low
- 77
- lightness -- center
- 77
- lightness -- center
- 77
- lightness -- high
- 78
- saturation -- low
- 78
- saturation -- center
- 78
- saturation -- center
- 78
- saturation -- high
- 82
- --------------------------------------------------------------------------*\ * plot1 * * Illustrates a single shaded region. \*--------------------------------------------------------------------------
- 94
- Plot using identity transform
- 117
- --------------------------------------------------------------------------*\ * plot2 * * Illustrates multiple adjacent shaded regions, using different fill * patterns for each region. \*--------------------------------------------------------------------------
- 131
- Plot using identity transform
- 151
- --------------------------------------------------------------------------*\ * f2mnmx * * Returns min & max of input 2d array. \*--------------------------------------------------------------------------