+{
+ lisacons *lc = &Lisa[MI_SCREEN(mi)];
+ lisafuncs **lf = loop->function;
+ XPoint *lp;
+ int phase, pctr, fctr, xctr, yctr, extra_points;
+ double xprod, yprod, xsum, ysum;
+
+ xMaxLines = (XMaxRequestSize(MI_DISPLAY(mi))-3)/2;
+ /* printf("Got xMaxLines = %d\n", xMaxLines); */
+ loop->nsteps = MI_CYCLES(mi);
+ if (loop->nsteps == 0)
+ loop->nsteps = 1;
+ if (MI_NPIXELS(mi) > 2) {
+ loop->color = STARTCOLOR;
+ loop->cstep = (loop->nsteps > MI_NPIXELS(mi)) ? loop->nsteps / MI_NPIXELS(mi) : 1;
+ } else {
+ loop->color = MI_WHITE_PIXEL(mi);
+ loop->cstep = 0;
+ }
+ extra_points = loop->cstep - (loop->nsteps % loop->cstep);
+ lc->maxcycles = (MAXCYCLES * loop->nsteps) - 1;
+ loop->cstep = ( loop->nsteps > MI_NPIXELS(mi) ) ? loop->nsteps / MI_NPIXELS(mi) : 1;
+ /* printf("Got cstep = %d\n", loop->cstep); */
+ loop->melting = 0;
+ loop->nfuncs = 1;
+ loop->pistep = 2.0 * M_PI / (double) loop->nsteps;
+ loop->center.x = lc->width / 2;
+ loop->center.y = lc->height / 2;
+ loop->radius = (int) MI_SIZE(mi);
+ CHECK_RADIUS(loop, lc);
+ loop->dx = NRAND(XVMAX);
+ loop->dy = NRAND(YVMAX);
+ loop->dx++;
+ loop->dy++;
+#if defined STARTFUNC
+ lf[0] = &Function[STARTFUNC];
+#else /* STARTFUNC */
+ lf[0] = &Function[NRAND(NUMSTDFUNCS)];
+#endif /* STARTFUNC */
+
+ if ((lp = loop->lastpoint = (XPoint *)
+ calloc(loop->nsteps+extra_points, sizeof (XPoint))) == NULL) {
+ free_lisa(lc);
+ return False;
+ }
+ phase = lc->loopcount % loop->nsteps;
+
+#if defined DEBUG
+ printf( "nsteps = %d\tcstep = %d\tmrs = %d\textra_points = %d\n",
+ loop->nsteps, loop->cstep, xMaxLines, extra_points );
+ PRINT_FUNC(lf[0]);
+#endif /* DEBUG */
+
+ for (pctr = 0; pctr < loop->nsteps; pctr++) {
+ loop->phi = (double) (pctr - phase) * loop->pistep;
+ loop->theta = (double) (pctr + phase) * loop->pistep;
+ fctr = loop->nfuncs;
+ xsum = ysum = 0.0;
+ while (fctr--) {
+ xprod = yprod = (double) loop->radius;
+ xctr = lf[fctr]->nx;
+ yctr = lf[fctr]->ny;
+ while (xctr--)
+ xprod *= sin(lf[fctr]->xcoeff[xctr] * loop->theta);
+ while (yctr--)
+ yprod *= sin(lf[fctr]->ycoeff[yctr] * loop->phi);
+ xsum += xprod;
+ ysum += yprod;
+ }
+ if (loop->nfuncs > 1) {
+ xsum /= 2.0;
+ ysum /= 2.0;
+ }
+ xsum += (double) loop->center.x;
+ ysum += (double) loop->center.y;
+
+ lp[pctr].x = (int) ceil(xsum);
+ lp[pctr].y = (int) ceil(ysum);
+ }
+ /* this fills in the extra points, so we can use segment-drawing calls */
+ for (pctr = loop->nsteps; pctr < loop->nsteps + extra_points; pctr++) {
+ lp[pctr].x=lp[pctr - loop->nsteps].x;
+ lp[pctr].y=lp[pctr - loop->nsteps].y;
+ }
+#if defined DRAWLINES
+ loop->linewidth = LINEWIDTH; /* #### make this a resource */
+
+ if (loop->linewidth == 0)
+ loop->linewidth = 1;
+ if (loop->linewidth < 0)
+ loop->linewidth = NRAND(-loop->linewidth) + 1;
+ XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), loop->linewidth,
+ LINESTYLE, LINECAP, LINEJOIN);
+#endif /* DRAWLINES */
+
+ if ( loop->cstep < xMaxLines ) {
+ /* we can send each color segment in a single request
+ * because the max request length is long enough
+ * and because we have padded out the array to have extra elements
+ * to support calls which would otherwise fall off the end*/
+ for (pctr = 0; pctr < loop->nsteps; pctr+=loop->cstep) {
+ /* Set the color */
+ SET_COLOR();
+
+#if defined DRAWLINES
+ XDrawLines(MI_DISPLAY(mi), MI_WINDOW(mi),
+ MI_GC(mi), &lp[pctr], loop->cstep, CoordModeOrigin );
+#else /* DRAWLINES */
+ XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi),
+ &lp[pctr], loop->cstep, CoordModeOrigin );
+#endif /* DRAWLINES */
+ }
+ } else { /* do it one by one as before */
+ for (pctr = 0; pctr < loop->nsteps; pctr++ ) {
+ SET_COLOR();
+
+#if defined DRAWLINES
+ XDrawLine(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi),
+ lp[pctr].x, lp[pctr].y,
+ lp[pctr+1 % loop->nsteps].x, lp[pctr+1 % loop->nsteps].y);
+#else /* DRAWLINES */
+ XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi),
+ lp[pctr].x, lp[pctr].y);
+#endif /* DRAWLINES */
+ }
+ }
+
+#if defined DRAWLINES
+ XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), 1,
+ LINESTYLE, LINECAP, LINEJOIN);
+#endif /* DRAWLINES */
+ return True;
+}
+
+static void
+refreshlisa(ModeInfo * mi)