int main(int argc, char *argv[]) { int i; /* Loop variable */ int N = 50; /* Number of points */ float x[50], y[50], z[50]; /* Coordinates of points */ float r, g, b; /* RGB colours */ int symbol = 1; /* Point symbol */ int offset = 32; /* Starting colour */ srand48((long)time(NULL)); /* Seed random numbers */ for (i=0;i<N;i++) { x[i] = drand48()*2.0 - 1.0; y[i] = drand48()*2.0 - 1.0; z[i] = drand48()*2.0 - 1.0; } s2opend("/?",argc, argv); /* Open the display */ s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */ s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */ s2slw(5); /* Sets size of point */ s2scir(offset, offset+N); /* Set the colour index range */ for (i=offset;i<(offset+N);i++) { r = drand48(); /* Choose random red value */ g = r; /* Green = Blue = Red */ b = r; /* means grey-scale! */ s2scr(i, r, g, b); /* Set colour representation */ } for (i=0;i<N;i++) { s2qcr(offset+i, &r, &g, &b); /* Query colour representation */ s2scr(offset+i, r, 1.0, g); /* Make it greenish */ s2sci(offset+i); /* Set the colour */ s2pt1(x[i],y[i],z[i],symbol); /* Draw a single point */ } s2show(1); /* Open the s2plot window */ return 1; }
int main(int argc, char *argv[]) { float x1 = -XLIMIT, x2 = XLIMIT; /* x world coord range */ float y1 = -YLIMIT, y2 = YLIMIT; /* y world coord range */ float z1 = -ZLIMIT, z2 = ZLIMIT; /* z world coord range */ int i, j; /* Loop variables */ float **image; /* 2D array for image */ float minz = 9e30; /* Minimum value */ float maxz = -9e30; /* Maximum value */ float x, y, dx, dy; /* Temporary variables */ float tr[12]; /* Transformation matrix */ int walls = 1; /* Should walls be drawn? */ int lcolor = S2_PG_LTGREY; /* Colour index for left-hand wall */ int fcolor = S2_PG_DKGREY; /* Automatic colour */ s2opend("/?",argc,argv); /* Open the display */ dx = (x2-x1)/(float)(NX-1); /* Spacing in X */ dy = (y2-y1)/(float)(NY-1); /* Spacing in Y */ s2swin(x1-0.5*dx,x2+0.5*dx,y1-0.5*dy,y2+0.5*dy,z1,z2); /* Set the window coordinates */ s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */ dx = (x2-x1)/(float)(NX-1); /* Spacing in X */ dy = (y2-y1)/(float)(NY-1); /* Spacing in Y */ image = (float **)calloc(NX, sizeof(float *)); /* Allocate memory */ for (i=0;i<NX;i++) { image[i] = (float *)calloc(NY, sizeof(float)); /* Allocate memory */ x = i*dx + x1; for (j=0;j<NY;j++) { y = j*dy + y1; image[i][j] = -sqrt(x*x + y*y); /* Data points */ image[i][j] += rand() / (float)RAND_MAX; minz = (image[i][j] < minz) ? image[i][j] : minz; maxz = (image[i][j] > maxz) ? image[i][j] : maxz; } } s2icm("rainbow", 1000, 1500); /* Install colour map */ s2scir(1000, 1500); /* Set colour range */ /* Set up the transformation mapping from grid to world coordinatee */ tr[0] = x1; tr[1] = (x2-x1)/(float)(NX-1); tr[2] = 0.0; tr[3] = 0.0; tr[4] = y1; tr[5] = 0.0; tr[6] = (y2-y1)/(float)(NY-1); tr[7] = 0.0; tr[8] = z1; tr[9] = 0.0; tr[10] = 0.0; tr[11] = 0.0; /* Draw the data mapped to the z-plane */ s2surpa(image, NX, NY, 0, NX-1, 0, NY-1, minz, maxz, tr); tr[8] = z1 - minz * (z2 - z1) / (maxz - minz); /* Fix up z minimum */ tr[11] = (z2 - z1) / (maxz - minz); /* Fix up z range */ /* with automatic colored building walls: */ s2skypa(image, NX, NY, 0, (NX-1)/2, 0, NY-1, minz, maxz, tr, walls, -1, -1); /* with grey walls: idx_left and idx_right specified */ s2skypa(image, NX, NY, (NX-1)/2+1, NX-1, 0, NY-1, minz, maxz, tr, walls, lcolor, fcolor); s2show(1); /* Show the S2PLOT window */ return 1; }