int main(int argc, char *argv[]) { int i, N = 20; float x[20], y[20], z[20]; /* Static geometry */ srand48((long)time(NULL)); /* Seed random numbers */ for (i=0;i<N;i++) { x[i] = drand48()*4.0-2.0; /* Random positions */ y[i] = drand48()*4.0-2.0; z[i] = drand48()*4.0-2.0; } s2opend("/?",argc, argv); /* Open the display */ s2swin(-2.,2., -2.,2., -2.,2.); /* Set the window coordinates */ s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */ cs2scb(&cb); /* Install the callback */ cs2sncb(&ncb); /* Install number callback */ s2slw(4); /* Set line width */ s2sci(S2_PG_YELLOW); s2pt(N,x,y,z,1); /* Draw static data */ s2slw(1); s2show(1); /* Open the s2plot window */ return 1; }
void cb(double *t, int *kc) /* A dynamic callback - jitter particle positions each time through */ { static int flag = 0; /* Flag on whether first time through */ static float x[20], y[20], z[20]; /* Dynamic geometry */ int i, N = 20; if (flag == 0) { /* First time only */ for (i=0;i<N;i++) { x[i] = drand48()*2.0-1.0; /* Random positions */ y[i] = drand48()*2.0-1.0; z[i] = drand48()*2.0-1.0; } flag = 1; /* Set the flag - don't need this loop again */ } for (i=0;i<N;i++) { x[i] += (drand48()*0.1-0.05); /* Apply a jitter each time in callback */ y[i] += (drand48()*0.1-0.05); z[i] += (drand48()*0.1-0.05); } s2sci((*kc % 2) + colour); /* Set colour on number of times space is pressed - uses global */ s2slw(3); /* Set the line width */ s2pt(N, x, z, y, 1); /* Draw the points */ }
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 */ }