+#undef countof
+#define countof(x) (sizeof(x)/sizeof(*(x)))
+
+#define LITTLE_NAP 5000 /* 1/200th sec */
+
+typedef void (*Eraser) (Display *dpy, Window window, GC gc,
+ int width, int height, int total_msecs);
+
+
+static unsigned long
+millitime (void)
+{
+ struct timeval tt;
+# ifdef GETTIMEOFDAY_TWO_ARGS
+ struct timezone tz;
+ gettimeofday (&tt, &tz);
+# else
+ gettimeofday (&tt);
+# endif
+ return (tt.tv_sec * 1000) + (tt.tv_usec / 1000);
+}
+
+
+static void
+random_lines (Display *dpy, Window window, GC gc,
+ int width, int height, int total_msecs)
+{
+ int granularity = 50;
+
+ Bool horiz_p = (random() & 1);
+ int max = (horiz_p ? height : width);
+ int *lines = (int *) calloc(max, sizeof(*lines));
+ int oi = -1;
+ int i;
+ unsigned long start_tick = millitime();
+ unsigned long end_tick = start_tick + total_msecs;
+ unsigned long tick = start_tick;
+ int hits = 0;
+ int nonhits = 0;
+
+ for (i = 0; i < max; i++)
+ lines[i] = i;
+
+ for (i = 0; i < max; i++)
+ {
+ int t, r;
+ t = lines[i];
+ r = random() % max;
+ lines[i] = lines[r];
+ lines[r] = t;
+ }
+
+ while (tick < end_tick)
+ {
+ int i = (max * (tick - start_tick)) / (end_tick - start_tick);
+
+ i /= granularity;
+
+ if (i == oi)
+ {
+ usleep (LITTLE_NAP);
+ nonhits++;
+ }
+ else
+ {
+ int j;
+ for (j = 0; j < granularity; j++)
+ {
+ int ii = i * granularity + j;
+
+ if (ii >= horiz_p ? height : width) /* don't go off array */
+ break;
+
+ if (horiz_p)
+ XDrawLine (dpy, window, gc, 0, lines[ii], width, lines[ii]);
+ else
+ XDrawLine (dpy, window, gc, lines[ii], 0, lines[ii], height);
+ hits++;
+ }
+ XSync (dpy, False);
+ }
+
+ oi = i;
+ tick = millitime();
+ }
+
+ free(lines);
+}
+
+
+static void
+venetian (Display *dpy, Window window, GC gc,
+ int width, int height, int total_msecs)
+{
+ Bool horiz_p = (random() & 1);
+ Bool flip_p = (random() & 1);
+ int max = (horiz_p ? height : width);
+ int *lines = (int *) calloc(max, sizeof(*lines));
+ int i, j;
+ int oi = -1;
+
+ unsigned long start_tick = millitime();
+ unsigned long end_tick = (start_tick +
+ (1.5 * total_msecs)); /* this one needs more */
+ unsigned long tick = start_tick;
+ int hits = 0;
+ int nonhits = 0;
+
+ j = 0;
+ for (i = 0; i < max*2; i++)
+ {
+ int line = ((i / 16) * 16) - ((i % 16) * 15);
+ if (line >= 0 && line < max)
+ lines[j++] = (flip_p ? max - line : line);
+ }
+
+ while (tick < end_tick)
+ {
+ int i = (max * (tick - start_tick)) / (end_tick - start_tick);
+
+ if (i == oi)
+ {
+ usleep (LITTLE_NAP);
+ nonhits++;
+ }
+ else
+ {
+ int k;
+ for (k = oi; k <= i; k++)
+ {
+ if (horiz_p)
+ XDrawLine(dpy,window, gc, 0, lines[k], width, lines[k]);
+ else
+ XDrawLine(dpy,window, gc, lines[k], 0, lines[k], height);
+ hits++;
+ }
+ XSync (dpy, False);
+ }
+
+ oi = i;
+ tick = millitime();
+ }
+ free(lines);
+}
+
+
+static void
+triple_wipe (Display *dpy, Window window, GC gc,
+ int width, int height, int total_msecs)
+{
+ Bool flip_x = random() & 1;
+ Bool flip_y = random() & 1;
+ int max = width + (height / 2);
+ int *lines = (int *)calloc(max, sizeof(int));
+ int i;
+ int oi = -1;
+
+ unsigned long start_tick = millitime();
+ unsigned long end_tick = start_tick + total_msecs;
+ unsigned long tick = start_tick;
+ int hits = 0;
+ int nonhits = 0;
+
+ for(i = 0; i < width/2; i++)
+ lines[i] = i*2+height;
+ for(i = 0; i < height/2; i++)
+ lines[i+width/2] = i*2;
+ for(i = 0; i < width/2; i++)
+ lines[i+width/2+height/2] = width-i*2-(width%2?0:1)+height;
+
+ while (tick < end_tick)
+ {
+ int i = (max * (tick - start_tick)) / (end_tick - start_tick);
+ int x, y, x2, y2;
+
+ if (i == oi)
+ {
+ usleep (LITTLE_NAP);
+ nonhits++;
+ }
+ else
+ {
+ int k;
+ for (k = oi; k <= i; k++)
+ {
+ if (lines[k] < height)
+ x = 0, y = lines[k], x2 = width, y2 = y;
+ else
+ x = lines[k]-height, y = 0, x2 = x, y2 = height;
+
+ if (flip_x)
+ x = width-x, x2 = width-x2;
+ if (flip_y)
+ y = height-y, y2 = height-y2;
+
+ XDrawLine (dpy, window, gc, x, y, x2, y2);
+ hits++;
+ }
+ XSync (dpy, False);
+ }
+
+ oi = i;
+ tick = millitime();
+ }
+ free(lines);
+}
+
+
+static void
+quad_wipe (Display *dpy, Window window, GC gc,
+ int width, int height, int total_msecs)
+{
+ Bool flip_x = random() & 1;
+ Bool flip_y = random() & 1;
+ int max = width + height;
+ int *lines = (int *)calloc(max, sizeof(int));
+ int i;
+ int oi = -1;
+
+ unsigned long start_tick = millitime();
+ unsigned long end_tick = start_tick + total_msecs;
+ unsigned long tick = start_tick;
+ int hits = 0;
+ int nonhits = 0;
+
+ for (i = 0; i < max/4; i++)
+ {
+ lines[i*4] = i*2;
+ lines[i*4+1] = height-i*2-(height%2?0:1);
+ lines[i*4+2] = height+i*2;
+ lines[i*4+3] = height+width-i*2-(width%2?0:1);
+ }
+
+ while (tick < end_tick)
+ {
+ int i = (max * (tick - start_tick)) / (end_tick - start_tick);
+
+ if (i == oi)
+ {
+ usleep (LITTLE_NAP);
+ nonhits++;
+ }
+ else
+ {
+ int k;
+ for (k = oi; k <= i; k++)
+ {
+ int x, y, x2, y2;
+ if (lines[k] < height)
+ x = 0, y = lines[k], x2 = width, y2 = y;
+ else
+ x = lines[k]-height, y = 0, x2 = x, y2 = height;
+
+ if (flip_x)
+ x = width-x, x2 = width-x2;
+ if (flip_y)
+ y = height-y, y2 = height-y2;
+
+ XDrawLine (dpy, window, gc, x, y, x2, y2);
+ hits++;
+ }
+ XSync (dpy, False);
+ }
+
+ oi = i;
+ tick = millitime();
+ }
+
+ free(lines);
+}
+
+
+
+static void
+circle_wipe (Display *dpy, Window window, GC gc,
+ int width, int height, int total_msecs)
+{
+ int max = 360 * 64;
+ int start = random() % max;
+ int rad = (width > height ? width : height);
+ int flip_p = random() & 1;
+ int oth;
+
+ unsigned long start_tick = millitime();
+ unsigned long end_tick = start_tick + total_msecs;
+ unsigned long tick = start_tick;
+
+ int hits = 0;
+ int nonhits = 0;
+
+ oth = (flip_p ? max : 0);
+ while (tick < end_tick)
+ {
+ int th = (max * (tick - start_tick)) / (end_tick - start_tick);
+ if (flip_p)
+ th = (360 * 64) - th;
+
+ if (th == oth)
+ {
+ usleep (LITTLE_NAP);
+ nonhits++;
+ }
+ else
+ {
+ XFillArc(dpy, window, gc,
+ (width/2)-rad, (height/2)-rad, rad*2, rad*2,
+ (start+oth)%(360*64),
+ (th-oth));
+ hits++;
+ XSync (dpy, False);
+ }
+
+ oth = th;
+ tick = millitime();
+ }
+}
+
+
+static void
+three_circle_wipe (Display *dpy, Window window, GC gc,
+ int width, int height, int total_msecs)
+{
+ int max = (360 * 64) / 6;
+ int start = random() % max;
+ int rad = (width > height ? width : height);
+ int oth;
+
+ unsigned long start_tick = millitime();
+ unsigned long end_tick = start_tick + total_msecs;
+ unsigned long tick = start_tick;
+
+ int hits = 0;
+ int nonhits = 0;
+
+ oth = 0;
+ while (tick < end_tick)
+ {
+ int th = (max * (tick - start_tick)) / (end_tick - start_tick);
+
+ if (th == oth)
+ {
+ usleep (LITTLE_NAP);
+ nonhits++;
+ }
+ else
+ {
+ int off = 0;
+ XFillArc(dpy, window, gc,
+ (width/2)-rad, (height/2)-rad, rad*2, rad*2,
+ (start+off+oth)%(360*64),
+ (th-oth));
+ XFillArc(dpy, window, gc,
+ (width/2)-rad, (height/2)-rad, rad*2, rad*2,
+ ((start+off-oth))%(360*64),
+ -(th-oth));
+
+ off += max + max;
+ XFillArc(dpy, window, gc,
+ (width/2)-rad, (height/2)-rad, rad*2, rad*2,
+ (start+off+oth)%(360*64),
+ (th-oth));
+ XFillArc(dpy, window, gc,
+ (width/2)-rad, (height/2)-rad, rad*2, rad*2,
+ ((start+off-oth))%(360*64),
+ -(th-oth));
+
+ off += max + max;
+ XFillArc(dpy, window, gc,
+ (width/2)-rad, (height/2)-rad, rad*2, rad*2,
+ (start+off+oth)%(360*64),
+ (th-oth));
+ XFillArc(dpy, window, gc,
+ (width/2)-rad, (height/2)-rad, rad*2, rad*2,
+ ((start+off-oth))%(360*64),
+ -(th-oth));
+
+ hits++;
+ XSync (dpy, False);
+ }
+
+ oth = th;
+ tick = millitime();
+ }
+}
+
+
+static void
+squaretate (Display *dpy, Window window, GC gc,
+ int width, int height, int total_msecs)
+{
+ int max = ((width > height ? width : width) * 2);
+ int oi = -1;
+ Bool flip = random() & 1;
+
+ unsigned long start_tick = millitime();
+ unsigned long end_tick = start_tick + total_msecs;
+ unsigned long tick = start_tick;
+ int hits = 0;
+ int nonhits = 0;
+
+#define DRAW() \
+ if (flip) { \
+ points[0].x = width-points[0].x; \
+ points[1].x = width-points[1].x; \
+ points[2].x = width-points[2].x; } \
+ XFillPolygon (dpy, window, gc, points, 3, Convex, CoordModeOrigin)
+
+ while (tick < end_tick)
+ {
+ int i = (max * (tick - start_tick)) / (end_tick - start_tick);
+
+ if (i == oi)
+ {
+ usleep (LITTLE_NAP);
+ nonhits++;
+ }
+ else
+ {
+ XPoint points [3];
+ points[0].x = 0;
+ points[0].y = 0;
+ points[1].x = width;
+ points[1].y = 0;
+ points[2].x = 0;
+ points[2].y = points[0].y + ((i * height) / max);
+ DRAW();
+
+ points[0].x = 0;
+ points[0].y = 0;
+ points[1].x = 0;
+ points[1].y = height;
+ points[2].x = ((i * width) / max);
+ points[2].y = height;
+ DRAW();
+
+ points[0].x = width;
+ points[0].y = height;
+ points[1].x = 0;
+ points[1].y = height;
+ points[2].x = width;
+ points[2].y = height - ((i * height) / max);
+ DRAW();
+
+ points[0].x = width;
+ points[0].y = height;
+ points[1].x = width;
+ points[1].y = 0;
+ points[2].x = width - ((i * width) / max);
+ points[2].y = 0;
+ DRAW();
+ hits++;
+ XSync (dpy, True);
+ }
+
+ oi = i;
+ tick = millitime();
+ }
+#undef DRAW
+}
+
+
+/* from Frederick Roeber <roeber@netscape.com> */
+static void
+fizzle (Display *dpy, Window window, GC gc,
+ int width, int height, int total_msecs)
+{
+ /* These dimensions must be prime numbers. They should be roughly the
+ square root of the width and height. */
+# define BX 41
+# define BY 31
+# define SIZE (BX*BY)
+
+ int array[SIZE];
+ int i, j;
+ int oi = -1;
+ XPoint *skews;
+ XPoint points[250];
+ int npoints = 0;
+ int nx, ny;
+
+ unsigned long start_tick = millitime();
+ unsigned long end_tick = (start_tick +
+ (2.5 * total_msecs)); /* this one needs more */
+ unsigned long tick = start_tick;
+ int hits = 0;
+ int nonhits = 0;
+
+ /* Distribute the numbers [0,SIZE) randomly in the array */
+ {
+ int indices[SIZE];
+
+ for( i = 0; i < SIZE; i++ ) {
+ array[i] = -1;
+ indices[i] = i;
+ }
+
+ for( i = 0; i < SIZE; i++ ) {
+ j = random()%(SIZE-i);
+ array[indices[j]] = i;
+ indices[j] = indices[SIZE-i-1];
+ }
+ }
+
+ /* nx, ny are the number of cells across and down, rounded up */
+ nx = width / BX + (0 == (width %BX) ? 0 : 1);
+ ny = height / BY + (0 == (height%BY) ? 0 : 1);
+ skews = (XPoint *)malloc(sizeof(XPoint) * (nx*ny));
+ if( (XPoint *)0 != skews ) {
+ for( i = 0; i < nx; i++ ) {
+ for( j = 0; j < ny; j++ ) {
+ skews[j * nx + i].x = random()%BX;
+ skews[j * nx + i].y = random()%BY;
+ }
+ }
+ }
+
+# define SKEWX(cx, cy) (((XPoint *)0 == skews)?0:skews[cy*nx + cx].x)
+# define SKEWY(cx, cy) (((XPoint *)0 == skews)?0:skews[cy*nx + cx].y)
+
+ while (tick < end_tick)
+ {
+ int i = (SIZE * (tick - start_tick)) / (end_tick - start_tick);
+
+ if (i == oi)
+ {
+ usleep (LITTLE_NAP);
+ nonhits++;
+ }
+ else
+ {
+ int j;
+ for (j = oi; j < i; j++)
+ {
+ int x = array[j] % BX;
+ int y = array[j] / BX;
+ int iy, cy;
+ for (iy = 0, cy = 0; iy < height; iy += BY, cy++)
+ {
+ int ix, cx;
+ for( ix = 0, cx = 0; ix < width; ix += BX, cx++ ) {
+ int xx = ix + (SKEWX(cx, cy) + x*((cx%(BX-1))+1))%BX;
+ int yy = iy + (SKEWY(cx, cy) + y*((cy%(BY-1))+1))%BY;
+ if (xx < width && yy < height)
+ {
+ points[npoints].x = xx;
+ points[npoints].y = yy;
+ if (++npoints == countof(points))
+ {
+ XDrawPoints(dpy, window, gc, points, npoints,
+ CoordModeOrigin);
+ XSync (dpy, False);
+ npoints = 0;
+ }
+ }
+ }
+ }
+ }
+ hits++;
+ }
+
+ oi = i;
+ tick = millitime();
+ }
+
+ if (npoints > 100)
+ {
+ XDrawPoints(dpy, window, gc, points, npoints, CoordModeOrigin);
+ XSync (dpy, False);
+ usleep (10000);
+ }
+
+# undef SKEWX
+# undef SKEWY
+# undef BX
+# undef BY
+# undef SIZE
+
+ if (skews) free(skews);
+}
+
+
+/* from Rick Campbell <rick@campbellcentral.org> */
+static void
+spiral (Display *dpy, Window window, GC context,
+ int width, int height, int total_msecs)