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 */ int symbol = 1; /* Point symbol */ 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 */ s2sch(2); /* Sets size of most symbols */ s2slw(2); /* Sets size of point */ for (i=0;i<N;i++) { s2sci((i%15) + 1); /* 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[]) { int i; /* Loop varibale */ float x, y, z; /* Random data */ srand48((long)time(NULL)); /* Seed random numbers */ fprintf(stderr,"Shift-s to toggle handles\nShift-c to toggle crosshair\n"); fprintf(stderr,"Right mouse select\nSpacebar toggle show all/show sel\n"); 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 */ for (i=0;i<N;i++) { /* Set-up globals */ xyz[i].x = drand48()*2.0 - 1.0; /* Random position */ xyz[i].y = drand48()*2.0 - 1.0; xyz[i].z = drand48()*2.0 - 1.0; col[i].r = drand48(); /* Random colour */ col[i].g = drand48(); col[i].b = drand48(); sel[i] = 0; /* Not currently selected */ } cs2scb(&cb); /* Install dynamic callback */ cs2shcb(&pick); /* Install handle callback */ s2slw(2); /* Set line width */ for (i=0;i<N;i++) { /* Non-selectable random data points */ x = drand48()*2.0 - 1.0; y = drand48()*2.0 - 1.0; z = drand48()*2.0 - 1.0; s2sci(15*drand48() + 1); /* Random colour */ s2pt1(x,y,z,1); } s2show(1); /* Open the s2plot window */ return 1; }
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[]) { int i, N = 20; /* Loop variables */ float x, y, z; /* Random data */ XYZ focus; /* Point to rotate about */ int wc = 1; /* Use world coordinates */ srand48((long)time(NULL)); /* Seed random numbers */ 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(3); /* Set line width */ for (i=0;i<N;i++) { x = drand48()*2.0 - 1.0; /* Random (x,y,z) */ y = drand48()*2.0 - 1.0; z = drand48()*2.0 - 1.0; s2sci(15*drand48() + 1); /* Random colour */ s2pt1(x,y,z,1); /* Plot the point */ } focus.x = drand48()*2.0 - 1.0; /* Random rotation point */ focus.y = drand48()*2.0 - 1.0; focus.z = drand48()*2.0 - 1.0; ss2scf(focus, wc); /* Set the rotation point */ s2sch(0.7); /* Set text height */ s2textxy(-1,0,0,"Rotate camera - then press 1 followed by +"); cs2sncb(&numcb); /* Install number callback */ s2show(1); /* Open the s2plot window */ return 1; }
plotsnap() { real t, *mp, *psp, *pp, *ap, *acp; int vismax, visnow, i, vis, icol; real psz, col, x, y, z; Body b; bool Qall = FALSE; t = (timeptr != NULL ? *timeptr : 0.0); /* get current time value */ CLRV(Acc(&b)); /* zero unsupported fields */ Key(&b) = 0; visnow = vismax = 0; do { /* loop painting layers */ visnow++; /* make next layer visib. */ mp = massptr; /* (re)set data pointers */ psp = phaseptr; pp = phiptr; ap = auxptr; acp = accptr; npnt = 0; for (i = 0; i < nbody; i++) { /* loop over all bodies */ Mass(&b) = (mp != NULL ? *mp++ : 0.0); /* set mass if supplied */ SETV(Pos(&b), psp); /* always set position */ psp += NDIM; /* and advance p.s. ptr */ SETV(Vel(&b), psp); /* always set velocity */ psp += NDIM; /* and advance ptr */ Phi(&b) = (pp != NULL ? *pp++ : 0.0); Aux(&b) = (ap != NULL ? *ap++ : 0.0); if (acp) { SETV(Acc(&b),acp); /* set accel's */ acp += NDIM; /* and advance ptr */ } /* set phi,aux if given */ vis = (*vfunc)(&b, t, i); /* evaluate visibility */ vismax = MAX(vismax, vis); /* remember how hi to go*/ if (vis == visnow) { /* if body is visible */ x = (*xfunc)(&b, t, i); /* evaluate x,y,z coords*/ y = (*yfunc)(&b, t, i); z = (*zfunc)(&b, t, i); psz = (*pfunc)(&b, t, i); #define MAXCOLOR 16 #ifdef COLOR col = (*cfunc)(&b, t, i); col = (col - crange[0])/(crange[1] - crange[0]); icol = 1 + (MAXCOLOR - 2) * MAX(0.0, MIN(1.0, col)); s2sci(icol); #endif xpnt[npnt] = x; ypnt[npnt] = y; zpnt[npnt] = z; if (!Qall) { s2pt1(xpnt[npnt],ypnt[npnt],zpnt[npnt], visnow); } npnt++; } } /* i<nbody */ if (Qall) s2pt(npnt, xpnt, ypnt, zpnt, visnow); } while (visnow < vismax); /* until final layer done */ }