- double range;
- XWindowAttributes xgwa;
- hopstruct *hp = &hop;
- XGCValues gcv;
- Colormap cmap;
- XGetWindowAttributes (dsp, win, &xgwa);
- cmap = xgwa.colormap;
-
- if (! pixels)
- {
- XColor color;
- int i = get_integer_resource ("ncolors", "Integer");
- int shift;
- if (i <= 2) i = 2, mono_p = True;
- shift = 360 / i;
- pixels = (unsigned int *) calloc (i, sizeof (unsigned int));
- fg_pixel = get_pixel_resource ("foreground", "Foreground", dsp, cmap);
- bg_pixel = get_pixel_resource ("background", "Background", dsp, cmap);
- if (! mono_p)
- {
- hsv_to_rgb (random () % 360, 1.0, 1.0,
- &color.red, &color.green, &color.blue);
- for (npixels = 0; npixels < i; npixels++)
- {
- if (! XAllocColor (dsp, cmap, &color))
- break;
- pixels[npixels] = color.pixel;
- cycle_hue (&color, shift);
- }
- }
- timeout = get_integer_resource ("timeout", "Seconds");
- if (timeout <= 0) timeout = 30;
- delay = get_integer_resource ("delay", "Usecs");
-
- gcv.foreground = fg_pixel;
- gc = XCreateGC (dsp, win, GCForeground, &gcv);
- }
-
- XClearWindow (dsp, win);
-
- hp->centerx = xgwa.width / 2;
- hp->centery = xgwa.height / 2;
- range = sqrt((double) hp->centerx * hp->centerx +
- (double) hp->centery * hp->centery) /
- (10.0 + random() % 10);
-
- hp->pix = 0;
-#define frand0() (((double) random()) / ((unsigned int) (~0)))
- hp->inc = (int) (frand0() * 200) - 100;
- hp->a = frand0() * range - range / 2.0;
- hp->b = frand0() * range - range / 2.0;
- hp->c = frand0() * range - range / 2.0;
- if (!(random() % 2))
- hp->c = 0.0;
-
- hp->i = hp->j = 0.0;
-
- if (!pointBuffer)
- pointBuffer = (XPoint *) malloc(batchcount * sizeof(XPoint));
-
- XSetForeground(dsp, gc, bg_pixel);
- XFillRectangle(dsp, win, gc, 0, 0,
- hp->centerx * 2, hp->centery * 2);
- XSetForeground(dsp, gc, fg_pixel);
- hp->startTime = time ((time_t *) 0);
+ Display *display = MI_DISPLAY(mi);
+ GC gc = MI_GC(mi);
+ hopstruct *hp;
+ double range;
+
+ if (hops == NULL) {
+ if ((hops = (hopstruct *) calloc(MI_NUM_SCREENS(mi),
+ sizeof (hopstruct))) == NULL)
+ return;
+ }
+ hp = &hops[MI_SCREEN(mi)];
+
+ hp->centerx = MI_WIN_WIDTH(mi) / 2;
+ hp->centery = MI_WIN_HEIGHT(mi) / 2;
+ /* Make the other operations less common since they are less interesting */
+ if (MI_WIN_IS_FULLRANDOM(mi)) {
+ hp->op = NRAND(OPS+2); /* jwz: make the others a bit more likely. */
+ if (hp->op >= OPS)
+ hp->op = SQRT;
+ } else {
+ hp->op = SQRT;
+ if (jong)
+ hp->op = JONG;
+ else if (sine)
+ hp->op = SINE;
+ }
+ switch (hp->op) {
+ case SQRT:
+ range = sqrt((double) hp->centerx * hp->centerx +
+ (double) hp->centery * hp->centery) / (10.0 + NRAND(10));
+
+ hp->a = (LRAND() / MAXRAND) * range - range / 2.0;
+ hp->b = (LRAND() / MAXRAND) * range - range / 2.0;
+ hp->c = (LRAND() / MAXRAND) * range - range / 2.0;
+ if (LRAND() & 1)
+ hp->c = 0.0;
+ break;
+ case JONG:
+ hp->a = (LRAND() / MAXRAND) * 2.0 * M_PI - M_PI;
+ hp->b = (LRAND() / MAXRAND) * 2.0 * M_PI - M_PI;
+ hp->c = (LRAND() / MAXRAND) * 2.0 * M_PI - M_PI;
+ hp->d = (LRAND() / MAXRAND) * 2.0 * M_PI - M_PI;
+ break;
+ case SINE:
+ hp->a = M_PI + ((LRAND() / MAXRAND) * 2.0 - 1.0) * 0.7;
+ break;
+ }
+ if (MI_NPIXELS(mi) > 2)
+ hp->pix = NRAND(MI_NPIXELS(mi));
+ hp->i = hp->j = 0.0;
+ hp->inc = (int) ((LRAND() / MAXRAND) * 200) - 100;
+ hp->bufsize = MI_BATCHCOUNT(mi);
+
+ if (!pointBuffer)
+ pointBuffer = (XPoint *) malloc(hp->bufsize * sizeof (XPoint));
+
+ XClearWindow(display, MI_WINDOW(mi));
+
+ XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
+ hp->count = 0;