/* Kac ring animator */ /* gcc kacringanim.c -L/usr/X11R6/lib -lplot -lXaw -lXmu -lXt -lSM -lICE -lXext -lX11 -lm */ #include #include #include #include #include #define PI 3.1415927 float x, y, size, ell, th, dth, x0, y00, deltabar, sum; int epsilon[16], eta[16], eta_new[16]; int n, m, k, t, N_w, N_b,M,N; int pl_handle; char buffer[6], *labels; FILE *outptr; main (int argc, char *argv[]) { char P1[18] = "p\\sb"; char P2[18] = "\\eb"; char P3[18] = "t="; char P4[18] = "N\\sbb\\eb="; char P5[18] = "N\\sbw\\eb="; char P6[18] = "\\*D="; char P7[18] = "<\\*D>\\sbt\\eb="; char labels2[25]; srand (19); size = 5.0; t=atoi(argv[1]); /* create a file to output the time averaged delta N */ outptr = fopen ("time.dat", "w"); deltabar = 0.0; /* initialize time average N_b-N_w */ N=4; M=1; /* set initial ball colors */ eta[0]=1; eta[1]=-1; eta[2]=-1; eta[3]=1; /* set marker values */ for (n = 0; n < 4; n++) { epsilon[n] = 1; } /* set up three markers, you can add more */ epsilon[0] = -1; /* set up the X-plotter */ pl_handle = pl_newpl ("ps", stdin, stdout, stderr); pl_selectpl (pl_handle); if (pl_openpl () < 0) /* open Plotter */ { fprintf (stderr, "Couldn't open Plotter\n"); return 1; } pl_fspace (-size, -size, size, size); pl_flinewidth (0.005); /* output initial delta */ N_w = 0; N_b = 0; for (n = 0; n < 4; n++) { if (eta[n] == 1) N_b = N_b + 1; else N_w = N_w + 1; } if(t>0){ /* time loop */ for(k=1;k<=t;k++){ /* update ball colors */ for (n = 0; n < 4; n++) eta_new[n] = epsilon[n - 1] * eta[n - 1]; eta_new[0] = epsilon[3] * eta[3]; for (n = 0; n < 4; n++) eta[n] = eta_new[n]; } } /* compute number of black, white balls */ N_w = 0; N_b = 0; for (n = 0; n < 4; n++) { if (eta[n] == 1) N_b = N_b + 1; else N_w = N_w + 1; } pl_ffontsize(0.7); pl_flinewidth (0.005); /* draw the figure */ pl_erase (); pl_filltype (0); pl_pencolorname ("black"); pl_linemod ("dotted"); pl_fcircle (0.0, 0.0, 4.0); dth = PI / 2.0; for (n = 0; n < 16; n++) { th = (float) n *dth; pl_fline (0.0, 0.0, 4.0 * cos (th), 4.0 * sin (-th)); } pl_linemod ("solid"); pl_ffontname ("HersheySerif"); pl_ffontsize (0.4); for (n = 0; n < 4; n++) { char P1[18] = "p\\sb"; char P2[18] = "\\eb"; th = (float) n *dth; pl_fmove (4.5 * cos (th), 4.5 * sin (-th)); labels = gcvt ((float) (n + 1), 4, buffer); strcat (P1, labels); strcat (P1, P2); pl_label (P1); } pl_filltype (1); for (n = 0; n < 4; n++) { th = (float) n *dth - dth / 2.0; pl_fmove (4.0 * cos (th) + 0.2, 4.0 * sin (-th)); if (eta[n] > 0) pl_fillcolorname ("black"); else pl_fillcolorname ("white"); pl_fcircle (4.0 * cos (th), 4.0 * sin (-th), 0.2); } /* draw the marked positions */ pl_filltype (1); pl_fillcolorname ("red"); for (n = 0; n < 4; n++) { th = (float) n *dth; if (epsilon[n] == -1) { pl_fcircle (4.0 * cos (th), 4.0 * sin (-th), 0.07); } } pl_filltype (0); pl_fmove (-3.0, -5.0); labels = gcvt ((float) (t), 4, buffer); memcpy (labels2, P3, 12); strcat (labels2, labels); pl_label (labels2); pl_fmove (-2.0, -5.0); labels = gcvt ((float) (N_w), 4, buffer); memcpy (labels2, P5, 12); strcat (labels2, labels); pl_label (labels2); pl_fmove (-0.5, -5.0); labels = gcvt ((float) (N_b), 4, buffer); memcpy (labels2, P4, 12); strcat (labels2, labels); pl_label (labels2); pl_fmove (1.0, -5.0); labels = gcvt ((float) (N_b - N_w), 4, buffer); memcpy (labels2, P6, 12); strcat (labels2, labels); pl_label (labels2); pl_closepl (); pl_selectpl (0); pl_deletepl (pl_handle); fclose (outptr); }