/* *----------------------------------------------------------------------------- * Called by the mainline code periodically to update the display. *----------------------------------------------------------------------------- */ ENTRYPOINT void draw_fire(ModeInfo * mi) { firestruct *fs = &fire[MI_SCREEN(mi)]; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); MI_IS_DRAWN(mi) = True; if (!fs->glx_context) return; glXMakeCurrent(display, window, *(fs->glx_context)); DrawFire(mi); #ifndef STANDALONE Reshape(mi); /* xlock mode */ #else reshape_fire(mi,MI_WIDTH(mi),MI_HEIGHT(mi)); /* xscreensaver mode */ #endif glFinish(); glXSwapBuffers(display, window); }
void draw_goop(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i; goopstruct *gp; if (goops == NULL) return; gp = &goops[MI_SCREEN(mi)]; if (gp->layers == NULL) return; MI_IS_DRAWN(mi) = True; switch (gp->mode) { case transparent: for (i = 0; i < gp->nlayers; i++) draw_layer_plane(display, &(gp->layers[i]), gp->width, gp->height); XSetForeground(display, gp->pixmap_gc, gp->background); XSetPlaneMask(display, gp->pixmap_gc, AllPlanes); XFillRectangle(display, gp->pixmap, gp->pixmap_gc, 0, 0, gp->width, gp->height); XSetForeground(display, gp->pixmap_gc, ~0L); for (i = 0; i < gp->nlayers; i++) { XSetPlaneMask(display, gp->pixmap_gc, gp->layers[i].pixel); #if 0 XSetForeground (display, gp->pixmap_gc, ~0L); XFillRectangle (display, gp->pixmap, gp->pixmap_gc, 0, 0, gp->width, gp->height); XSetForeground (display, gp->pixmap_gc, 0L); #endif draw_layer_blobs(display, gp->pixmap, gp->pixmap_gc, &(gp->layers[i]), gp->width, gp->height, True); } XCopyArea(display, gp->pixmap, window, MI_GC(mi), 0, 0, gp->width, gp->height, 0, 0); break; case xored: XSetFunction(display, gp->pixmap_gc, GXcopy); XSetForeground(display, gp->pixmap_gc, 0); XFillRectangle(display, gp->pixmap, gp->pixmap_gc, 0, 0, gp->width, gp->height); XSetFunction(display, gp->pixmap_gc, GXxor); XSetForeground(display, gp->pixmap_gc, 1); for (i = 0; i < gp->nlayers; i++) draw_layer_blobs(display, gp->pixmap, gp->pixmap_gc, &(gp->layers[i]), gp->width, gp->height, (gp->mode != outline)); XCopyPlane(display, gp->pixmap, window, MI_GC(mi), 0, 0, gp->width, gp->height, 0, 0, 1L); break; case opaque: case outline: XSetForeground(display, gp->pixmap_gc, MI_BLACK_PIXEL(mi)); XFillRectangle(display, gp->pixmap, gp->pixmap_gc, 0, 0, gp->width, gp->height); for (i = 0; i < gp->nlayers; i++) { XSetForeground(display, gp->pixmap_gc, gp->layers[i].pixel); draw_layer_blobs(display, gp->pixmap, gp->pixmap_gc, &(gp->layers[i]), gp->width, gp->height, (gp->mode != outline)); } XCopyArea(display, gp->pixmap, window, MI_GC(mi), 0, 0, gp->width, gp->height, 0, 0); break; default: if (MI_IS_VERBOSE(mi)) { (void) fprintf(stderr, "Weirdness in draw_goop()\n"); (void) fprintf(stderr, "gp->mode = %d\n", gp->mode); } break; } }
void draw_toneclock(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i; toneclockstruct *tclock; if (toneclocks == NULL) return; tclock = &toneclocks[MI_SCREEN(mi)]; if (tclock->hour == NULL) return; if (tclock->no_colors) { free_toneclock(display, tclock); init_toneclock(mi); return; } XSetFunction(display, tclock->gc, GXxor); #ifndef NO_DBUF XSetForeground(display,tclock->dbuf_gc,MI_BLACK_PIXEL(mi)); XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc, 0, 0, tclock->win_width, tclock->win_height); #endif tclock->painted = True; MI_IS_DRAWN(mi) = True; /* Rotate colours */ if (tclock->cycle_p) { rotate_colors(display, tclock->cmap, tclock->colors, tclock->ncolors, tclock->direction); if (!(LRAND() % 1000)) tclock->direction = -tclock->direction; } for (i = 0; i < tclock->num_hour; i++) { toneclockhour *hour0; int x0 , y0; x0 = (int) (tclock->radius * sin( -tclock->angle - PI_RAD * i * 360.0 / tclock->num_hour ) * 0.5 * ( 1 + cos( tclock->phase ) ) + tclock->x0 + tclock->a_x * sin( tclock->anglex ) ); y0 = (int) (tclock->radius * cos( -tclock->angle - PI_RAD * i * 360.0 / tclock->num_hour ) * 0.5 * ( 1 + cos( tclock->phase ) ) + tclock->y0 + tclock->a_y * sin( tclock->angley ) ); hour0 = &tclock->hour[i]; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel); } else { XSetForeground(display, tclock->gc, hour0->colour); } toneclock_drawhour(mi, hour0 , x0 , y0); hour0->velocity += ((float) NRAND(1001) - 500.0) / 200000.0; hour0->angle += hour0->velocity; } tclock->velocity += ((float) NRAND(1001) - 500.0) / 200000.0; tclock->angle += tclock->velocity; if ( tclock->pulsating ) tclock->phase += tclock->ph_vel; if ( tclock->moving ) { tclock->anglex += tclock->vx; tclock->angley += tclock->vy; } #ifdef NO_DBUF for (i = 0; i < tclock->num_hour; i++) { toneclockhour *hour0; int x0 , y0; x0 = (int) (tclock->radius * sin( -tclock->angle - PI_RAD * i * 360.0 / tclock->num_hour ) * 0.5 * ( 1 + cos( tclock->phase ) ) + tclock->x0 + tclock->a_x * sin( tclock->anglex ) ); y0 = (int) (tclock->radius * cos( -tclock->angle - PI_RAD * i * 360.0 / tclock->num_hour ) * 0.5 * ( 1 + cos( tclock->phase ) ) + tclock->y0 + tclock->a_y * sin( tclock->angley ) ); hour0 = &tclock->hour[i]; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel); } else { XSetForeground(display, tclock->gc, hour0->colour); } toneclock_drawhour(mi, hour0 , x0 , y0); } #else XFlush(display); XCopyArea (display, (Drawable) tclock->dbuf, window, tclock->dbuf_gc, 0, 0, tclock->win_width, tclock->win_height, 0, 0); XFlush(display); XSetForeground(display,tclock->dbuf_gc,MI_BLACK_PIXEL(mi)); XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc, 0, 0, tclock->win_width, tclock->win_height); #endif XSetFunction(display, tclock->gc, GXcopy); }
ENTRYPOINT void draw_demon (ModeInfo * mi) { int i, j, k, l, mj = 0, ml; demonstruct *dp; if (demons == NULL) return; dp = &demons[MI_SCREEN(mi)]; if (dp->cellList == NULL) return; MI_IS_DRAWN(mi) = True; if (dp->state >= dp->states) { (void) memcpy((char *) dp->newcell, (char *) dp->oldcell, dp->ncols * dp->nrows * sizeof (unsigned char)); if (dp->neighbors == 6) { for (j = 0; j < dp->nrows; j++) { for (i = 0; i < dp->ncols; i++) { /* NE */ if (!(j & 1)) k = (i + 1 == dp->ncols) ? 0 : i + 1; else k = i; l = (!j) ? dp->nrows - 1 : j - 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* E */ k = (i + 1 == dp->ncols) ? 0 : i + 1; ml = mj; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* SE */ if (!(j & 1)) k = (i + 1 == dp->ncols) ? 0 : i + 1; else k = i; l = (j + 1 == dp->nrows) ? 0 : j + 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* SW */ if (j & 1) k = (!i) ? dp->ncols - 1 : i - 1; else k = i; l = (j + 1 == dp->nrows) ? 0 : j + 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* W */ k = (!i) ? dp->ncols - 1 : i - 1; ml = mj; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* NW */ if (j & 1) k = (!i) ? dp->ncols - 1 : i - 1; else k = i; l = (!j) ? dp->nrows - 1 : j - 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; } mj += dp->ncols; } } else if (dp->neighbors == 4 || dp->neighbors == 8) { for (j = 0; j < dp->nrows; j++) { for (i = 0; i < dp->ncols; i++) { /* N */ k = i; l = (!j) ? dp->nrows - 1 : j - 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* E */ k = (i + 1 == dp->ncols) ? 0 : i + 1; ml = mj; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* S */ k = i; l = (j + 1 == dp->nrows) ? 0 : j + 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* W */ k = (!i) ? dp->ncols - 1 : i - 1; l = j; ml = mj; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; } mj += dp->ncols; } if (dp->neighbors == 8) { mj = 0; for (j = 0; j < dp->nrows; j++) { for (i = 0; i < dp->ncols; i++) { /* NE */ k = (i + 1 == dp->ncols) ? 0 : i + 1; l = (!j) ? dp->nrows - 1 : j - 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* SE */ k = (i + 1 == dp->ncols) ? 0 : i + 1; l = (j + 1 == dp->nrows) ? 0 : j + 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* SW */ k = (!i) ? dp->ncols - 1 : i - 1; l = (j + 1 == dp->nrows) ? 0 : j + 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* NW */ k = (!i) ? dp->ncols - 1 : i - 1; l = (!j) ? dp->nrows - 1 : j - 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; } mj += dp->ncols; } } } else if (dp->neighbors == 3 || dp->neighbors == 9 || dp->neighbors == 12) { for (j = 0; j < dp->nrows; j++) { for (i = 0; i < dp->ncols; i++) { if ((i + j) % 2) { /* right */ /* W */ k = (!i) ? dp->ncols - 1 : i - 1; ml = mj; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; } else { /* left */ /* E */ k = (i + 1 == dp->ncols) ? 0 : i + 1; ml = mj; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; } /* N */ k = i; l = (!j) ? dp->nrows - 1 : j - 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* S */ k = i; l = (j + 1 == dp->nrows) ? 0 : j + 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; } mj += dp->ncols; } if (dp->neighbors == 9 || dp->neighbors == 12) { mj = 0; for (j = 0; j < dp->nrows; j++) { for (i = 0; i < dp->ncols; i++) { /* NN */ k = i; if (!j) l = dp->nrows - 2; else if (!(j - 1)) l = dp->nrows - 1; else l = j - 2; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* SS */ k = i; if (j + 1 == dp->nrows) l = 1; else if (j + 2 == dp->nrows) l = 0; else l = j + 2; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* NW */ k = (!i) ? dp->ncols - 1 : i - 1; l = (!j) ? dp->nrows - 1 : j - 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* NE */ k = (i + 1 == dp->ncols) ? 0 : i + 1; l = (!j) ? dp->nrows - 1 : j - 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* SW */ k = (!i) ? dp->ncols - 1 : i - 1; l = (j + 1 == dp->nrows) ? 0 : j + 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* SE */ k = (i + 1 == dp->ncols) ? 0 : i + 1; l = (j + 1 == dp->nrows) ? 0 : j + 1; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; } mj += dp->ncols; } if (dp->neighbors == 12) { mj = 0; for (j = 0; j < dp->nrows; j++) { for (i = 0; i < dp->ncols; i++) { if ((i + j) % 2) { /* right */ /* NNW */ k = (!i) ? dp->ncols - 1 : i - 1; if (!j) l = dp->nrows - 2; else if (!(j - 1)) l = dp->nrows - 1; else l = j - 2; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* SSW */ k = (!i) ? dp->ncols - 1 : i - 1; if (j + 1 == dp->nrows) l = 1; else if (j + 2 == dp->nrows) l = 0; else l = j + 2; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* EE */ k = (i + 1 == dp->ncols) ? 0 : i + 1; l = j; ml = mj; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; } else { /* left */ /* NNE */ k = (i + 1 == dp->ncols) ? 0 : i + 1; if (!j) l = dp->nrows - 2; else if (!(j - 1)) l = dp->nrows - 1; else l = j - 2; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* SSE */ k = (i + 1 == dp->ncols) ? 0 : i + 1; if (j + 1 == dp->nrows) l = 1; else if (j + 2 == dp->nrows) l = 0; else l = j + 2; ml = l * dp->ncols; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; /* WW */ k = (!i) ? dp->ncols - 1 : i - 1; l = j; ml = mj; if (dp->oldcell[k + ml] == (int) (dp->oldcell[i + mj] + 1) % dp->states) dp->newcell[i + mj] = dp->oldcell[k + ml]; } } mj += dp->ncols; } } } } mj = 0; for (j = 0; j < dp->nrows; j++) { for (i = 0; i < dp->ncols; i++) if (dp->oldcell[i + mj] != dp->newcell[i + mj]) { dp->oldcell[i + mj] = dp->newcell[i + mj]; if (!addtolist(mi, i, j, dp->oldcell[i + mj])) { free_demon(MI_DISPLAY(mi), dp); return; } } mj += dp->ncols; } if (++dp->generation > MI_CYCLES(mi)) init_demon(mi); dp->state = 0; } else { if (dp->ncells[dp->state]) if (!draw_state(mi, dp->state)) { free_demon(MI_DISPLAY(mi), dp); return; } dp->state++; } if (dp->redrawing) { for (i = 0; i < REDRAWSTEP; i++) { if (dp->oldcell[dp->redrawpos]) { drawcell(mi, dp->redrawpos % dp->ncols, dp->redrawpos / dp->ncols, dp->oldcell[dp->redrawpos]); } if (++(dp->redrawpos) >= dp->ncols * dp->nrows) { dp->redrawing = 0; break; } } } }
void draw_swarm(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); int b, newlimit; Bool track_p = trackmouse; int cx, cy; short prev; float speed; swarmstruct *sp; if (swarms == NULL) return; sp = &swarms[MI_SCREEN(mi)]; if (sp->segs == NULL) return; MI_IS_DRAWN(mi) = True; if (track_p) { Window r, c; int rx, ry; unsigned int m; (void) XQueryPointer(display, window, &r, &c, &rx, &ry, &cx, &cy, &m); if (cx <= sp->border || cy <= sp->border || cx >= MI_WIDTH(mi) - 1 - sp->border || cy >= MI_HEIGHT(mi) - 1 - sp->border) track_p = False; } /* <=- Wasp -=> */ /* Age the arrays. */ sp->wx[2] = sp->wx[1]; sp->wx[1] = sp->wx[0]; sp->wy[2] = sp->wy[1]; sp->wy[1] = sp->wy[0]; if (track_p) { sp->wx[0] = cx; sp->wy[0] = cy; } else { /* Accelerate */ sp->wxv += balance_rand(WASPACC); sp->wyv += balance_rand(WASPACC); /* Speed Limit Checks */ speed = sqrt((double) sp->wxv * sp->wxv + sp->wyv * sp->wyv); if (speed > WASPVEL) { newlimit = (int) ((NRAND(WASPVEL) + WASPVEL / 2) / speed); sp->wxv *= newlimit; sp->wyv *= newlimit; } /* Move */ sp->wx[0] = sp->wx[1] + sp->wxv; sp->wy[0] = sp->wy[1] + sp->wyv; /* Bounce Checks */ if ((sp->wx[0] < sp->border) || (sp->wx[0] > sp->width - sp->border - 1)) { sp->wxv = -sp->wxv; sp->wx[0] += sp->wxv; } if ((sp->wy[0] < sp->border) || (sp->wy[0] > sp->height - sp->border - 1)) { sp->wyv = -sp->wyv; sp->wy[0] += sp->wyv; } /* Don't let things settle down. */ sp->xv[NRAND(sp->beecount)] += balance_rand(3); sp->yv[NRAND(sp->beecount)] += balance_rand(3); } /* <=- Bees -=> */ sp->tick = ++(sp->tick) % (sp->taillen); prev = (sp->tick) ? sp->tick - 1 : sp->taillen - 1; if (sp->tick == sp->taillen - 1) sp->rolloverflag = 1; for (b = 0; b < sp->beecount; b++) { int distance, dx, dy; /* Accelerate */ dx = (int) (sp->wx[1] - X(prev, b)); dy = (int) (sp->wy[1] - Y(prev, b)); distance = (int) sqrt((double) dx * dx + dy * dy); if (distance == 0) distance = 1; sp->xv[b] += dx * BEEACC / (2 * distance); sp->yv[b] += dy * BEEACC / (2 * distance); /* Speed Limit Checks */ speed = sqrt(sp->xv[b] * sp->xv[b] + sp->yv[b] * sp->yv[b]); if (speed > BEEVEL) { newlimit = (int) ((NRAND(BEEVEL) + BEEVEL / 2) / speed); sp->xv[b] *= newlimit; sp->yv[b] *= newlimit; } /* Move */ X(sp->tick, b) = X(prev, b) + sp->xv[b]; Y(sp->tick, b) = Y(prev, b) + sp->yv[b]; /* Fill the segment lists. */ sp->segs[b].x1 = (short) X(sp->tick, b); sp->segs[b].y1 = (short) Y(sp->tick, b); sp->segs[b].x2 = (short) X(prev, b); sp->segs[b].y2 = (short) Y(prev, b); sp->old_segs[b].x1 = (short) X(((sp->tick+2)%sp->taillen), b); sp->old_segs[b].y1 = (short) Y(((sp->tick+2)%sp->taillen), b); sp->old_segs[b].x2 = (short) X(((sp->tick+1)%sp->taillen), b); sp->old_segs[b].y2 = (short) Y(((sp->tick+1)%sp->taillen), b); } XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XDrawLine(display, window, gc, sp->wx[1], sp->wy[1], sp->wx[2], sp->wy[2]); if (sp->rolloverflag) { XDrawSegments(display, window, gc, sp->old_segs, sp->beecount); } XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); XDrawLine(display, window, gc, sp->wx[0], sp->wy[0], sp->wx[1], sp->wy[1]); if (MI_NPIXELS(mi) > 2) { XSetForeground(display, gc, MI_PIXEL(mi, sp->pix)); if (++sp->pix >= MI_NPIXELS(mi)) sp->pix = 0; } XDrawSegments(display, window, gc, sp->segs, sp->beecount); }
void draw_morph3d(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); morph3dstruct *mp; if (morph3d == NULL) return; mp = &morph3d[MI_SCREEN(mi)]; if (!mp->glx_context) return; MI_IS_DRAWN(mi) = True; #ifdef WIN32 wglMakeCurrent(hdc, mp->glx_context); #else glXMakeCurrent(display, window, *(mp->glx_context)); #endif glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(0.0, 0.0, -10.0); if (!MI_IS_ICONIC(mi)) { glScalef(Scale4Window * mp->WindH / mp->WindW, Scale4Window, Scale4Window); glTranslatef(2.5 * mp->WindW / mp->WindH * sin(mp->step * 1.11), 2.5 * cos(mp->step * 1.25 * 1.11), 0); } else { glScalef(Scale4Iconic * mp->WindH / mp->WindW, Scale4Iconic, Scale4Iconic); } glRotatef(mp->step * 100, 1, 0, 0); glRotatef(mp->step * 95, 0, 1, 0); glRotatef(mp->step * 90, 0, 0, 1); mp->seno = (sin(mp->step) + 1.0 / 3.0) * (4.0 / 5.0) * mp->Magnitude; if (mp->VisibleSpikes) { #ifdef DEBUG_CULL_FACE int loop; for (loop = 0; loop < 20; loop++) mp->MaterialColor[loop] = MaterialGray; #endif glDisable(GL_CULL_FACE); } else { #ifdef DEBUG_CULL_FACE int loop; for (loop = 0; loop < 20; loop++) mp->MaterialColor[loop] = MaterialWhite; #endif glEnable(GL_CULL_FACE); } mp->draw_object(mi); glPopMatrix(); glFlush(); if (MI_IS_FPS(mi)) do_fps (mi); glXSwapBuffers(display, window); mp->step += 0.05; }
void draw_bouboule(ModeInfo * mi) /****************/ { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); int i, diff = 0; double CX, CY, CZ, SX, SY, SZ; Star *star; XArc *arc, *arcleft = (XArc *) NULL; StarField *sp; #if (ADAPT_ERASE == 1) struct timeval tv1; struct timeval tv2; #endif #if ((USEOLDXARCS == 0) || (ADAPT_ERASE == 1)) short x_1, y_1, x_2, y_2; /* bounding rectangle around the old starfield, * for erasing with the smallest rectangle * instead of filling the whole screen */ int maxdiff = 0; /* maximal distance between left and right */ /* star in 3d mode, otherwise 0 */ #endif if (starfield == NULL) return; sp = &starfield[MI_SCREEN(mi)]; if (sp->star == NULL) return; MI_IS_DRAWN(mi) = True; #if ((USEOLDXARCS == 0) || (ADAPT_ERASE == 1)) if (MI_IS_USE3D(mi)) { maxdiff = (int) MAXDIFF; } x_1 = (int) sp->x.value - (int) sp->sizex.value - sp->max_star_size - maxdiff; y_1 = (int) sp->y.value - (int) sp->sizey.value - sp->max_star_size; x_2 = 2 * ((int) sp->sizex.value + sp->max_star_size + maxdiff); y_2 = 2 * ((int) sp->sizey.value + sp->max_star_size); #endif /* We make variables vary. */ sinvary(&sp->thetax); sinvary(&sp->thetay); sinvary(&sp->thetaz); sinvary(&sp->x); sinvary(&sp->y); if (MI_IS_USE3D(mi)) sinvary(&sp->z); /* A little trick to prevent the bouboule from being * bigger than the screen */ sp->sizex.maximum = MIN(((double) sp->width) - sp->x.value, sp->x.value); sp->sizex.minimum = sp->sizex.maximum / 3.0; /* Another trick to make the ball not too flat */ sp->sizey.minimum = MAX(sp->sizex.value / MAX_SIZEX_SIZEY, sp->sizey.maximum / 3.0); sp->sizey.maximum = MIN(sp->sizex.value * MAX_SIZEX_SIZEY, MIN(((double) sp->height) - sp->y.value, sp->y.value)); sinvary(&sp->sizex); sinvary(&sp->sizey); /* * We calculate the rotation matrix values. We just make the * rotation on the fly, without using a matrix. * Star positions are recorded as unit vectors pointing in various * directions. We just make them all rotate. */ CX = cos(sp->thetax.value); SX = sin(sp->thetax.value); CY = cos(sp->thetay.value); SY = sin(sp->thetay.value); CZ = cos(sp->thetaz.value); SZ = sin(sp->thetaz.value); for (i = 0; i < sp->NbStars; i++) { star = &(sp->star[i]); arc = &(sp->xarc[i]); if (MI_IS_USE3D(mi)) { arcleft = &(sp->xarcleft[i]); /* to help the eyes, the starfield is always as wide as */ /* deep, so .sizex.value can be used. */ diff = (int) GETZDIFF(sp->sizex.value * ((SY * CX) * star->x + (SX) * star->y + (CX * CY) * star->z) + sp->z.value); } arc->x = (short) ((sp->sizex.value * ((CY * CZ - SX * SY * SZ) * star->x + (-CX * SZ) * star->y + (SY * CZ + SZ * SX * CY) * star->z) + sp->x.value)); arc->y = (short) ((sp->sizey.value * ((CY * SZ + SX * SY * CZ) * star->x + (CX * CZ) * star->y + (SY * SZ - SX * CY * CZ) * star->z) + sp->y.value)); if (MI_IS_USE3D(mi)) { arcleft->x = (short) ((sp->sizex.value * ((CY * CZ - SX * SY * SZ) * star->x + (-CX * SZ) * star->y + (SY * CZ + SZ * SX * CY) * star->z) + sp->x.value)); arcleft->y = (short) ((sp->sizey.value * ((CY * SZ + SX * SY * CZ) * star->x + (CX * CZ) * star->y + (SY * SZ - SX * CY * CZ) * star->z) + sp->y.value)); arc->x += diff; arcleft->x -= diff; } if (star->size != 0) { arc->x -= star->size; arc->y -= star->size; if (MI_IS_USE3D(mi)) { arcleft->x -= star->size; arcleft->y -= star->size; } } } /* First, we erase the previous starfield */ if (MI_IS_INSTALL(mi) && MI_IS_USE3D(mi)) XSetForeground(display, gc, MI_NONE_COLOR(mi)); else XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); #if (ADAPT_ERASE == 1) if (sp->hasbeenchecked == 0) { /* We just calculate which method is the faster and eventually free * the oldxarc list */ if (sp->xarc_time > ADAPT_ARC_PREFERED * sp->rect_time) { sp->hasbeenchecked = -2; /* XFillRectangle mode */ free(sp->oldxarc); sp->oldxarc = (XArc *) NULL; if (MI_IS_USE3D(mi)) { free(sp->oldxarcleft); sp->oldxarcleft = (XArc *) NULL; } } else { sp->hasbeenchecked = -1; /* XFillArcs mode */ } } if (sp->hasbeenchecked == -2) { /* Erasing is done with XFillRectangle */ XFillRectangle(display, window, gc, x_1, y_1, x_2, y_2); } else if (sp->hasbeenchecked == -1) { /* Erasing is done with XFillArcs */ XFillArcs(display, window, gc, sp->oldxarc, sp->NbStars); if (MI_IS_USE3D(mi)) XFillArcs(display, window, gc, sp->oldxarcleft, sp->NbStars); } else { long usec; if (sp->hasbeenchecked > ADAPT_CHECKS) { GETTIMEOFDAY(&tv1); XFillRectangle(display, window, gc, x_1, y_1, x_2, y_2); GETTIMEOFDAY(&tv2); usec = (tv2.tv_sec - tv1.tv_sec) * 1000000; if (usec + tv2.tv_usec - tv1.tv_usec > 0) { sp->rect_time += usec + tv2.tv_usec - tv1.tv_usec; sp->hasbeenchecked--; } } else { GETTIMEOFDAY(&tv1); XFillArcs(display, window, gc, sp->oldxarc, sp->NbStars); if (MI_IS_USE3D(mi)) XFillArcs(display, window, gc, sp->oldxarcleft, sp->NbStars); GETTIMEOFDAY(&tv2); usec = (tv2.tv_sec - tv1.tv_sec) * 1000000; if (usec + tv2.tv_usec - tv1.tv_usec > 0) { sp->xarc_time += usec + tv2.tv_usec - tv1.tv_usec; sp->hasbeenchecked--; } } } #else #if (USEOLDXARCS == 1) XFillArcs(display, window, gc, sp->oldxarc, sp->NbStars); if (MI_IS_USE3D(mi)) XFillArcs(display, window, gc, sp->oldxarcleft, sp->NbStars); #else XFillRectangle(display, window, gc, x_1, y_1, x_2, y_2); #endif #endif /* Then we draw the new one */ if (MI_IS_USE3D(mi)) { if (MI_IS_INSTALL(mi)) XSetFunction(display, gc, GXor); XSetForeground(display, gc, MI_RIGHT_COLOR(mi)); XFillArcs(display, window, gc, sp->xarc, sp->NbStars); XSetForeground(display, gc, MI_LEFT_COLOR(mi)); XFillArcs(display, window, gc, sp->xarcleft, sp->NbStars); if (MI_IS_INSTALL(mi)) XSetFunction(display, gc, GXcopy); } else { XSetForeground(display, gc, sp->color); XFillArcs(display, window, gc, sp->xarc, sp->NbStars); } #if ((USEOLDXARCS == 1) || (ADAPT_ERASE == 1)) #if (ADAPT_ERASE == 1) if (sp->hasbeenchecked >= -1) { arc = sp->xarc; sp->xarc = sp->oldxarc; sp->oldxarc = arc; if (MI_IS_USE3D(mi)) { arcleft = sp->xarcleft; sp->xarcleft = sp->oldxarcleft; sp->oldxarcleft = arcleft; } } #else arc = sp->xarc; sp->xarc = sp->oldxarc; sp->oldxarc = arc; if (MI_IS_USE3D(mi)) { arcleft = sp->xarcleft; sp->xarcleft = sp->oldxarcleft; sp->oldxarcleft = arcleft; } #endif #endif /* We set up the color for the next drawing */ if (!MI_IS_USE3D(mi) && MI_NPIXELS(mi) > 2 && (++sp->colorchange >= COLOR_CHANGES)) { sp->colorchange = 0; if (++sp->colorp >= MI_NPIXELS(mi)) sp->colorp = 0; sp->color = MI_PIXEL(mi, sp->colorp); } }
ENTRYPOINT void draw_hop(ModeInfo * mi) { double oldj, oldi; XPoint *xp; int k; hopstruct *hp; if (hops == NULL) return; hp = &hops[MI_SCREEN(mi)]; #ifdef STANDALONE if (hp->eraser) { hp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), hp->eraser); return; } #endif if (hp->pointBuffer == NULL) return; xp = hp->pointBuffer; k = hp->bufsize; MI_IS_DRAWN(mi) = True; hp->inc++; if (MI_NPIXELS(mi) > 2) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, hp->pix)); if (++hp->pix >= MI_NPIXELS(mi)) hp->pix = 0; } while (k--) { oldj = hp->j; switch (hp->op) { case MARTIN: /* SQRT, MARTIN1 */ oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj + ((hp->i < 0) ? sqrt(fabs(hp->b * oldi - hp->c)) : -sqrt(fabs(hp->b * oldi - hp->c))); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case EJK1: oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - ((hp->i > 0) ? (hp->b * oldi - hp->c) : -(hp->b * oldi - hp->c)); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case EJK2: oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - ((hp->i < 0) ? log(fabs(hp->b * oldi - hp->c)) : -log(fabs(hp->b * oldi - hp->c))); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case EJK3: oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c : -sin(hp->b * oldi) - hp->c); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case EJK4: oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c : -sqrt(fabs(hp->b * oldi - hp->c))); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case EJK5: oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c : -(hp->b * oldi - hp->c)); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case EJK6: oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - asin((hp->b * oldi) - (long) (hp->b * oldi)); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case RR: /* RR1 */ oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - ((hp->i < 0) ? -pow(fabs(hp->b * oldi - hp->c), hp->d) : pow(fabs(hp->b * oldi - hp->c), hp->d)); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; case POPCORN: #define HVAL 0.05 #define INCVAL 50 { double tempi, tempj; if (hp->inc >= 100) hp->inc = 0; if (hp->inc == 0) { if (hp->a++ >= INCVAL) { hp->a = 0; if (hp->b++ >= INCVAL) hp->b = 0; } hp->i = (-hp->c * INCVAL / 2 + hp->c * hp->a) * M_PI / 180.0; hp->j = (-hp->c * INCVAL / 2 + hp->c * hp->b) * M_PI / 180.0; } tempi = hp->i - HVAL * sin(hp->j + tan(3.0 * hp->j)); tempj = hp->j - HVAL * sin(hp->i + tan(3.0 * hp->i)); xp->x = hp->centerx + (int) (MI_WIDTH(mi) / 40 * tempi); xp->y = hp->centery + (int) (MI_HEIGHT(mi) / 40 * tempj); hp->i = tempi; hp->j = tempj; } break; case JONG: if (hp->centerx > 0) oldi = hp->i + 4 * hp->inc / hp->centerx; else oldi = hp->i; hp->j = sin(hp->c * hp->i) - cos(hp->d * hp->j); hp->i = sin(hp->a * oldj) - cos(hp->b * oldi); xp->x = hp->centerx + (int) (hp->centerx * (hp->i + hp->j) / 4.0); xp->y = hp->centery - (int) (hp->centery * (hp->i - hp->j) / 4.0); break; case SINE: /* MARTIN2 */ oldi = hp->i + hp->inc; hp->j = hp->a - hp->i; hp->i = oldj - sin(oldi); xp->x = hp->centerx + (int) (hp->i + hp->j); xp->y = hp->centery - (int) (hp->i - hp->j); break; } xp++; } XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), hp->pointBuffer, hp->bufsize, CoordModeOrigin); if (++hp->count > MI_CYCLES(mi)) { #ifdef STANDALONE hp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), hp->eraser); #endif /* STANDALONE */ init_hop(mi); } }
ENTRYPOINT void draw_providence(ModeInfo * mi) { providencestruct *mp; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); if(!providence) return; mp = &providence[MI_SCREEN(mi)]; MI_IS_DRAWN(mi) = True; if(!mp->glx_context) return; glXMakeCurrent(display, window, *(mp->glx_context)); /* setup twoside lighting */ glLightfv(GL_LIGHT0, GL_AMBIENT, ambient2); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_POSITION, mp->position0); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); glFrontFace(GL_CCW); /* glDisable(GL_CULL_FACE); */ glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glRotatef(current_device_rotation(), 0, 0, 1); /* modify camera */ if(fabs(mp->camera_velocity) > EPSILON) { mp->camera_z = max(min(mp->camera_z + 0.1*mp->camera_velocity, -4.0), -12.0); mp->camera_velocity = 0.95*mp->camera_velocity; } /* rotate providence */ glTranslatef(0.0, 0.0, mp->camera_z + sin(mp->theta/4.0)); glRotatef(10.0+20.0*sin(mp->theta/2.0), 1.0, 0.0, 0.0); gltrackball_rotate(mp->trackball); glRotatef(mp->theta * 180.0 / Pi, 0.0, -1.0, 0.0); # ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */ { GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi); int o = (int) current_device_rotation(); if (o != 0 && o != 180 && o != -180) glScalef (1/h, 1/h, 1/h); } # endif /* draw providence */ draw_providence_strip(mi); glPopMatrix(); if(MI_IS_FPS(mi)) do_fps (mi); glFlush(); glXSwapBuffers(display, window); /* update */ mp->currenttime += 1.0 / FPS; mp->theta = mp->currenttime / 2.0 * mp->theta_scale; update_particles(mp); }
void draw_xcl(ModeInfo * mi) { static int count = 0; int i; xclstruct *dp; if (xcls == NULL) return; dp = &xcls[MI_SCREEN(mi)]; if (dp->erase_gc == None) return; MI_IS_DRAWN(mi) = True; if(viewmodel == True) { dp->Vx = 1; /* movement in X (width,negativ)*/ if(dp->width < 900) dp->Vy = 800*800/dp->width; /* Y (deep)*/ else dp->Vy = 800*1200/dp->width; /* Y (deep)*/ dp->Vz = -300; /* Z (height) */ dp->G = 350.0; /* make it smaller when display is smaller */ dp->Alpha += 0.03; dp->Beta += 0.006; dp->Gamma += 0.009; if (count != 0) { XDrawSegments(MI_DISPLAY(mi),MI_WINDOW(mi),dp->erase_gc, dp->xseg_old[0],dp->lines); XDrawSegments(MI_DISPLAY(mi),MI_WINDOW(mi),dp->gc[0], dp->xseg[0],dp->lines); (void) usleep(ROTATEDELAY * 2); } (void) memcpy(dp->xseg_old[0],dp->xseg[0],sizeof(XSegment)*dp->lines); view_3d(dp->xseg[0],dp); count ++; } else { if(automatic) dp->G = dp->width / 2.1 ; for(i=0;i<dp->planes;i++) { (void) memcpy(dp->xseg_old[i],dp->xseg[i],sizeof(XSegment)*dp->lines); dp->Alpha = - dp->alpha[i]; dp->Beta = - dp->el[i]; dp->Gamma = dp->az[i]; dp->Vx = -(int)(cos(dp->az[i]) * cos(dp->el[i]) * line_length); dp->Vy = spectator - (int)(sin(dp->az[i]) * cos(dp->el[i]) * line_length); dp->Vz = (int)(sin(dp->el[i]) * line_length); view_3d(dp->xseg[i],dp); XDrawSegments(MI_DISPLAY(mi),MI_WINDOW(mi),dp->erase_gc, dp->xseg_old[i],dp->lines); XDrawSegments(MI_DISPLAY(mi),MI_WINDOW(mi),dp->gc[i], dp->xseg[i],dp->lines); } XFlush(MI_DISPLAY(mi)); /* now move all planes */ for(i=0;i<dp->planes;i++) { dp->delta_az[i] = cos(dp->alpha[i]) * dp->omega_const[i] * frametime/1000000; dp->delta_el[i] = sin(dp->alpha[i]) * dp->omega_const[i] * frametime/1000000; dp->az[i] -= dp->delta_az[i]; dp->el[i] -= dp->delta_el[i]; if (dp->el[i] >= 0.0) switch (dp->turn[i]) { case 0: dp->turn_direction[i] *= -1; dp->alpha[i] += 0.62831853 * dp->turn_direction[i]; dp->turn[i] ++; break; case 1: case 2: case 3: case 4: case 5: dp->alpha[i] += 0.62831853 * dp->turn_direction[i]; dp->turn[i] ++; break; default: dp->turn[i] ++; break; } else dp->turn[i] = 0; if (dp->el[i] <= -(M_PI / 2.0)) { dp->alpha[i] += M_PI; dp->az[i] += M_PI; /* el[i] = el[i] + (M_PI / 2.0) ; */ } else if(dp->turn[i] == 0) dp->alpha[i] += (double)(RAND(600)) / 6283.0 * 2.0 * M_PI; } /* for (i) */ count++; (void) usleep(dp->xcldelay); if((count % REGULATE) == 0) { (void) gettimeofday(&(dp->tv1),0); dp->time2 = (double)dp->tv1.tv_sec + (double)dp->tv1.tv_usec/ (double)1000000; dp->time3 = dp->time2 - dp->time1; dp->time1 = dp->time2; dp->drawtime = (int) (dp->time3 * (1000000/REGULATE)) - dp->xcldelay; if((dp->xcldelay = frametime - dp->drawtime) <= 0) { dp->xcldelay = 10; /* 1 is possible xor xscreensaver mode */ } if(debug == True) (void) printf("t_draw: %d, t_delay: %d\n",dp->drawtime, dp->xcldelay); } } }
ENTRYPOINT void draw_strange(ModeInfo * mi) { int i, j, n, Cur_Pt; PRM x, y, xo, yo; DBL u; XPoint *Buf; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); DBL Lx, Ly; void (*Iterate) (ATTRACTOR *, PRM, PRM, PRM *, PRM *); PRM xmin, xmax, ymin, ymax; ATTRACTOR *A; if (Root == NULL) return; A = &Root[MI_SCREEN(mi)]; if (A->Fold == NULL) return; Cur_Pt = A->Cur_Pt; Iterate = A->Iterate; u = (DBL) (A->Count) / 40000.0; for (j = MAX_PRM - 1; j >= 0; --j) A->Prm[j] = DBL_To_PRM((1.0 - u) * A->Prm1[j] + u * A->Prm2[j]); /* We collect the accumulation of the orbits in the 2d int array field. */ #ifndef POINTS_HISTORY #ifdef useAccumulator if (useAccumulator) { for (i=0;i<A->Width;i++) { for (j=0;j<A->Height;j++) { A->accMap[i][j] = 0; } } } #endif #endif x = y = DBL_To_PRM(.0); for (n = SKIP_FIRST; n; --n) { (*Iterate) (A, x, y, &xo, &yo); x = xo + NRAND(8) - 4; y = yo + NRAND(8) - 4; } xmax = 0; xmin = UNIT * 4; ymax = 0; ymin = UNIT * 4; A->Cur_Pt = 0; Buf = A->Buffer2; Lx = (DBL) A->Width / UNIT / 2.2; Ly = (DBL) A->Height / UNIT / 2.2; for (n = A->Max_Pt; n; --n) { (*Iterate) (A, x, y, &xo, &yo); #ifdef useAccumulator if (useAccumulator) { int mx,my; mx = (short) ( A->Width*0.1 + A->Width*0.8 * (xo - xmin) / (xmax - xmin) ); my = (short) ( A->Width*0.1 + (A->Height - A->Width*0.2) * (yo - ymin) / (ymax - ymin) ); if (mx>=0 && my>=0 && mx<A->Width && my<A->Height) { A->accMap[mx][my]++; } #ifdef POINTS_HISTORY /* #define clearOldPoint(i) { if (startedClearing) { field[oldPoints[i].x][oldPoints[i].y]--; } } #define saveUnplot(X,Y) { clearOldPoint(oldPointsIndex) oldPoints[oldPointsIndex].x = X; oldPoints[oldPointsIndex].y = Y; oldPointsIndex = (oldPointsIndex + 1) % numOldPoints; if (oldPointsIndex==0) { startedClearing=1; } } saveUnplot(mx,my) */ if (startedClearing) { int oldX = oldPointsX[oldPointsIndex]; int oldY = oldPointsY[oldPointsIndex]; if (oldX>=0 && oldY>=0 && oldX<A->Width && oldY<A->Height) { A->accMap[oldX][oldY]--; } } oldPointsX[oldPointsIndex] = mx; oldPointsY[oldPointsIndex] = my; oldPointsIndex = (oldPointsIndex + 1) % numOldPoints; if (oldPointsIndex==0) { startedClearing=1; } #endif } else { #endif Buf->x = (int) (Lx * (x + DBL_To_PRM(1.1))); Buf->y = (int) (Ly * (DBL_To_PRM(1.1) - y)); Buf++; A->Cur_Pt++; #ifdef useAccumulator } #endif /* (void) fprintf( stderr, "X,Y: %d %d ", Buf->x, Buf->y ); */ if (xo > xmax) xmax = xo; else if (xo < xmin) xmin = xo; if (yo > ymax) ymax = yo; else if (yo < ymin) ymin = yo; x = xo + NRAND(8) - 4; y = yo + NRAND(8) - 4; } MI_IS_DRAWN(mi) = True; XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); #ifdef useAccumulator if (useAccumulator) { float colorScale; int col; #ifdef VARY_SPEED_TO_AVOID_BOREDOM int pixelCount = 0; #endif colorScale = (A->Width*A->Height/640.0/480.0*800000.0/(float)A->Max_Pt*(float)NUM_COLS/256); if (A->dbuf != None) { XSetForeground(display, A->dbuf_gc, 0); XFillRectangle(display, A->dbuf, A->dbuf_gc, 0, 0, A->Width, A->Height); } else { XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillRectangle(display, window, gc, 0, 0, A->Width, A->Height); } for (i=0;i<A->Width;i++) { for (j=0;j<A->Height;j++) { if (A->accMap[i][j]>0) { col = (float)A->accMap[i][j] * colorScale; if (col>NUM_COLS-1) { col = NUM_COLS-1; } #ifdef VARY_SPEED_TO_AVOID_BOREDOM if (col>0) { if (col<NUM_COLS-1) /* we don't count maxxed out pixels */ pixelCount++; } #endif if (MI_NPIXELS(mi) < 2) XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); else /*XSetForeground(display, gc, MI_PIXEL(mi, A->Col % MI_NPIXELS(mi)));*/ XSetForeground(display, gc, cols[col].pixel); if (A->dbuf != None) { XSetForeground(display, A->dbuf_gc, cols[col].pixel); XDrawPoint(display, A->dbuf, A->dbuf_gc, i, j); } else { XSetForeground(display, gc, cols[col].pixel); XDrawPoint(display, window, gc, i, j); } } } } if (A->dbuf != None) { XCopyArea(display, A->dbuf, window, gc, 0, 0, A->Width, A->Height, 0, 0); } #ifdef VARY_SPEED_TO_AVOID_BOREDOM /* Increaase the rate of change of the parameters if the attractor has become visually boring. */ if ((xmax - xmin < DBL_To_PRM(.2)) && (ymax - ymin < DBL_To_PRM(.2))) { A->Speed *= 1.25; } else if (pixelCount>0 && pixelCount<A->Width*A->Height/1000) { A->Speed *= 1.25; /* A->Count = 1000; */ } else { A->Speed = 4; /* reset to normal/default */ } if (A->Speed > 32) A->Speed = 32; A->Count += A->Speed; if (A->Count >= 1000) { for (i = MAX_PRM - 1; i >= 0; --i) A->Prm1[i] = A->Prm2[i]; Random_Prm(A->Prm2); A->Count = 0; } #endif } else { #endif if (A->dbuf != None) { /* jwz */ XSetForeground(display, A->dbuf_gc, 0); /* XDrawPoints(display, A->dbuf, A->dbuf_gc, A->Buffer1, Cur_Pt,CoordModeOrigin); */ XFillRectangle(display, A->dbuf, A->dbuf_gc, 0, 0, A->Width, A->Height); } else XDrawPoints(display, window, gc, A->Buffer1, Cur_Pt, CoordModeOrigin); if (MI_NPIXELS(mi) < 2) XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); else XSetForeground(display, gc, MI_PIXEL(mi, A->Col % MI_NPIXELS(mi))); if (A->dbuf != None) { XSetForeground(display, A->dbuf_gc, 1); XDrawPoints(display, A->dbuf, A->dbuf_gc, A->Buffer2, A->Cur_Pt, CoordModeOrigin); XCopyPlane(display, A->dbuf, window, gc, 0, 0, A->Width, A->Height, 0, 0, 1); } else XDrawPoints(display, window, gc, A->Buffer2, A->Cur_Pt, CoordModeOrigin); #ifdef useAccumulator } #endif Buf = A->Buffer1; A->Buffer1 = A->Buffer2; A->Buffer2 = Buf; if ((xmax - xmin < DBL_To_PRM(.2)) && (ymax - ymin < DBL_To_PRM(.2))) A->Count += 4 * A->Speed; else A->Count += A->Speed; if (A->Count >= 1000) { for (i = MAX_PRM - 1; i >= 0; --i) A->Prm1[i] = A->Prm2[i]; Random_Prm(A->Prm2); A->Count = 0; } A->Col++; mi->recursion_depth = A->Count; }
void draw_coral(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); int npoints = 0; int i; coralstruct *cp; if (reefs == NULL) return; cp = &reefs[MI_SCREEN(mi)]; if (cp->reef == NULL) return; MI_IS_DRAWN(mi) = True; for (i = 0; i < cp->nwalkers; i++) { int x = cp->walkers[i].x; int y = cp->walkers[i].y; if (getdot(x, y)) { /* XDrawPoint(display, window, gc, x, y); */ cp->pointbuf[npoints].x = x; cp->pointbuf[npoints].y = y; npoints++; /* Mark the surrounding area as "sticky" */ setdot((x - 1), (y - 1)); setdot(x, (y - 1)); setdot((x + 1), (y - 1)); setdot((x - 1), y); setdot((x + 1), y); setdot((x - 1), (y + 1)); setdot(x, (y + 1)); setdot((x + 1), (y + 1)); cp->nwalkers--; cp->walkers[i].x = cp->walkers[cp->nwalkers].x; cp->walkers[i].y = cp->walkers[cp->nwalkers].y; if (0 == cp->nwalkers || npoints >= MAXPOINTS) { XDrawPoints(display, window, gc, cp->pointbuf, npoints, CoordModeOrigin); npoints = 0; } if (MI_NPIXELS(mi) > 2) { XSetForeground(display, gc, MI_PIXEL(mi, cp->colorindex / COLORTHRESH)); if (++cp->colorindex >= MI_NPIXELS(mi) * COLORTHRESH) cp->colorindex = 0; } else XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); if (0 == cp->nwalkers) { if (cp->pointbuf) free(cp->pointbuf); cp->pointbuf = 0; init_coral(mi); return; } } else { /* move it a notch */ switch (rand_2()) { case 0: if (1 == x) continue; cp->walkers[i].x--; break; case 1: if (cp->width - 2 == x) continue; cp->walkers[i].x++; break; case 2: if (1 == y) continue; cp->walkers[i].y--; break; default: /* case 3: */ if (cp->height - 2 == y) continue; cp->walkers[i].y++; break; } } } if (npoints > 0) { XDrawPoints(display, window, gc, cp->pointbuf, npoints, CoordModeOrigin); } }
/*- * draw_swirl * * Draw one iteration of swirling * * - win is the window to draw in */ void draw_swirl(ModeInfo * mi) { swirlstruct *sp; if (swirls == NULL) return; sp = &(swirls[MI_SCREEN(mi)]); if (sp->knots == NULL) return; MI_IS_DRAWN(mi) = True; /* are we going? */ if (sp->started) { /* in the middle of drawing? */ if (sp->drawing) { if(sp->cycle_p) { rotate_colors(MI_DISPLAY(mi), sp->cmap, sp->colors, sp->ncolors, sp->direction); if (!(LRAND() % 1000)) sp->direction = -sp->direction; } /* draw a batch of points */ sp->batch_todo = BATCH_DRAW; while ((sp->batch_todo > 0) && sp->drawing) { /* draw a point */ draw_point(mi, sp); /* move to the next point */ next_point(sp); /* done a point */ sp->batch_todo--; } } else { if(sp->cycle_p) { rotate_colors(MI_DISPLAY(mi), sp->cmap, sp->colors, sp->ncolors, sp->direction); if (!(LRAND() % 1000)) sp->direction = -sp->direction; } /* time for a higher resolution? */ if (sp->resolution > sp->max_resolution) { /* move to higher resolution */ sp->resolution--; /* calculate the pixel step for this resulution */ sp->r = (1 << (sp->resolution - 1)); /* start drawing again */ sp->drawing = True; /* start in the middle of the screen */ sp->x = (sp->width - sp->r) / 2; sp->y = (sp->height - sp->r) / 2; /* initialise spiral drawing parameters */ sp->dir = DRAW_RIGHT; sp->dir_todo = 1; sp->dir_done = 0; } else { /* all done, decide when to restart */ if (sp->start_again == -1) { /* start the counter */ sp->start_again = RESTART; } else if (sp->start_again == 0) { /* reset the counter */ sp->start_again = -1; /* start again */ init_swirl(mi); } else /* decrement the counter */ sp->start_again--; } } } }
/* One step of the growth algorithm. */ void draw_penrose(ModeInfo * mi) { int i = 0, n; forced_node_c *p; tiling_c *tp; if (tilings == NULL) return; tp = &tilings[MI_SCREEN(mi)]; if (tp->fringe.nodes == NULL) return; MI_IS_DRAWN(mi) = True; p = tp->forced.first; if (tp->busyLoop > 0) { tp->busyLoop--; return; } if (tp->done || tp->failures >= 100) { init_penrose(mi); return; } /* Check for the initial "2-gon". */ if (tp->fringe.nodes->prev == tp->fringe.nodes->next) { vertex_type_c vtype = (unsigned char) (VT_TOTAL_MASK & LRAND()); MI_CLEARWINDOW(mi); if (!add_tile(mi, tp->fringe.nodes, S_LEFT, vtype)) free_penrose(tp); return; } /* No visible nodes left. */ if (tp->fringe.n_nodes == 0) { tp->done = True; tp->busyLoop = COMPLETION; /* Just finished drawing */ return; } if (tp->forced.n_visible > 0 && tp->failures < 10) { n = NRAND(tp->forced.n_visible); for (;;) { while (p->vertex->off_screen) p = p->next; if (i++ < n) p = p->next; else break; } } else if (tp->forced.n_nodes > 0) { n = NRAND(tp->forced.n_nodes); while (i++ < n) p = p->next; } else { fringe_node_c *fringe_p = tp->fringe.nodes; n = NRAND(tp->fringe.n_nodes); i = 0; for (; i <= n; i++) do { fringe_p = fringe_p->next; } while (fringe_p->off_screen); add_random_tile(fringe_p, mi); tp->failures = 0; return; } if (add_forced_tile(mi, p)) tp->failures = 0; else tp->failures++; }
void draw_dragon(ModeInfo * mi) { int white, black; int choose_layer, factor, orient, l; dragonstruct *dp; CellList *locallist; Bool detour = False; if (dragons == NULL) return; dp = &dragons[MI_SCREEN(mi)]; if (dp->cellList == NULL) return; MI_IS_DRAWN(mi) = True; choose_layer= NRAND(6); if (dp->ncells[!dp->addlist] == 1) { /* Since the maze is infinite, it may not get to this last * spot for a while. Force it to do it right away so it * does not appear to be stuck. */ detour = True; white = black = 0; /* not used but make -Wall happy */ } else { white = (choose_layer / 2); black = (choose_layer % 2) ? ((white + 2) % 3) : ((white + 1) % 3); /* gray = (choose_layer % 2) ? ((white + 1) % 3) : ((white + 2) % 3); */ } locallist = dp->cellList[!dp->addlist]; orient = dp->generation % 2; factor = 1; for (l = 0; l < dp->generation / 2; l++) { factor *= 3; } if (!locallist && dp->generation >= MI_CYCLES(mi)) { init_dragon(mi); return; } while (locallist) { int i, j, k; i = locallist->pt.x; j = locallist->pt.y; if (orient) { k = (j / factor) % 3; } else { if (j % 2) { /* Had trouble with this line... */ k = ((i + factor / 2) / factor + 1) % 3; } else { k = (i / factor) % 3; } } if (detour) { k = (LRAND() & 1) + 1; dp->oldcell[j * dp->ncols + i] = k; drawcell(mi, i, j, k); } if (white == k) { dp->oldcell[j * dp->ncols + i] = 0; drawcell(mi, i, j, 0); if (!addtolist(mi, i, j)) { free_dragon(MI_DISPLAY(mi), dp); return; } } else if (black == k) { dp->oldcell[j * dp->ncols + i] = 1; drawcell(mi, i, j, 1); } else /* if (gray == k) */ { dp->oldcell[j * dp->ncols + i] = 2; drawcell(mi, i, j, 2); } dp->cellList[!dp->addlist] = dp->cellList[!dp->addlist]->next; free(locallist); dp->ncells[!dp->addlist]--; locallist = dp->cellList[!dp->addlist]; if ((dp->cellList[!dp->addlist] == NULL) && (dp->cellList[dp->addlist] == NULL)) dp->generation = 0; } dp->addlist = !dp->addlist; if (dp->redrawing) { int i; for (i = 0; i < REDRAWSTEP; i++) { if (dp->oldcell[dp->redrawpos] != 1) { drawcell(mi, dp->redrawpos % dp->ncols, dp->redrawpos / dp->ncols, dp->oldcell[dp->redrawpos]); } if (++(dp->redrawpos) >= dp->ncols * dp->nrows) { dp->redrawing = 0; break; } } } dp->generation++; }
ENTRYPOINT void draw_morph3d(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); morph3dstruct *mp; if (morph3d == NULL) return; mp = &morph3d[MI_SCREEN(mi)]; MI_IS_DRAWN(mi) = True; if (!mp->glx_context) return; mi->polygon_count = 0; glXMakeCurrent(display, window, *(mp->glx_context)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(0.0, 0.0, -10.0); if (!MI_IS_ICONIC(mi)) { glScalef(Scale4Window * mp->WindH / mp->WindW, Scale4Window, Scale4Window); glTranslatef(2.5 * mp->WindW / mp->WindH * sin(mp->step * 1.11), 2.5 * cos(mp->step * 1.25 * 1.11), 0); } else { glScalef(Scale4Iconic * mp->WindH / mp->WindW, Scale4Iconic, Scale4Iconic); } # ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */ { GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi); int o = (int) current_device_rotation(); if (o != 0 && o != 180 && o != -180) glScalef (1/h, h, 1); } # endif glRotatef(mp->step * 100, 1, 0, 0); glRotatef(mp->step * 95, 0, 1, 0); glRotatef(mp->step * 90, 0, 0, 1); mp->seno = (sin(mp->step) + 1.0 / 3.0) * (4.0 / 5.0) * mp->Magnitude; if (mp->VisibleSpikes) { #ifdef DEBUG_CULL_FACE int loop; for (loop = 0; loop < 20; loop++) mp->MaterialColor[loop] = MaterialGray; #endif glDisable(GL_CULL_FACE); } else { #ifdef DEBUG_CULL_FACE int loop; for (loop = 0; loop < 20; loop++) mp->MaterialColor[loop] = MaterialWhite; #endif glEnable(GL_CULL_FACE); } mp->draw_object(mi); glPopMatrix(); if (MI_IS_FPS(mi)) do_fps (mi); glXSwapBuffers(display, window); mp->step += 0.05; }
void draw_molecule (ModeInfo *mi) { /* static time_t last = 0; */ time_t now = time ((time_t *) 0); molecule_configuration *mc; Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); if (mcs == NULL) return; mc = &mcs[MI_SCREEN(mi)]; if (!mc->glx_context) return; MI_IS_DRAWN(mi) = True; if (last + timeout <= now) /* randomize molecules every -timeout seconds */ { if (mc->nmolecules == 1) { if (last != 0) goto SKIP; mc->which = 0; } else if (last == 0) { mc->which = NRAND(mc->nmolecules); } else { int n = mc->which; while (n == mc->which) n = NRAND(mc->nmolecules); mc->which = n; } last = now; glNewList (mc->molecule_dlist, GL_COMPILE); ensure_bounding_box_visible (mi); if (MI_IS_ICONIC(mi)) {do_labels = False; do_bonds = True; do_titles = False; } else { do_labels = orig_do_labels; do_bonds = orig_do_bonds; do_titles = orig_do_titles; } cur_wire = orig_wire; if (mc->molecule_size > mc->no_label_threshold) do_labels = 0; if (mc->molecule_size > mc->wireframe_threshold) cur_wire = 1; if (cur_wire) do_bonds = 1; build_molecule (mi); glEndList(); } SKIP: glPushMatrix (); glScalef(1.1, 1.1, 1.1); { GLfloat x, y, z; if (do_wander) { static int frame = 0; # define SINOID(SCALE,SIZE) \ ((((1 + sin((frame * (SCALE)) / 2 * M_PI)) / 2.0) * (SIZE)) - (SIZE)/2) x = SINOID(0.031, 9.0); y = SINOID(0.023, 9.0); z = SINOID(0.017, 9.0); frame++; glTranslatef(x, y, z); } if (mc->spin_x || mc->spin_y || mc->spin_z) { x = mc->rotx; y = mc->roty; z = mc->rotz; if (x < 0) x = 1 - (x + 1); if (y < 0) y = 1 - (y + 1); if (z < 0) z = 1 - (z + 1); if (mc->spin_x) glRotatef(x * 360, 1.0, 0.0, 0.0); if (mc->spin_y) glRotatef(y * 360, 0.0, 1.0, 0.0); if (mc->spin_z) glRotatef(z * 360, 0.0, 0.0, 1.0); rotate(&mc->rotx, &mc->dx, &mc->ddx, mc->d_max, MI_IS_VERBOSE(mi)); rotate(&mc->roty, &mc->dy, &mc->ddy, mc->d_max, MI_IS_VERBOSE(mi)); rotate(&mc->rotz, &mc->dz, &mc->ddz, mc->d_max, MI_IS_VERBOSE(mi)); } } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glCallList (mc->molecule_dlist); glPopMatrix (); if (MI_IS_FPS(mi)) do_fps (mi); glFinish(); glXSwapBuffers(dpy, window); }
void draw_dilemma(ModeInfo * mi) { int col, row, mrow, colrow, n, i; dilemmastruct *dp; if (dilemmas == NULL) return; dp = &dilemmas[MI_SCREEN(mi)]; if (dp->s == NULL) return; MI_IS_DRAWN(mi) = True; if (dp->state >= 2 * COLORS) { for (col = 0; col < dp->ncols; col++) { for (row = 0; row < dp->nrows; row++) { colrow = col + row * dp->ncols; if (conscious) dp->payoff[colrow] = dp->pm[(int) dp->s[colrow]][(int) dp->s[colrow]]; else dp->payoff[colrow] = 0.0; for (n = 0; n < dp->neighbors; n++) dp->payoff[colrow] += dp->pm[(int) dp->s[colrow]][(int) dp->s[neighbor_position(dp, col, row, n * 360 / dp->neighbors)]]; } } for (row = 0; row < dp->nrows; row++) { for (col = 0; col < dp->ncols; col++) { float hp; int position; colrow = col + row * dp->ncols; hp = dp->payoff[colrow]; dp->sn[colrow] = dp->s[colrow]; for (n = 0; n < dp->neighbors; n++) { position = neighbor_position(dp, col, row, n * 360 / dp->neighbors); if (ROUND_FLOAT(dp->payoff[position], 0.001) > ROUND_FLOAT(hp, 0.001)) { hp = dp->payoff[position]; dp->sn[colrow] = dp->s[position]; } } } } mrow = 0; for (row = 0; row < dp->nrows; row++) { for (col = 0; col < dp->ncols; col++) { addtolist(mi, col, row, dp->sn[col + mrow] * BITMAPS + dp->s[col + mrow]); } mrow += dp->ncols; } if (++dp->generation > MI_CYCLES(mi) || dp->defectors == dp->npositions || dp->defectors == 0) init_dilemma(mi); dp->state = 0; } else { if (dp->state < COLORS) { draw_state(mi, dp->state); } dp->state++; } #if 1 if (dp->redrawing) { for (i = 0; i < REDRAWSTEP; i++) { drawcell(mi, dp->redrawpos % dp->ncols, dp->redrawpos / dp->ncols, dp->colors[(int) dp->sn[dp->redrawpos]][(int) dp->s[dp->redrawpos]], dp->sn[dp->redrawpos], False); if (++(dp->redrawpos) >= dp->npositions) { dp->redrawing = 0; break; } } } #endif }
ENTRYPOINT void draw_thornbird(ModeInfo * mi) { Display *dsp = MI_DISPLAY(mi); Window win = MI_WINDOW(mi); double oldj, oldi; int batchcount = MI_COUNT(mi); int k; XPoint *xp; GC gc = MI_GC(mi); int erase; int current; double sint, cost, sinp, cosp; thornbirdstruct *hp; if (thornbirds == NULL) return; hp = þbirds[MI_SCREEN(mi)]; if (hp->pointBuffer == NULL) return; erase = (hp->inc + 1) % MI_CYCLES(mi); current = hp->inc % MI_CYCLES(mi); k = batchcount; xp = hp->pointBuffer[current]; /* vary papameters */ hp->a = 1.99 + (0.4 * sin(hp->inc / hp->liss.f1) + 0.05 * cos(hp->inc / hp->liss.f2)); hp->c = 0.80 + (0.15 * cos(hp->inc / hp->liss.f1) + 0.05 * sin(hp->inc / hp->liss.f2)); /* vary view */ hp->tumble.theta += hp->tumble.dtheta; hp->tumble.phi += hp->tumble.dphi; sint = sin(hp->tumble.theta); cost = cos(hp->tumble.theta); sinp = sin(hp->tumble.phi); cosp = cos(hp->tumble.phi); while (k--) { oldj = hp->j; oldi = hp->i; hp->j = oldi; hp->i = (1 - hp->c) * cos(M_PI * hp->a * oldj) + hp->c * hp->b; hp->b = oldj; xp->x = (short) (hp->maxx / 2 * (1 + sint*hp->j + cost*cosp*hp->i - cost*sinp*hp->b)); xp->y = (short) (hp->maxy / 2 * (1 - cost*hp->j + sint*cosp*hp->i - sint*sinp*hp->b)); xp++; } MI_IS_DRAWN(mi) = True; if (hp->pointBuffer[erase] == NULL) { if ((hp->pointBuffer[erase] = (XPoint *) malloc(MI_COUNT(mi) * sizeof (XPoint))) == NULL) { free_thornbird(hp); return; } } else { XSetForeground(dsp, gc, MI_BLACK_PIXEL(mi)); XDrawPoints(dsp, win, gc, hp->pointBuffer[erase], batchcount, CoordModeOrigin); } if (MI_NPIXELS(mi) > 2) { XSetForeground(dsp, gc, MI_PIXEL(mi, hp->pix)); #if 0 if (erase == 0) /* change colours after "cycles" cycles */ #else if (!((hp->inc + 1) % (1 + (MI_CYCLES(mi) / 3)))) /* jwz: sooner */ #endif if (++hp->pix >= MI_NPIXELS(mi)) hp->pix = 0; } else XSetForeground(dsp, gc, MI_WHITE_PIXEL(mi)); XDrawPoints(dsp, win, gc, hp->pointBuffer[current], batchcount, CoordModeOrigin); hp->inc++; }
void draw_marquee(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); char *space = (char *) " "; unsigned char *ch; marqueestruct *mp = &marquees[MI_SCREEN(mi)]; if (marquees == NULL) return; mp = &marquees[MI_SCREEN(mi)]; if (mp->gc == None && mode_font != None) return; MI_IS_DRAWN(mi) = True; ch = (unsigned char*) mp->words; if (isRibbon()) { ch = (unsigned char*) mp->words; switch (*ch) { case '\0': if (add_blanks(mp)) { init_marquee(mi); return; } break; case '\b': case '\r': case '\n': case '\t': case '\v': case '\f': add_letter(mp, " "); mp->words++; break; default: add_letter(mp, (char *) ch); mp->words++; } if (MI_NPIXELS(mi) > 2) { XSetForeground(display, mp->gc, MI_PIXEL(mi, mp->color)); if (++mp->color == MI_NPIXELS(mi)) mp->color = 0; } else XSetForeground(display, mp->gc, MI_WHITE_PIXEL(mi)); (void) XDrawImageString(display, MI_WINDOW(mi), mp->gc, mp->x, mp->y + mp->ascent, mp->modwords, mp->t + 2); } else { switch (*ch) { case '\0': if (++mp->time > 16) init_marquee(mi); return; case '\b': if (mp->t) { /* see note in text_font_width */ mp->t--; mp->x -= char_width[(int) (' ')]; } break; case '\v': case '\f': case '\n': mp->x = mp->startx; mp->t = 0; mp->y += mp->height; if (mp->y + mp->height > mp->win_height) { XCopyArea(display, window, window, mp->gc, 0, mp->height, mp->win_width, mp->y - mp->height, 0, 0); XSetForeground(display, mp->gc, MI_BLACK_PIXEL(mi)); mp->y -= mp->height; XFillRectangle(display, window, mp->gc, 0, mp->y, mp->win_width, mp->height); } break; case '\t': (void) XDrawString(display, window, mp->gc, mp->x, mp->y + mp->ascent, space, 8 - (mp->t % 8)); mp->x += char_width[(int) (' ')] * (8 - (mp->t % 8)); mp->t = ((mp->t + 8) / 8) * 8; break; case '\r': break; default: if (MI_NPIXELS(mi) > 2) { XSetForeground(display, mp->gc, MI_PIXEL(mi, mp->color)); if (++mp->color == MI_NPIXELS(mi)) mp->color = 0; } else XSetForeground(display, mp->gc, MI_WHITE_PIXEL(mi)); if (is_char_back_char((char *) ch)) { int xmid = mp->x + (char_back_char_width((char *) ch) + 1) / 2; (void) XDrawString(display, window, mp->gc, xmid - char_width[(int) (const char) *ch] / 2, mp->y + mp->ascent, (char *) ch, 1); (void) XDrawString(display, window, mp->gc, xmid - char_width[(int) (const char) *(ch + 2)] / 2, mp->y + mp->ascent, (char *) ch + 2, 1); mp->x += char_back_char_width((char *) ch); mp->words += 2; } else { int mb = charBytes(*ch); (void) XDrawString(display, window, mp->gc, mp->x, mp->y + mp->ascent, (char *) ch, mb); mp->x += charWidth((char *) ch); } mp->t++; } mp->words += charBytes(*ch); } }
ENTRYPOINT void draw_spiral(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); GC gc = MI_GC(mi); int i, j; spiralstruct *sp; if (spirals == NULL) return; sp = &spirals[MI_SCREEN(mi)]; if (sp->traildots == NULL) return; MI_IS_DRAWN(mi) = True; if (sp->erase == 1) { XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); draw_dots(mi, sp->inc); } sp->cx += sp->dx; sp->traildots[sp->inc].hx = sp->cx; if ((sp->cx > 9000.0) || (sp->cx < 1000.0)) sp->dx *= -1.0; sp->cy += sp->dy; sp->traildots[sp->inc].hy = sp->cy; if ((sp->cy > 9000.0) || (sp->cy < 1000.0)) sp->dy *= -1.0; sp->radius += sp->dr; sp->traildots[sp->inc].hr = sp->radius; if ((sp->radius > 2500.0) && (sp->dr > 0.0)) sp->dr *= -1.0; else if ((sp->radius < 50.0) && (sp->radius < 0.0)) sp->dr *= -1.0; /* Randomly give some variations to: */ /* spiral direction (if it is within the boundaries) */ if ((NRAND(3000) < 1 * JAGGINESS) && (((sp->cx > 2000.0) && (sp->cx < 8000.0)) && ((sp->cy > 2000.0) && (sp->cy < 8000.0)))) { sp->dx = (float) (10 - NRAND(20)) * SPEED; sp->dy = (float) (10 - NRAND(20)) * SPEED; } /* The speed of the change in size of the spiral */ if (NRAND(3000) < 1 * JAGGINESS) { if (LRAND() & 1) sp->dr += (float) (NRAND(3) + 1); else sp->dr -= (float) (NRAND(3) + 1); /* don't let it get too wild */ if (sp->dr > 18.0) sp->dr = 18.0; else if (sp->dr < 4.0) sp->dr = 4.0; } /* The speed of rotation */ if (NRAND(3000) < 1 * JAGGINESS) sp->da = (float) NRAND(360) / 7200.0 + 0.01; /* Reverse rotation */ if (NRAND(3000) < 1 * JAGGINESS) sp->da *= -1.0; sp->angle += sp->da; sp->traildots[sp->inc].ha = sp->angle; if (sp->angle > TWOPI) sp->angle -= TWOPI; else if (sp->angle < 0.0) sp->angle += TWOPI; sp->colors += (float) MI_NPIXELS(mi) / ((float) (2 * sp->nlength)); if (sp->colors >= (float) MI_NPIXELS(mi)) sp->colors = 0.0; if (MI_NPIXELS(mi) > 2) XSetForeground(display, gc, MI_PIXEL(mi, (int) sp->colors)); else XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); draw_dots(mi, sp->inc); sp->inc++; if (sp->inc > sp->nlength - 1) { sp->inc -= sp->nlength; sp->erase = 1; } if (sp->redrawing) { for (i = 0; i < REDRAWSTEP; i++) { j = (sp->inc - sp->redrawpos + sp->nlength) % sp->nlength; draw_dots(mi, j); if (++(sp->redrawpos) >= sp->nlength) { sp->redrawing = 0; break; } } } }
ENTRYPOINT void draw_antmaze(ModeInfo * mi) { double h = (GLfloat) MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi); antmazestruct *mp; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); if(!antmaze) return; mp = &antmaze[MI_SCREEN(mi)]; MI_IS_DRAWN(mi) = True; if(!mp->glx_context) return; mi->polygon_count = 0; glXMakeCurrent(display, window, *(mp->glx_context)); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); /* first panel */ glPushMatrix(); /* h = ((GLfloat) MI_HEIGHT(mi)/2) / (3*(GLfloat)MI_WIDTH(mi)/4); */ glViewport(MI_WIDTH(mi)/32, MI_HEIGHT(mi)/8, (9*MI_WIDTH(mi))/16, 3*MI_HEIGHT(mi)/4); glMatrixMode(GL_PROJECTION); glLoadIdentity(); /* h = (3*MI_HEIGHT(mi)/4) / (3*MI_WIDTH(mi)/4); */ gluPerspective(45, 1/h, 1, 25.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); device_rotate(mi); glPushMatrix(); /* follow focused ant */ glTranslatef(0.0, 0.0, -mp->mag - 5.0); glRotatef(20.0+5.0*sin(mp->ant_step/40.0), 1.0, 0.0, 0.0); /* glTranslatef(0.0, */ /* started ? -mag : -8.0 + 4.0*fabs(sin(ant_step/10.0)), */ /* started ? -mag : -8.0 + 4.0*fabs(sin(ant_step/10.0))); */ gltrackball_rotate(mp->trackball); glRotatef(mp->ant_step*0.6, 0.0, 1.0, 0.0); /* glRotatef(90.0, 0.0, 0.0, 1.0); */ /* glTranslatef(-antposition[0][0]-0.5, 0.0, -antposition[focus][1]); */ /*-elevator*/ /* sync */ if(!draw_antmaze_strip(mi)) { release_antmaze(mi); return; } glPopMatrix(); glPopMatrix(); h = (GLfloat) (3*MI_HEIGHT(mi)/8) / (GLfloat) (MI_WIDTH(mi)/2); /* draw overhead */ glPushMatrix(); glViewport((17*MI_WIDTH(mi))/32, MI_HEIGHT(mi)/2, MI_WIDTH(mi)/2, 3*MI_HEIGHT(mi)/8); glMatrixMode(GL_PROJECTION); glLoadIdentity(); device_rotate(mi); gluPerspective(45, 1/h, 1, 25.0); glMatrixMode(GL_MODELVIEW); /* twist scene */ glTranslatef(0.0, 0.0, -16.0); glRotatef(60.0, 1.0, 0.0, 0.0); glRotatef(-15.0 + mp->ant_step/10.0, 0.0, 1.0, 0.0); gltrackball_rotate(mp->trackball); /* sync */ if(!draw_antmaze_strip(mi)) { release_antmaze(mi); return; } glPopMatrix(); /* draw ant display */ glPushMatrix(); glViewport((5*MI_WIDTH(mi))/8, MI_HEIGHT(mi)/8, (11*MI_WIDTH(mi))/32, 3*MI_HEIGHT(mi)/8); glMatrixMode(GL_PROJECTION); glLoadIdentity(); device_rotate(mi); gluPerspective(45, 1/h, 1, 25.0); glMatrixMode(GL_MODELVIEW); /* twist scene */ glTranslatef(0.0, 0.0, -1.6); glRotatef(30.0, 1.0, 0.0, 0.0); glRotatef(mp->ant_step, 0.0, 1.0, 0.0); glRotatef(90.0, 0.0, 0.0, 1.0); /* /\* draw ant shadow *\/ */ /* glPushMatrix(); */ /* glScalef(1.0, 0.01, 1.0); */ /* glRotatef(90.0, 0.0, 0.0, 1.0); */ /* glRotatef(90.0, 0.0, 1.0, 0.0); */ /* glDisable(GL_LIGHTING); */ /* glColor4fv(MaterialGray6); */ /* /\* slow down first ant *\/ */ /* draw_ant(MaterialGrayB, 0, 1, first_ant_step, mySphere, myCone); */ /* glPopMatrix(); */ /* draw ant body */ glEnable(GL_TEXTURE_2D); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); glBindTexture(GL_TEXTURE_2D, mp->brushedtexture); draw_ant(mi, mp, MaterialGray35, 0, 1, mp->ant_step/2.0, mySphereTex, myCone2); glDisable(GL_TEXTURE_2D); glPopMatrix(); /* /\* draw overlay *\/ */ /* glPushMatrix(); */ /* /\* go to ortho mode *\/ */ /* glViewport(MI_WIDTH(mi)/2, MI_HEIGHT(mi)/8, MI_WIDTH(mi)/2, 3*MI_HEIGHT(mi)/8); */ /* glMatrixMode(GL_PROJECTION); */ /* glLoadIdentity(); */ /* glPushMatrix (); */ /* glOrtho(-4.0, 4.0, -3.0, 3.0, -100.0, 100.0); */ /* glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGrayB); */ /* glColor4fv(MaterialGrayB); */ /* glDisable(GL_LIGHTING); */ /* glEnable(GL_BLEND); */ /* glBegin(GL_QUADS); */ /* glNormal3f(0.0, 0.0, 1.0); */ /* glVertex3f(4.0, 3.0, 0.0); */ /* glVertex3f(2.0, 3.0, 0.0); */ /* glVertex3f(2.0, -3.0, 0.0); */ /* glVertex3f(4.0, -3.0, 0.0); */ /* mi->polygon_count++; */ /* glEnd(); */ /* glEnable(GL_LIGHTING); */ /* glDisable(GL_BLEND); */ /* glPopMatrix(); */ /* glPopMatrix(); */ if (MI_IS_FPS(mi)) { glViewport(0, 0, MI_WIDTH(mi), MI_HEIGHT(mi)); do_fps (mi); } glFlush(); glXSwapBuffers(display, window); update_ants(mp); mp->step += 0.025; }
ENTRYPOINT void draw_rotor (ModeInfo * mi) { Display *display = MI_DISPLAY(mi); GC gc = MI_GC(mi); register elem *pelem; int thisx, thisy; int i; int x_1, y_1, x_2, y_2; rotorstruct *rp; if (rotors == NULL) return; rp = &rotors[MI_SCREEN(mi)]; if (rp->elements == NULL) return; MI_IS_DRAWN(mi) = True; if (!rp->iconifiedscreen) { thisx = rp->centerx; thisy = rp->centery; } else { thisx = rp->prevcenterx; thisy = rp->prevcentery; } XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), rp->linewidth, LineSolid, CapButt, JoinMiter); for (i = rp->num, pelem = rp->elements; --i >= 0; pelem++) { if (pelem->radius_drift_max <= pelem->radius_drift_now) { pelem->start_radius = pelem->end_radius; pelem->end_radius = (float) NRAND(40000) / 100.0 - 200.0; pelem->radius_drift_max = (float) NRAND(100000) + 10000.0; pelem->radius_drift_now = 0.0; } if (pelem->ratio_drift_max <= pelem->ratio_drift_now) { pelem->start_ratio = pelem->end_ratio; pelem->end_ratio = (float) NRAND(2000) / 100.0 - 10.0; pelem->ratio_drift_max = (float) NRAND(100000) + 10000.0; pelem->ratio_drift_now = 0.0; } pelem->ratio = pelem->start_ratio + (pelem->end_ratio - pelem->start_ratio) / pelem->ratio_drift_max * pelem->ratio_drift_now; pelem->angle = rp->angle * pelem->ratio; pelem->radius = pelem->start_radius + (pelem->end_radius - pelem->start_radius) / pelem->radius_drift_max * pelem->radius_drift_now; thisx += (int) (COSF(pelem->angle) * pelem->radius); thisy += (int) (SINF(pelem->angle) * pelem->radius); pelem->ratio_drift_now += 1.0; pelem->radius_drift_now += 1.0; } if (rp->firsttime) rp->firsttime = False; else { XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); x_1 = (int) rp->save[rp->rotor].x; y_1 = (int) rp->save[rp->rotor].y; x_2 = (int) rp->save[rp->prev].x; y_2 = (int) rp->save[rp->prev].y; if (rp->iconifiedscreen) { x_1 = x_1 * rp->centerx / rp->prevcenterx; x_2 = x_2 * rp->centerx / rp->prevcenterx; y_1 = y_1 * rp->centery / rp->prevcentery; y_2 = y_2 * rp->centery / rp->prevcentery; } XDrawLine(display, MI_WINDOW(mi), gc, x_1, y_1, x_2, y_2); if (MI_NPIXELS(mi) > 2) { XSetForeground(display, gc, MI_PIXEL(mi, rp->pix)); if (++rp->pix >= MI_NPIXELS(mi)) rp->pix = 0; } else XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); x_1 = rp->lastx; y_1 = rp->lasty; x_2 = thisx; y_2 = thisy; if (rp->iconifiedscreen) { x_1 = x_1 * rp->centerx / rp->prevcenterx; x_2 = x_2 * rp->centerx / rp->prevcenterx; y_1 = y_1 * rp->centery / rp->prevcentery; y_2 = y_2 * rp->centery / rp->prevcentery; } XDrawLine(display, MI_WINDOW(mi), gc, x_1, y_1, x_2, y_2); } rp->save[rp->rotor].x = rp->lastx = thisx; rp->save[rp->rotor].y = rp->lasty = thisy; ++rp->rotor; rp->rotor %= rp->nsave; ++rp->prev; rp->prev %= rp->nsave; if (rp->forward) { rp->angle += 0.01; if (rp->angle >= MAXANGLE) { rp->angle = MAXANGLE; rp->forward = False; } } else { rp->angle -= 0.1; if (rp->angle <= 0) { rp->angle = 0.0; rp->forward = True; } } if (rp->redrawing) { int j; for (i = 0; i < REDRAWSTEP; i++) { j = (rp->rotor - rp->redrawpos + rp->nsave) % rp->nsave; x_1 = (int) rp->save[j].x; y_1 = (int) rp->save[j].y; x_2 = (int) rp->save[(j - 1 + rp->nsave) % rp->nsave].x; y_2 = (int) rp->save[(j - 1 + rp->nsave) % rp->nsave].y; if (rp->iconifiedscreen) { x_1 = x_1 * rp->centerx / rp->prevcenterx; x_2 = x_2 * rp->centerx / rp->prevcenterx; y_1 = y_1 * rp->centery / rp->prevcentery; y_2 = y_2 * rp->centery / rp->prevcentery; } XDrawLine(display, MI_WINDOW(mi), gc, x_1, y_1, x_2, y_2); if (++(rp->redrawpos) >= rp->nsave) { rp->redrawing = 0; break; } } } XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), 1, LineSolid, CapButt, JoinMiter); }
void draw_mandelbrot(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int h; complex c; double demrange; mandelstruct *mp; if (mandels == NULL) return; mp = &mandels[MI_SCREEN(mi)]; MI_IS_DRAWN(mi) = True; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (mp->mono_p) { XSetForeground(display, mp->gc, mp->cur_color); } else { mp->cur_color = (mp->cur_color + 1) % mp->ncolors; XSetForeground(display, mp->gc, mp->colors[mp->cur_color].pixel); } } else { if (MI_NPIXELS(mi) > 2) XSetForeground(display, mp->gc, MI_PIXEL(mi, mp->cur_color)); else if (mp->cur_color) XSetForeground(display, mp->gc, MI_BLACK_PIXEL(mi)); else XSetForeground(display, mp->gc, MI_WHITE_PIXEL(mi)); if (++mp->cur_color >= (unsigned int) MI_NPIXELS(mi)) mp->cur_color = 0; } /* Rotate colours */ if (mp->cycle_p) { rotate_colors(display, mp->cmap, mp->colors, mp->ncolors, mp->direction); if (!(LRAND() % 1000)) mp->direction = -mp->direction; } /* so we iterate columns beyond the width of the physical screen, so that ** we just wait around and show what we've done */ if ((!mp->backwards && (mp->column >= 3 * mp->screen_width)) || (mp->backwards && (mp->column < -2 * mp->screen_width))) { /* reset to left edge of screen, bump power */ mp->backwards = (Bool) (LRAND() & 1); if (mp->backwards) mp->column = mp->screen_width - 1; else mp->column = 0; mp->power = NRAND(3) + MINPOWER; /* select a new region! */ Select(&mp->extreme_ul,&mp->extreme_lr, mp->screen_width,mp->screen_height, (int) mp->power,mp->reptop, mp->pow, mp->sin, &mp->ul,&mp->lr); } else if (mp->column >= mp->screen_width || mp->column < 0) { /* delay a while */ if (mp->backwards) mp->column--; else mp->column++; mp->counter++; return; } /* demrange is used to give some idea of scale */ demrange = mp->dem ? fabs(mp->ul.real - mp->lr.real) / 2 : 0; for (h = 0; h < mp->screen_height; h++) { unsigned int color; int result; /* c.real = 1.3 - (double) mp->column / mp->screen_width * 3.4; */ /* c.imag = -1.6 + (double) h / mp->screen_height * 3.2; */ c.real = mp->ul.real + (mp->ul.real-mp->lr.real)*(((double)(mp->column))/mp->screen_width); c.imag = mp->ul.imag + (mp->ul.imag - mp->lr.imag)*(((double) h) / mp->screen_height); result = reps(c, mp->power, mp->reptop, mp->binary, mp->interior, demrange, mp->pow, mp->sin); if (result < 0 || result >= mp->reptop) XSetForeground(display, mp->gc, MI_BLACK_PIXEL(mi)); else { color=(unsigned int) ((MI_NPIXELS(mi) * (float)result) / mp->reptop); XSetForeground(display, mp->gc, MI_PIXEL(mi, color)); } /* we no longer have vertical symmetry - so we compute all points ** and don't draw with redundancy */ XDrawPoint(display, window, mp->gc, mp->column, h); } if (mp->backwards) mp->column--; else mp->column++; mp->counter++; if (mp->counter > MI_CYCLES(mi)) { init_mandelbrot(mi); } }
void draw_life1d(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); int col; life1dstruct *lp; if (life1ds == NULL) return; lp = &life1ds[MI_SCREEN(mi)]; if (lp->buffer == NULL) return; MI_IS_DRAWN(mi) = True; if (lp->busyLoop) { if (lp->busyLoop >= 250) lp->busyLoop = 0; else lp->busyLoop++; return; } if (lp->row == 0) { lp->repeating = 0; if (lp->screen_generation > MI_CYCLES(mi)) init_life1d(mi); if (!lp->previousBuffer && lp->screen_generation > 1) { lp->previousBuffer = (unsigned char *) calloc(lp->ncols * lp->nrows, sizeof (unsigned char)); } if (lp->previousBuffer) { (void) memcpy((char *) (lp->previousBuffer), (char *) (lp->buffer), lp->nrows * lp->ncols); } for (col = 0; col < lp->ncols; col++) if (lp->buffer[col] != lp->newcells[col + lp->border]) drawcell(mi, col, 0, lp->newcells[col + lp->border]); (void) memcpy((char *) lp->buffer, (char *) (lp->newcells + lp->border), lp->ncols); } else { for (col = 0; col < lp->ncols + 2 * lp->border; col++) { int sum = 0, m; if (totalistic) { for (m = col - lp->r; m <= col + lp->r; m++) sum += lp->oldcells[m + maxradius]; } else { int pow_size = 1; for (m = col + lp->r; m >= col - lp->r; m--) { sum += lp->oldcells[m + maxradius] * pow_size; pow_size *= lp->k; } } lp->newcells[col] = (unsigned char) lp->nextstate[sum]; } (void) memcpy((char *) (lp->oldcells + maxradius), (char *) lp->newcells, lp->ncols + 2 * lp->border); for (col = 0; col < lp->ncols; col++) { if (lp->buffer[col + lp->row * lp->ncols] != lp->newcells[col + lp->border]) drawcell(mi, col, lp->row, lp->newcells[col + lp->border]); } (void) memcpy((char *) (lp->buffer + lp->row * lp->ncols), (char *) (lp->newcells + lp->border), lp->ncols); { int temp = compare(mi); if (temp) lp->repeating += temp; else lp->repeating = 0; } lp->repeating += (lp->row == lp->nrows - 1) ? (lp->nrows - 1) * compare(mi) : 0; } if (lp->repeating >= 1) { XGCValues gcv; gcv.stipple = lp->pixmaps[MAXSTATES - 1]; gcv.fill_style = FillStippled; gcv.foreground = lp->black; XChangeGC(MI_DISPLAY(mi), lp->stippledGC, GCStipple | GCFillStyle | GCForeground, &gcv); XFillRectangle(display, MI_WINDOW(mi), lp->stippledGC, 0, lp->yb + lp->ys * lp->row, lp->width, lp->ys); } lp->row++; if (lp->repeating >= lp->nrows - 1) { if (lp->row < lp->nrows) { XSetForeground(display, lp->backGC, lp->black); XFillRectangle(display, MI_WINDOW(mi), lp->backGC, 0, lp->yb + lp->ys * lp->row, lp->width, lp->height - lp->ys * lp->row - lp->yb); } lp->screen_generation = MI_CYCLES(mi); lp->row = lp->nrows; } if (lp->row >= lp->nrows) { lp->screen_generation++; lp->busyLoop = 1; lp->row = 0; } }
ENTRYPOINT void draw_strange(ModeInfo * mi) { int i, j, n, Cur_Pt; PRM x, y, xo, yo; DBL u; XPoint *Buf; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); DBL Lx, Ly; void (*Iterate) (ATTRACTOR *, PRM, PRM, PRM *, PRM *); PRM xmin, xmax, ymin, ymax; ATTRACTOR *A; if (Root == NULL) return; A = &Root[MI_SCREEN(mi)]; if (A->Fold == NULL) return; Cur_Pt = A->Cur_Pt; Iterate = A->Iterate; u = (DBL) (A->Count) / 1000.0; for (j = MAX_PRM - 1; j >= 0; --j) A->Prm[j] = DBL_To_PRM((1.0 - u) * A->Prm1[j] + u * A->Prm2[j]); x = y = DBL_To_PRM(.0); for (n = SKIP_FIRST; n; --n) { (*Iterate) (A, x, y, &xo, &yo); x = xo + NRAND(8) - 4; y = yo + NRAND(8) - 4; } xmax = 0; xmin = UNIT * 4; ymax = 0; ymin = UNIT * 4; A->Cur_Pt = 0; Buf = A->Buffer2; Lx = (DBL) A->Width / UNIT / 2.2; Ly = (DBL) A->Height / UNIT / 2.2; for (n = A->Max_Pt; n; --n) { (*Iterate) (A, x, y, &xo, &yo); Buf->x = (int) (Lx * (x + DBL_To_PRM(1.1))); Buf->y = (int) (Ly * (DBL_To_PRM(1.1) - y)); /* (void) fprintf( stderr, "X,Y: %d %d ", Buf->x, Buf->y ); */ Buf++; A->Cur_Pt++; if (xo > xmax) xmax = xo; else if (xo < xmin) xmin = xo; if (yo > ymax) ymax = yo; else if (yo < ymin) ymin = yo; x = xo + NRAND(8) - 4; y = yo + NRAND(8) - 4; } MI_IS_DRAWN(mi) = True; XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); if (A->dbuf != None) { /* jwz */ XSetForeground(display, A->dbuf_gc, 0); /* XDrawPoints(display, A->dbuf, A->dbuf_gc, A->Buffer1, Cur_Pt,CoordModeOrigin); */ XFillRectangle(display, A->dbuf, A->dbuf_gc, 0, 0, A->Width, A->Height); } else XDrawPoints(display, window, gc, A->Buffer1, Cur_Pt, CoordModeOrigin); if (MI_NPIXELS(mi) < 2) XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); else XSetForeground(display, gc, MI_PIXEL(mi, A->Col % MI_NPIXELS(mi))); if (A->dbuf != None) { XSetForeground(display, A->dbuf_gc, 1); XDrawPoints(display, A->dbuf, A->dbuf_gc, A->Buffer2, A->Cur_Pt, CoordModeOrigin); XCopyPlane(display, A->dbuf, window, gc, 0, 0, A->Width, A->Height, 0, 0, 1); } else XDrawPoints(display, window, gc, A->Buffer2, A->Cur_Pt, CoordModeOrigin); Buf = A->Buffer1; A->Buffer1 = A->Buffer2; A->Buffer2 = Buf; if ((xmax - xmin < DBL_To_PRM(.2)) && (ymax - ymin < DBL_To_PRM(.2))) A->Count += 4 * A->Speed; else A->Count += A->Speed; if (A->Count >= 1000) { for (i = MAX_PRM - 1; i >= 0; --i) A->Prm1[i] = A->Prm2[i]; Random_Prm(A->Prm2); A->Count = 0; } A->Col++; }
void draw_voters(ModeInfo * mi) { int i, spineless_dude, neighbor_direction; int spineless_col, spineless_row; int new_opinion, old_opinion; cellstruct info; voterstruct *vp; if (voters == NULL) return; vp = &voters[MI_SCREEN(mi)]; if (vp->first == NULL) return; MI_IS_DRAWN(mi) = True; vp->painted = True; if (vp->busyLoop) { if (vp->busyLoop >= 5000) vp->busyLoop = 0; else vp->busyLoop++; return; } for (i = 0; i < BITMAPS; i++) if (vp->number_in_party[i] == vp->npositions) { /* The End of the WORLD */ init_voters(mi); /* Create a more interesting planet */ } spineless_dude = NRAND(vp->npositions); neighbor_direction = NRAND(vp->neighbors) * 360 / vp->neighbors; spineless_col = spineless_dude % vp->ncols; spineless_row = spineless_dude / vp->ncols; old_opinion = vp->arr[spineless_dude]; new_opinion = neighbors_opinion(vp, spineless_col, spineless_row, neighbor_direction); if (old_opinion != new_opinion) { vp->number_in_party[old_opinion]--; vp->number_in_party[new_opinion]++; vp->arr[spineless_dude] = new_opinion; info.kind = new_opinion; info.age = (old_opinion - new_opinion); if (info.age == 2) info.age = -1; if (info.age == -2) info.age = 1; info.age *= (FACTOR * MI_NPIXELS(mi)) / 3; info.col = spineless_col; info.row = spineless_row; if (MI_NPIXELS(mi) > 2) { advanceColors(mi, spineless_col, spineless_row); if (!addto_list(vp, info)) { free_voters(vp); return; } } drawcell(mi, spineless_col, spineless_row, (MI_NPIXELS(mi) + info.age / FACTOR + (MI_NPIXELS(mi) * new_opinion / BITMAPS)) % MI_NPIXELS(mi), new_opinion, True); } else if (MI_NPIXELS(mi) > 2) advanceColors(mi, -1, -1); vp->generation++; for (i = 0; i < BITMAPS; i++) if (vp->number_in_party[i] == vp->npositions) { /* The End of the WORLD */ vp->busyLoop = 1; refresh_voters(mi); } }
ENTRYPOINT void draw_braid(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int num_points = 500; float t_inc; float theta, psi; float t, r_diff; int i, s; float x_1, y_1, x_2, y_2, r1, r2; float color, color_use = 0.0, color_inc; braidtype *braid; if (braids == NULL) return; braid = &braids[MI_SCREEN(mi)]; #ifdef STANDALONE if (braid->eraser) { braid->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), braid->eraser); return; } #endif MI_IS_DRAWN(mi) = True; XSetLineAttributes(display, MI_GC(mi), braid->linewidth, LineSolid, (braid->linewidth <= 3 ? CapButt : CapRound), JoinMiter); theta = (2.0 * M_PI) / (float) (braid->braidlength); t_inc = (2.0 * M_PI) / (float) num_points; color_inc = (float) MI_NPIXELS(mi) * braid->color_direction / (float) num_points; braid->startcolor += SPINRATE * color_inc; if (((int) braid->startcolor) >= MI_NPIXELS(mi)) braid->startcolor = 0.0; r_diff = (braid->max_radius - braid->min_radius) / (float) (braid->nstrands); color = braid->startcolor; psi = 0.0; for (i = 0; i < braid->braidlength; i++) { psi += theta; for (t = 0.0; t < theta; t += t_inc) { #ifdef COLORROUND color += color_inc; if (((int) color) >= MI_NPIXELS(mi)) color = 0.0; color_use = color; #endif for (s = 0; s < braid->nstrands; s++) { if (ABS(braid->braidword[i]) == s) continue; if (ABS(braid->braidword[i]) - 1 == s) { /* crosSINFg */ #ifdef COLORCOMP if (MI_NPIXELS(mi) > 2) { color_use = color + SPINRATE * braid->components[applywordbackto(braid, s, i)] + (psi + t) / 2.0 / M_PI * (float) MI_NPIXELS(mi); while (((int) color_use) >= MI_NPIXELS(mi)) color_use -= (float) MI_NPIXELS(mi); while (((int) color_use) < 0) color_use += (float) MI_NPIXELS(mi); } #endif #ifdef COLORROUND if (MI_NPIXELS(mi) > 2) { color_use += SPINRATE * color_inc; while (((int) color_use) >= MI_NPIXELS(mi)) color_use -= (float) MI_NPIXELS(mi); } #endif r1 = braid->min_radius + r_diff * (float) (s); r2 = braid->min_radius + r_diff * (float) (s + 1); if (braid->braidword[i] > 0 || (FABSF(t - theta / 2.0) > theta / 7.0)) { x_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r2 + 0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r1)) * COSF(t + psi) + braid->center_x; y_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r2 + 0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r1)) * SINF(t + psi) + braid->center_y; x_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r2 + 0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r1)) * COSF(t + t_inc + psi) + braid->center_x; y_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r2 + 0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r1)) * SINF(t + t_inc + psi) + braid->center_y; if (MI_NPIXELS(mi) > 2) XSetForeground(display, MI_GC(mi), MI_PIXEL(mi, (int) color_use)); else XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi)); XDrawLine(display, window, MI_GC(mi), (int) (x_1), (int) (y_1), (int) (x_2), (int) (y_2)); } #ifdef COLORCOMP if (MI_NPIXELS(mi) > 2) { color_use = color + SPINRATE * braid->components[applywordbackto(braid, s + 1, i)] + (psi + t) / 2.0 / M_PI * (float) MI_NPIXELS(mi); while (((int) color_use) >= MI_NPIXELS(mi)) color_use -= (float) MI_NPIXELS(mi); while (((int) color_use) < 0) color_use += (float) MI_NPIXELS(mi); } #endif if (braid->braidword[i] < 0 || (FABSF(t - theta / 2.0) > theta / 7.0)) { x_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r1 + 0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r2)) * COSF(t + psi) + braid->center_x; y_1 = ((0.5 * (1.0 + SINF(t / theta * M_PI - M_PI_2)) * r1 + 0.5 * (1.0 + SINF((theta - t) / theta * M_PI - M_PI_2)) * r2)) * SINF(t + psi) + braid->center_y; x_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r1 + 0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r2)) * COSF(t + t_inc + psi) + braid->center_x; y_2 = ((0.5 * (1.0 + SINF((t + t_inc) / theta * M_PI - M_PI_2)) * r1 + 0.5 * (1.0 + SINF((theta - t - t_inc) / theta * M_PI - M_PI_2)) * r2)) * SINF(t + t_inc + psi) + braid->center_y; if (MI_NPIXELS(mi) > 2) XSetForeground(display, MI_GC(mi), MI_PIXEL(mi, (int) color_use)); else XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi)); XDrawLine(display, window, MI_GC(mi), (int) (x_1), (int) (y_1), (int) (x_2), (int) (y_2)); } } else { /* no crosSINFg */ #ifdef COLORCOMP if (MI_NPIXELS(mi) > 2) { color_use = color + SPINRATE * braid->components[applywordbackto(braid, s, i)] + (psi + t) / 2.0 / M_PI * (float) MI_NPIXELS(mi); while (((int) color_use) >= MI_NPIXELS(mi)) color_use -= (float) MI_NPIXELS(mi); while (((int) color_use) < 0) color_use += (float) MI_NPIXELS(mi); } #endif #ifdef COLORROUND if (MI_NPIXELS(mi) > 2) { color_use += SPINRATE * color_inc; while (((int) color_use) >= MI_NPIXELS(mi)) color_use -= (float) MI_NPIXELS(mi); } #endif r1 = braid->min_radius + r_diff * (float) (s); x_1 = r1 * COSF(t + psi) + braid->center_x; y_1 = r1 * SINF(t + psi) + braid->center_y; x_2 = r1 * COSF(t + t_inc + psi) + braid->center_x; y_2 = r1 * SINF(t + t_inc + psi) + braid->center_y; if (MI_NPIXELS(mi) > 2) XSetForeground(display, MI_GC(mi), MI_PIXEL(mi, (int) color_use)); else XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi)); XDrawLine(display, window, MI_GC(mi), (int) (x_1), (int) (y_1), (int) (x_2), (int) (y_2)); } } } } XSetLineAttributes(display, MI_GC(mi), 1, LineSolid, CapNotLast, JoinRound); if (++braid->age > MI_CYCLES(mi)) { #ifdef STANDALONE braid->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), braid->eraser); #endif init_braid(mi); } }
void draw_galaxy(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Drawable drawable; GC gc = MI_GC(mi); double d; /* tmp */ int i, j, k; /* more tmp */ unistruct *gp; Bool clipped; if (universes == NULL) return; gp = &universes[MI_SCREEN(mi)]; if (gp->galaxies == NULL) return; if (gp->fisheye) drawable = (Drawable) gp->pixmap; else drawable = MI_WINDOW(mi); MI_IS_DRAWN(mi) = True; for (i = 0; i < gp->ngalaxies; ++i) { Galaxy *gt = &gp->galaxies[i]; for (j = 0; j < gp->galaxies[i].nstars; ++j) { Star *st = >->stars[j]; double v0 = st->vel[0]; double v1 = st->vel[1]; double v2 = st->vel[2]; for (k = 0; k < gp->ngalaxies; ++k) { Galaxy *gtk = &gp->galaxies[k]; double d0 = gtk->pos[0] - st->pos[0]; double d1 = gtk->pos[1] - st->pos[1]; double d2 = gtk->pos[2] - st->pos[2]; d = d0 * d0 + d1 * d1 + d2 * d2; if (d > EPSILON) d = gt->mass / (d * sqrt(d)) * DELTAT * DELTAT * QCONS; else d = gt->mass / (EPSILON * sqrt_EPSILON) * DELTAT * DELTAT * QCONS; v0 += d0 * d; v1 += d1 * d; v2 += d2 * d; } st->vel[0] = v0; st->vel[1] = v1; st->vel[2] = v2; #ifndef NO_VELOCITY_COLORING d = (v0 * v0 + v1 * v1 + v2 * v2) / (3.0 * DELTAT * DELTAT); if (d > (double) COLORBASE) st->color = gt->galcol + COLORBASE - 1; else st->color = gt->galcol + ((int) d) % COLORBASE; #endif st->pos[0] += v0; st->pos[1] += v1; st->pos[2] += v2; clipped = True; if (gp->fisheye) { /* clip if star Z position < 0.0 - also avoid divide by zero errors */ if(st->pos[2]>0.0) { st->px = (int) ((st->pos[0] * gp->scale) / st->pos[2]) + gp->midx; st->py = (int) ((st->pos[1] * gp->scale) / st->pos[2]) + gp->midy; st->size = (int) (gp->star_scale_Z / st->pos[2]) + st->Z_size; if(st->size>12)st->size=12; clipped = False; } } else { if (st->px >= gp->clip.left && st->px <= gp->clip.right - st->size && st->py >= gp->clip.top && st->py <= gp->clip.bottom - st->size) { XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); drawStar(st->px, st->py, st->size); } st->px = (int) (st->pos[0] * gp->scale) + gp->midx; st->py = (int) (st->pos[1] * gp->scale) + gp->midy; #ifdef WRAP /* won't WRAP if FISHEYE_LENS */ if (st->px < gp->clip.left) { (void) printf("wrap l -> r\n"); st->px = gp->clip.right; } if (st->px > gp->clip.right) { (void) printf("wrap r -> l\n"); st->px = gp->clip.left; } if (st->py > gp->clip.bottom) { (void) printf("wrap b -> t\n"); st->py = gp->clip.top; } if (st->py < gp->clip.top) { (void) printf("wrap t -> b\n"); st->py = gp->clip.bottom; } #endif /*WRAP */ if (st->px >= gp->clip.left && st->px <= gp->clip.right - st->size && st->py >= gp->clip.top && st->py <= gp->clip.bottom - st->size) { clipped = False; } } if (!clipped) { if (MI_NPIXELS(mi) >= COLORS) { #ifdef NO_VELOCITY_COLORING XSetForeground(display, gc, MI_PIXEL(mi, gt->galcol)); #else XSetForeground(display, gc, MI_PIXEL(mi, st->color)); #endif } else XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); if (gp->tracks) { drawStar(st->px + 1, st->py, st->size); } else { drawStar(st->px, st->py, st->size); } } } for (k = i + 1; k < gp->ngalaxies; ++k) { Galaxy *gtk = &gp->galaxies[k]; double d0 = gtk->pos[0] - gt->pos[0]; double d1 = gtk->pos[1] - gt->pos[1]; double d2 = gtk->pos[2] - gt->pos[2]; d = d0 * d0 + d1 * d1 + d2 * d2; if (d > EPSILON) d = gt->mass * gt->mass / (d * sqrt(d)) * DELTAT * QCONS; else d = gt->mass * gt->mass / (EPSILON * sqrt_EPSILON) * DELTAT * QCONS; d0 *= d; d1 *= d; d2 *= d; gt->vel[0] += d0 / gt->mass; gt->vel[1] += d1 / gt->mass; gt->vel[2] += d2 / gt->mass; gtk->vel[0] -= d0 / gtk->mass; gtk->vel[1] -= d1 / gtk->mass; gtk->vel[2] -= d2 / gtk->mass; } gt->pos[0] += gt->vel[0] * DELTAT; gt->pos[1] += gt->vel[1] * DELTAT; gt->pos[2] += gt->vel[2] * DELTAT; } if (gp->fisheye) { XCopyArea(display, drawable, MI_WINDOW(mi), gc, 0, 0, MI_WIDTH(mi), MI_HEIGHT(mi),0 , 0); XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillRectangle(display, drawable, gc, 0, 0, MI_WIDTH(mi), MI_HEIGHT(mi)); } gp->step++; if (gp->step > gp->f_hititerations * 4) (void) startover(mi); }