ENTRYPOINT void init_thornbird (ModeInfo * mi) { thornbirdstruct *hp; if (thornbirds == NULL) { if ((thornbirds = (thornbirdstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (thornbirdstruct))) == NULL) return; } hp = þbirds[MI_SCREEN(mi)]; hp->maxx = MI_WIDTH(mi); hp->maxy = MI_HEIGHT(mi); hp->b = 0.1; hp->i = hp->j = 0.1; hp->pix = 0; hp->inc = 0; hp->nbuffers = MI_CYCLES(mi); if (hp->pointBuffer == NULL) if ((hp->pointBuffer = (XPoint **) calloc(MI_CYCLES(mi), sizeof (XPoint *))) == NULL) { free_thornbird(hp); return; } if (hp->pointBuffer[0] == NULL) if ((hp->pointBuffer[0] = (XPoint *) malloc(MI_COUNT(mi) * sizeof (XPoint))) == NULL) { free_thornbird(hp); return; } /* select frequencies for parameter variation */ hp->liss.f1 = LRAND() % 5000; hp->liss.f2 = LRAND() % 2000; /* choose random 3D tumbling */ hp->tumble.theta = 0; hp->tumble.phi = 0; hp->tumble.dtheta = balance_rand(0.001); hp->tumble.dphi = balance_rand(0.005); /* Clear the background. */ MI_CLEARWINDOW(mi); hp->count = 0; }
ENTRYPOINT void draw_mountain (ModeInfo * mi) { mountainstruct *mp; if (mountains == NULL) return; mp = &mountains[MI_SCREEN(mi)]; if (mp->stippledGC == NULL) return; MI_IS_DRAWN(mi) = True; switch (mp->stage) { case 0: drawamountain(mi); break; case 1: if (++mp->time > MI_CYCLES(mi)) mp->stage++; break; case 2: init_mountain(mi); break; } }
void draw_turtle(ModeInfo * mi) { turtlestruct *tp; if (turtles == NULL) return; tp = &turtles[MI_SCREEN(mi)]; if (++tp->time > MI_CYCLES(mi)) init_turtle(mi); MI_IS_DRAWN(mi) = True; if (MI_NPIXELS(mi) > 2) XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)))); tp->r = tp->r >> 1; tp->level++; if (tp->r > 1) switch (tp->curve) { case HILBERT: switch (tp->dir) { case 0: tp->pt1.x = tp->pt2.x = tp->start.x + tp->r / 2; tp->pt1.y = tp->pt2.y = tp->start.y + tp->r / 2; generate_hilbert(mi, 0, tp->r); break; case 1: tp->pt1.x = tp->pt2.x = tp->start.x + tp->min - tp->r / 2; tp->pt1.y = tp->pt2.y = tp->start.y + tp->min - tp->r / 2; generate_hilbert(mi, 0, -tp->r); break; case 2: tp->pt1.x = tp->pt2.x = tp->start.x + tp->min - tp->r / 2; tp->pt1.y = tp->pt2.y = tp->start.y + tp->min - tp->r / 2; generate_hilbert(mi, -tp->r, 0); break; case 3: tp->pt1.x = tp->pt2.x = tp->start.x + tp->r / 2; tp->pt1.y = tp->pt2.y = tp->start.y + tp->r / 2; generate_hilbert(mi, tp->r, 0); } break; case CESARO_VAR: generate_cesarovar(mi, (double) tp->pt1.x, (double) tp->pt1.y, (double) tp->pt2.x, (double) tp->pt2.y, tp->level, tp->sign); break; case HARTER_HEIGHTWAY: generate_harter_heightway(mi, (double) tp->pt1.x, (double) tp->pt1.y, (double) tp->pt2.x, (double) tp->pt2.y, tp->level, tp->sign); break; } }
void draw_wire(ModeInfo * mi) { int offset, i, j, found = 0; unsigned char *z, *znew; circuitstruct *wp; if (circuits == NULL) return; wp = &circuits[MI_SCREEN(mi)]; if (wp->newcells == NULL) return; MI_IS_DRAWN(mi) = True; /* wires do not grow so min max stuff does not change */ for (j = wp->minrow; j <= wp->maxrow; j++) { for (i = wp->mincol; i <= wp->maxcol; i++) { offset = j * wp->bncols + i; z = wp->oldcells + offset; znew = wp->newcells + offset; if (*z != *znew) { /* Counting on once a space always a space */ found = 1; *z = *znew; if (!addtolist(mi, i - 2, j - 2, *znew - 1)) { free_wire(MI_DISPLAY(mi), wp); return; } } } } for (i = 0; i < COLORS - 1; i++) if (!draw_state(mi, i)) { free_wire(MI_DISPLAY(mi), wp); return; } if (++wp->generation > MI_CYCLES(mi) || !found) { init_wire(mi); return; } else do_gen(wp); if (wp->redrawing) { for (i = 0; i < REDRAWSTEP; i++) { if ((*(wp->oldcells + wp->redrawpos))) { drawCell(mi, wp->redrawpos % wp->bncols - 2, wp->redrawpos / wp->bncols - 2, *(wp->oldcells + wp->redrawpos) - 1); } if (++(wp->redrawpos) >= wp->bncols * (wp->bnrows - 2)) { wp->redrawing = 0; break; } } } }
ENTRYPOINT void init_atlantis(ModeInfo * mi) { int screen = MI_SCREEN(mi); atlantisstruct *ap; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); if (atlantis == NULL) { if ((atlantis = (atlantisstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (atlantisstruct))) == NULL) return; } ap = &atlantis[screen]; ap->num_sharks = MI_COUNT(mi); if (ap->sharks == NULL) { if ((ap->sharks = (fishRec *) calloc(ap->num_sharks, sizeof (fishRec))) == NULL) { /* free everything up to now */ (void) free((void *) atlantis); atlantis = NULL; return; } } ap->sharkspeed = MI_CYCLES(mi); /* has influence on the "width" of the movement */ ap->sharksize = MI_SIZE(mi); /* has influence on the "distance" of the sharks */ ap->whalespeed = whalespeed; ap->wire = MI_IS_WIREFRAME(mi); if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tnum_sharks=%d\n\tsharkspeed=%.1f\n\tsharksize=%d\n\twhalespeed=%.1f\n\twireframe=%s\n", MI_NAME(mi), ap->num_sharks, ap->sharkspeed, ap->sharksize, ap->whalespeed, ap->wire ? "yes" : "no" ); } if ((ap->glx_context = init_GL(mi)) != NULL) { reshape_atlantis(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glDrawBuffer(GL_BACK); Init(mi); AllDisplay(ap); glXSwapBuffers(display, window); } else { MI_CLEARWINDOW(mi); } }
void draw_blot(ModeInfo * mi) { blotstruct *bp; XPoint *xp; int x, y, k; if (blots == NULL) return; bp = &blots[MI_SCREEN(mi)]; xp = bp->pointBuffer; if (xp == NULL) init_blot(mi); MI_IS_DRAWN(mi) = True; if (MI_NPIXELS(mi) > 2) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, bp->pix)); if (++bp->pix >= MI_NPIXELS(mi)) bp->pix = 0; } x = bp->xmid; y = bp->ymid; k = bp->size; while (k >= 4) { x += (NRAND(1 + (bp->offset << 1)) - bp->offset); y += (NRAND(1 + (bp->offset << 1)) - bp->offset); k--; xp->x = x; xp->y = y; xp++; if (bp->xsym) { k--; xp->x = bp->width - x; xp->y = y; xp++; } if (bp->ysym) { k--; xp->x = x; xp->y = bp->height - y; xp++; } if (bp->xsym && bp->ysym) { k--; xp->x = bp->width - x; xp->y = bp->height - y; xp++; } } XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), bp->pointBuffer, (bp->size - k), CoordModeOrigin); if (++bp->count > MI_CYCLES(mi)) init_blot(mi); }
void init_galaxy(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); unistruct *gp; if (universes == NULL) { if ((universes = (unistruct *) calloc(MI_NUM_SCREENS(mi), sizeof (unistruct))) == NULL) return; } gp = &universes[MI_SCREEN(mi)]; gp->f_hititerations = MI_CYCLES(mi); gp->clip.left = 0; gp->clip.top = 0; gp->clip.right = MI_WIDTH(mi); gp->clip.bottom = MI_HEIGHT(mi); gp->scale = (double) (gp->clip.right + gp->clip.bottom) / 8.0; gp->midx = gp->clip.right / 2; gp->midy = gp->clip.bottom / 2; if (MI_IS_FULLRANDOM(mi)) { gp->fisheye = !(NRAND(3)); if (!gp->fisheye) gp->tracks = (Bool) (LRAND() & 1); } else { gp->fisheye = fisheye; gp->tracks = tracks; } if (!startover(mi)) return; if (gp->fisheye) { if (gp->pixmap != None) XFreePixmap(display, gp->pixmap); if ((gp->pixmap = XCreatePixmap(display, MI_WINDOW(mi), MI_WIDTH(mi), MI_HEIGHT(mi), MI_DEPTH(mi))) == None) { gp->fisheye = False; } } if (gp->fisheye) { XSetGraphicsExposures(display, MI_GC(mi), False); gp->scale *= Z_OFFSET; gp->star_scale_Z = (gp->scale * .005); /* don't want any exposure events from XCopyPlane */ } }
ENTRYPOINT void init_fadeplot (ModeInfo * mi) { fadeplotstruct *fp; if (fadeplots == NULL) { if ((fadeplots = (fadeplotstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (fadeplotstruct))) == NULL) return; } fp = &fadeplots[MI_SCREEN(mi)]; fp->width = MI_WIDTH(mi); fp->height = MI_HEIGHT(mi); fp->min = MAX(MIN(fp->width, fp->height) / 2, 1); fp->speed.x = 8; fp->speed.y = 10; fp->step.x = 1; fp->step.y = 1; fp->temps = 0; fp->factor.x = MAX(fp->width / (2 * fp->min), 1); fp->factor.y = MAX(fp->height / (2 * fp->min), 1); fp->nbstep = MI_COUNT(mi); if (fp->nbstep < -MINSTEPS) { fp->nbstep = NRAND(-fp->nbstep - MINSTEPS + 1) + MINSTEPS; } else if (fp->nbstep < MINSTEPS) fp->nbstep = MINSTEPS; fp->maxpts = MI_CYCLES(mi); if (fp->maxpts < 1) fp->maxpts = 1; if (fp->pts == NULL) { if ((fp->pts = (XPoint *) calloc(fp->maxpts, sizeof (XPoint))) == NULL) { free_fadeplot(fp); return; } } if (MI_NPIXELS(mi) > 2) fp->pix = NRAND(MI_NPIXELS(mi)); if (fp->stab != NULL) (void) free((void *) fp->stab); if (!initSintab(mi)) return; MI_CLEARWINDOW(mi); }
void draw_petal(ModeInfo * mi) { petalstruct *pp; if (petals == NULL) return; pp = &petals[MI_SCREEN(mi)]; MI_IS_DRAWN(mi) = True; if (++pp->time > MI_CYCLES(mi)) init_petal(mi); else pp->painted = True; }
ENTRYPOINT void init_superquadrics(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int screen = MI_SCREEN(mi); superquadricsstruct *sp; if (superquadrics == NULL) { if ((superquadrics = (superquadricsstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (superquadricsstruct))) == NULL) return; } sp = &superquadrics[screen]; sp->mono = (MI_IS_MONO(mi) ? 1 : 0); sp->pats[1][1] = 1; sp->pats[1][3] = 1; sp->pats[2][2] = 1; sp->pats[2][3] = 1; sp->pats[3][1] = 1; sp->pats[3][2] = 1; /* {0, 0, 0, 0}, {0, 1, 0, 1}, {0, 0, 1, 1}, {0, 1, 1, 0} */ if ((sp->glx_context = init_GL(mi)) != NULL) { InitSuperquadrics(MI_IS_WIREFRAME(mi), 0, MI_COUNT(mi), MI_CYCLES(mi), spinspeed, sp); ReshapeSuperquadrics(MI_WIDTH(mi), MI_HEIGHT(mi)); DisplaySuperquadrics(sp); glFinish(); glXSwapBuffers(display, window); } else { MI_CLEARWINDOW(mi); } }
void draw_laser(ModeInfo * mi) { int i; lasersstruct *lp; if (lasers == NULL) return; lp = &lasers[MI_SCREEN(mi)]; if (lp->laser == NULL) return; MI_IS_DRAWN(mi) = True; for (i = 0; i < lp->lr; i++) draw_laser_once(mi); if (++lp->time > MI_CYCLES(mi)) init_laser(mi); }
ENTRYPOINT void draw_sierpinski(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); GC gc = MI_GC(mi); XPoint *xp[MAXCORNERS]; int i, v; sierpinskistruct *sp; if (tris == NULL) return; sp = &tris[MI_SCREEN(mi)]; if (sp->pointBuffer[0] == NULL) return; MI_IS_DRAWN(mi) = True; if (MI_NPIXELS(mi) <= 2) XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); for (i = 0; i < sp->corners; i++) xp[i] = sp->pointBuffer[i]; for (i = 0; i < sp->total_npoints; i++) { v = NRAND(sp->corners); sp->px = (sp->px + sp->vertex[v].x) / 2; sp->py = (sp->py + sp->vertex[v].y) / 2; xp[v]->x = sp->px; xp[v]->y = sp->py; xp[v]++; sp->npoints[v]++; } for (i = 0; i < sp->corners; i++) { if (MI_NPIXELS(mi) > 2) XSetForeground(display, gc, MI_PIXEL(mi, sp->colors[i])); XDrawPoints(display, MI_WINDOW(mi), gc, sp->pointBuffer[i], sp->npoints[i], CoordModeOrigin); sp->npoints[i] = 0; } if (++sp->time >= MI_CYCLES(mi)) startover(mi); }
ENTRYPOINT void draw_lissie (ModeInfo * mi) { register unsigned char ball; lissstruct *lp; if (lisses == NULL) return; lp = &lisses[MI_SCREEN(mi)]; if (lp->lissie == NULL) return; MI_IS_DRAWN(mi) = True; if (++lp->loopcount > MI_CYCLES(mi)) { init_lissie(mi); } else { lp->painted = True; for (ball = 0; ball < (unsigned char) lp->nlissies; ball++) drawlissie(mi, &lp->lissie[ball]); } }
ENTRYPOINT void init_galaxy(ModeInfo * mi) { unistruct *gp; if (universes == NULL) { if ((universes = (unistruct *) calloc(MI_NUM_SCREENS(mi), sizeof (unistruct))) == NULL) return; } gp = &universes[MI_SCREEN(mi)]; # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ dbufp = False; # endif gp->f_hititerations = MI_CYCLES(mi); gp->scale = (double) (MI_WIN_WIDTH(mi) + MI_WIN_HEIGHT(mi)) / 8.0; gp->midx = MI_WIN_WIDTH(mi) / 2; gp->midy = MI_WIN_HEIGHT(mi) / 2; startover(mi); }
ENTRYPOINT void change_sballs(ModeInfo * mi) { sballsstruct *sb; if (sballs == NULL) return; sb = &sballs[MI_SCREEN(mi)]; if (!sb->glx_context) return; /* initialise object number */ if ((object == 0) || (object > MAX_OBJ)) object = NRAND(MAX_OBJ-1)+1; object--; /* correct sphere number */ spheres = MI_COUNT(mi); if (MI_COUNT(mi) > polygons[object].numverts) spheres = polygons[object].numverts; if (MI_COUNT(mi) < 1) spheres = polygons[object].numverts; if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tobject=%s\n\tspheres=%d\n\tspeed=%d\n\ttexture=%s\n", MI_NAME(mi), polygons[object].shortname, spheres, (int) MI_CYCLES(mi), do_texture ? "on" : "off" ); } glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(sb->glx_context)); }
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++; }
ENTRYPOINT void init_rotor (ModeInfo * mi) { int x; elem *pelem; unsigned char wasiconified; rotorstruct *rp; if (rotors == NULL) { if ((rotors = (rotorstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (rotorstruct))) == NULL) return; } rp = &rotors[MI_SCREEN(mi)]; #ifdef HAVE_COCOA jwxyz_XSetAntiAliasing (MI_DISPLAY(mi), MI_GC(mi), False); #endif rp->prevcenterx = rp->centerx; rp->prevcentery = rp->centery; rp->centerx = MI_WIDTH(mi) / 2; rp->centery = MI_HEIGHT(mi) / 2; rp->redrawing = 0; /* * sometimes, you go into iconified view, only to see a really whizzy pattern * that you would like to look more closely at. Normally, clicking in the * icon reinitializes everything - but I don't, cuz I'm that kind of guy. * HENCE, the wasiconified stuff you see here. */ wasiconified = rp->iconifiedscreen; rp->iconifiedscreen = MI_IS_ICONIC(mi); if (wasiconified && !rp->iconifiedscreen) rp->firsttime = True; else { /* This is a fudge is needed since prevcenter may not be set when it comes from the the random mode and return is pressed (and its not the first mode that was running). This assumes that the size of the lock screen window / size of the icon window = 12 */ if (!rp->prevcenterx) rp->prevcenterx = rp->centerx * 12; if (!rp->prevcentery) rp->prevcentery = rp->centery * 12; rp->num = MI_COUNT(mi); if (rp->num < 0) { rp->num = NRAND(-rp->num) + 1; if (rp->elements != NULL) { (void) free((void *) rp->elements); rp->elements = (elem *) NULL; } } if (rp->elements == NULL) if ((rp->elements = (elem *) calloc(rp->num, sizeof (elem))) == NULL) { free_rotor(rp); return; } rp->nsave = MI_CYCLES(mi); if (rp->nsave <= 1) rp->nsave = 2; if (rp->save == NULL) if ((rp->save = (XPoint *) malloc(rp->nsave * sizeof (XPoint))) == NULL) { free_rotor(rp); return; } for (x = 0; x < rp->nsave; x++) { rp->save[x].x = rp->centerx; rp->save[x].y = rp->centery; } pelem = rp->elements; for (x = rp->num; --x >= 0; pelem++) { pelem->radius_drift_max = 1.0; pelem->radius_drift_now = 1.0; pelem->end_radius = 100.0; pelem->ratio_drift_max = 1.0; pelem->ratio_drift_now = 1.0; pelem->end_ratio = 10.0; } if (MI_NPIXELS(mi) > 2) rp->pix = NRAND(MI_NPIXELS(mi)); rp->rotor = 0; rp->prev = 1; rp->lastx = rp->centerx; rp->lasty = rp->centery; rp->angle = (float) NRAND((long) MAXANGLE) / 3.0; rp->forward = rp->firsttime = True; } rp->linewidth = MI_SIZE(mi); if (rp->linewidth == 0) rp->linewidth = 1; if (rp->linewidth < 0) rp->linewidth = NRAND(-rp->linewidth) + 1; MI_CLEARWINDOW(mi); }
static void create_eyes(ModeInfo * mi, Eyes * e, Eyes * eyes, int num_eyes) { EyeScrInfo *ep = &eye_info[MI_SCREEN(mi)]; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int win_width = MI_WIDTH(mi); int win_height = MI_HEIGHT(mi); unsigned long black_pixel = MI_BLACK_PIXEL(mi); unsigned long white_pixel = MI_WHITE_PIXEL(mi); Bool iconic = MI_IS_ICONIC(mi); Pixmap pix = e->pixmap; /* preserve pixmap handle */ int w = e->width; /* remember last w/h */ int h = e->height; int npixels = MI_NPIXELS(mi); /* num colors in colormap */ int cycs = MI_CYCLES(mi); /* affects eye lifetime */ int maxw = win_width / 2; /* widest eyes can be */ int color, lid_color; int i; (void) memset((char *) e, 0, sizeof (Eyes)); /* wipe everything */ e->pixmap = pix; /* remember Pixmap handle */ /* sanity check the cycles value */ if (cycs < 1) cycs = 1; if (cycs > MAX_CYCLES) cycs = MAX_CYCLES; e->time_to_die = (unsigned long) LIFE_MIN + NRAND(LIFE_RANGE); e->time_to_die *= (unsigned long) cycs; /* multiply life by cycles */ e->time_to_die += ep->time; e->pupil_pixel = black_pixel; /* pupil is always black */ if (MI_NPIXELS(mi) <= 2) { /* TODO: stipple the eyelid? */ e->eyelid_pixel = black_pixel; e->eyeball_pixel = white_pixel; } else { lid_color = NRAND(npixels); e->eyelid_pixel = MI_PIXEL(mi, lid_color); while ((color = NRAND(npixels + 5)) == lid_color) { /* empty */ } if (color >= npixels) { /* give white a little better chance */ e->eyeball_pixel = white_pixel; } else { e->eyeball_pixel = MI_PIXEL(mi, color); } } if (iconic) { /* only one pair of eyes, fills entire window */ e->width = win_width; e->height = win_height; } else { if (maxw - MIN_EYE_SIZE > MIN_EYE_SIZE) e->width = NRAND(maxw - MIN_EYE_SIZE) + MIN_EYE_SIZE; else e->width = NRAND(MIN_EYE_SIZE) + MIN_EYE_SIZE; e->x = (win_width - e->width > 0) ? NRAND(win_width - e->width) : 0; e->height = NRAND(e->width * 3 / 4) + (e->width / 4); e->y = (win_height - e->height > 0) ? NRAND(win_height - e->height) : 0; /* check for overlap with other eyes */ for (i = 0; i < num_eyes; i++) { if (&eyes[i] == e) { /* that's me */ continue; } if (eyes_overlap(e, &eyes[i])) { /* collision, force retry on next cycle */ e->time_to_die = 0; break; } } } /* If the Pixmap is smaller than the new size, make it bigger */ if ((e->width > w) || (e->height > h)) { if (e->pixmap != None) { XFreePixmap(display, e->pixmap); } if ((e->pixmap = XCreatePixmap(display, window, e->width, e->height, MI_DEPTH(mi))) == None) { e->width = e->height = 0; return; } } /* Set the transformation matrix for this set of eyes * If iconic, make the eyes image one pixel shorter and * skinnier, they seem to fit in the icon box better that way. */ SetTransform(&e->transform, 0, (iconic) ? e->width - 1 : e->width, (iconic) ? e->height - 1 : e->height, 0, W_MIN_X, W_MAX_X, W_MIN_Y, W_MAX_Y); /* clear the offscreen pixmap to background color */ XSetForeground(display, ep->eyeGC, black_pixel); XFillRectangle(display, (Drawable) e->pixmap, ep->eyeGC, 0, 0, e->width, e->height); /* make the full eye images in the offscreen Pixmap */ make_eye(mi, e->pixmap, e, 0, True); make_eye(mi, e->pixmap, e, 1, True); }
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_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); } }
static void Init(ModeInfo * mi) { sballsstruct *sb = &sballs[MI_SCREEN(mi)]; int i; /* Default settings */ if (MI_IS_WIREFRAME(mi)) do_texture = False; if (do_texture) inittextures(mi); else { sb->btexture = (XImage*) NULL; sb->ftexture = (XImage*) NULL; } vinit(sb->eye ,0.0f, 0.0f, 6.0f); vinit(sb->rotm ,0.0f, 0.0f, 0.0f); sb->speed = MI_CYCLES(mi); /* initialise object number */ if ((object == 0) || (object > MAX_OBJ)) object = NRAND(MAX_OBJ-1)+1; object--; /* initialise sphere number */ spheres = MI_COUNT(mi); if (MI_COUNT(mi) > polygons[object].numverts) spheres = polygons[object].numverts; if (MI_COUNT(mi) < 1) spheres = polygons[object].numverts; /* initialise sphere radius */ for(i=0; i < spheres;i++) { #if RANDOM_RADIUS sb->radius[i] = ((float) LRAND() / (float) MAXRAND); if (sb->radius[i] < 0.3) sb->radius[i] = 0.3; if (sb->radius[i] > 0.7) sb->radius[i] = 0.7; #else sb->radius[i] = polygons[object].radius; #endif } if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tobject=%s\n\tspheres=%d\n\tspeed=%d\n\ttexture=%s\n", MI_NAME(mi), polygons[object].shortname, spheres, (int) MI_CYCLES(mi), do_texture ? "on" : "off" ); } glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); glEnable(GL_LIGHT1); }
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; } }
void init_life1d(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int size = MI_SIZE(mi); int i; life1dstruct *lp; if (life1ds == NULL) { if ((life1ds = (life1dstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (life1dstruct))) == NULL) return; } lp = &life1ds[MI_SCREEN(mi)]; if (!init_stuff(mi)) { free_life1d(display, lp); return; } lp->screen_generation = 0; lp->row = 0; if (totalistic) { maxstates = MAXSTATES; maxradius = 4; maxsum_size = (maxstates - 1) * (maxradius * 2 + 1) + 1; } else { maxstates = MAXSTATES - 1; maxradius = 1; maxsum_size = (int) power(maxstates, (2 * maxradius + 1)); } if (lp->nextstate == NULL) { if ((lp->nextstate = (char *) malloc(maxsum_size * sizeof (char))) == NULL) { free_life1d(display, lp); return; } } if (lp->init_bits == 0) { XGCValues gcv; gcv.fill_style = FillOpaqueStippled; if ((lp->stippledGC = XCreateGC(display, window, GCFillStyle, &gcv)) == None) { free_life1d(display, lp); return; } for (i = 0; i < MAXSTATES - 1; i++) { LIFE1DBITS(stipples[i + NUMSTIPPLES - MAXSTATES + 1], STIPPLESIZE, STIPPLESIZE); } LIFE1DBITS(stipples[NUMSTIPPLES / 2], STIPPLESIZE, STIPPLESIZE); /* grey */ } if (lp->newcells != NULL) free(lp->newcells); if (lp->oldcells != NULL) free(lp->oldcells); if (lp->buffer != NULL) free(lp->buffer); if (lp->previousBuffer != NULL) free(lp->previousBuffer); lp->previousBuffer = (unsigned char *) NULL; lp->width = MI_WIDTH(mi); lp->height = MI_HEIGHT(mi); if (lp->width < 2) lp->width = 2; if (lp->height < 2) lp->height = 2; if (size == 0 || MINGRIDSIZE * size > lp->width || MINGRIDSIZE * size > lp->height) { if (lp->width > MINGRIDSIZE * lp->logo->width && lp->height > MINGRIDSIZE * lp->logo->height) { lp->pixelmode = False; lp->xs = lp->logo->width; lp->ys = lp->logo->height; } else { int min = MIN(lp->width, lp->height) / (12 * MINGRIDSIZE); int max = MIN(lp->width, lp->height) / (4 * MINGRIDSIZE); lp->xs = lp->ys = MAX(MINSIZE, min + NRAND(max - min + 1)); lp->pixelmode = True; } } else { lp->pixelmode = True; if (size < -MINSIZE) { lp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(lp->width, lp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; } else if (size < MINSIZE) { lp->ys = MINSIZE; } else { lp->ys = MIN(size, MAX(MINSIZE, MIN(lp->width, lp->height) / MINGRIDSIZE)); } lp->xs = lp->ys; } lp->ncols = MAX(lp->width / lp->xs, 2); lp->nrows = MAX(lp->height / lp->ys, 2); lp->border = (lp->nrows / 2 + 1) * MI_CYCLES(mi); if ((lp->newcells = (unsigned char *) calloc(lp->ncols + 2 * lp->border, sizeof (unsigned char))) == NULL) { free_life1d(display, lp); return; } if ((lp->oldcells = (unsigned char *) calloc(lp->ncols + 2 * (maxradius + lp->border), sizeof (unsigned char))) == NULL) { free_life1d(display, lp); return; } if ((lp->buffer = (unsigned char *) calloc(lp->ncols * lp->nrows, sizeof (unsigned char))) == NULL) { free_life1d(display, lp); return; } lp->xb = (lp->width - lp->xs * lp->ncols) / 2; lp->yb = (lp->height - lp->ys * lp->nrows) / 2; GetRule(lp, (int) NRAND((totalistic) ? TOTALISTICRULES : LCAURULES)); if (MI_IS_VERBOSE(mi)) { (void) fprintf(stdout, "colors %d, radius %d, code %ld, ", lp->k, lp->r, lp->code); if (totalistic) { (void) fprintf(stdout, "totalistic rule "); for (i = (lp->k - 1) * (lp->r * 2 + 1); i >= 0; i--) (void) fprintf(stdout, "%d", (int) lp->nextstate[i]); } else { (void) fprintf(stdout, "LCAU rule "); for (i = (int) power(lp->k, (lp->r * 2 + 1)); i >= 0; i--) (void) fprintf(stdout, "%d", (int) lp->nextstate[i]); } (void) fprintf(stdout, "\n"); } if (MI_NPIXELS(mi) > 2) { int offset = NRAND(MI_NPIXELS(mi)); for (i = 0; i < lp->k - 1; i++) { lp->colors[i] = ((offset + (i * MI_NPIXELS(mi) / (lp->k - 1))) % MI_NPIXELS(mi)); } } RandomSoup(lp, 40, 25); (void) memcpy((char *) (lp->oldcells + maxradius + lp->border), (char *) (lp->newcells + lp->border), lp->ncols); lp->busyLoop = 0; MI_CLEARWINDOWCOLORMAP(mi, lp->backGC, lp->black); }
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 init_spiral(ModeInfo * mi) { spiralstruct *sp; int i; if (spirals == NULL) { if ((spirals = (spiralstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (spiralstruct))) == NULL) return; } sp = &spirals[MI_SCREEN(mi)]; #ifdef HAVE_COCOA jwxyz_XSetAntiAliasing (MI_DISPLAY(mi), MI_GC(mi), False); #endif sp->width = MI_WIDTH(mi); sp->height = MI_HEIGHT(mi); MI_CLEARWINDOW(mi); /* Init */ sp->nlength = MI_CYCLES(mi); if (!sp->traildots) if ((sp->traildots = (Traildots *) malloc(sp->nlength * sizeof (Traildots))) == NULL) { return; } /* initialize the allocated array */ for (i = 0; i < sp->nlength; i++) { sp->traildots[i].hx = 0.0; sp->traildots[i].hy = 0.0; sp->traildots[i].ha = 0.0; sp->traildots[i].hr = 0.0; } sp->redrawing = 0; /* keep the window parameters proportional */ sp->top = 10000.0; sp->bottom = 0; sp->right = (float) (sp->width) / (float) (sp->height) * (10000.0); sp->left = 0; /* assign the initial values */ sp->cx = (float) (5000.0 - NRAND(2000)) / 10000.0 * sp->right; sp->cy = (float) (5000.0 - NRAND(2000)); sp->radius = (float) (NRAND(200) + 200); sp->angle = 0.0; sp->dx = (float) (10 - NRAND(20)) * SPEED; sp->dy = (float) (10 - NRAND(20)) * SPEED; sp->dr = (float) ((NRAND(10) + 4) * (1 - (LRAND() & 1) * 2)); sp->da = (float) NRAND(360) / 7200.0 + 0.01; if (MI_NPIXELS(mi) > 2) sp->colors = (float) NRAND(MI_NPIXELS(mi)); sp->erase = 0; sp->inc = 0; sp->traildots[sp->inc].hx = sp->cx; sp->traildots[sp->inc].hy = sp->cy; sp->traildots[sp->inc].ha = sp->angle; sp->traildots[sp->inc].hr = sp->radius; sp->inc++; sp->dots = MI_COUNT(mi); if (sp->dots < -MINDOTS) sp->dots = NRAND(sp->dots - MINDOTS + 1) + MINDOTS; /* Absolute minimum */ if (sp->dots < MINDOTS) sp->dots = MINDOTS; }
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 }
void init_molecule (ModeInfo *mi) { molecule_configuration *mc; int wire; #ifndef STANDALONE timeout = MI_CYCLES(mi); #endif if (!mcs) { mcs = (molecule_configuration *) calloc (MI_NUM_SCREENS(mi), sizeof (molecule_configuration)); if (!mcs) { return; } } mc = &mcs[MI_SCREEN(mi)]; if (mc->glx_context) { /* Free font stuff */ free_fonts (mi); } if ((mc->glx_context = init_GL(mi)) != NULL) { glDrawBuffer(GL_BACK); gl_init(); last = 0; reshape_molecule (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); } if (!load_fonts (mi)) { release_molecule(mi); return; } if (firstcall) startup_blurb (mi); cur_wire = MI_IS_WIREFRAME(mi); wire = cur_wire; mc->rotx = FLOATRAND(1.0) * RANDSIGN(); mc->roty = FLOATRAND(1.0) * RANDSIGN(); mc->rotz = FLOATRAND(1.0) * RANDSIGN(); /* bell curve from 0-6 degrees, avg 3 */ mc->dx = (FLOATRAND(0.1) + FLOATRAND(0.1) + FLOATRAND(0.1)) / (360/2); mc->dy = (FLOATRAND(0.1) + FLOATRAND(0.1) + FLOATRAND(0.1)) / (360/2); mc->dz = (FLOATRAND(0.1) + FLOATRAND(0.1) + FLOATRAND(0.1)) / (360/2); mc->d_max = mc->dx * 8; mc->ddx = 0.00006 + FLOATRAND(0.00003); mc->ddy = 0.00006 + FLOATRAND(0.00003); mc->ddz = 0.00006 + FLOATRAND(0.00003); { char *s = do_spin; while (*s) { if (*s == 'x' || *s == 'X') mc->spin_x = 1; else if (*s == 'y' || *s == 'Y') mc->spin_y = 1; else if (*s == 'z' || *s == 'Z') mc->spin_z = 1; else { (void) fprintf (stderr, "molecule: spin must contain only the characters X, Y, or Z (not \"%s\")\n", do_spin); /* exit (1); */ } s++; } } mc->molecule_dlist = glGenLists(1); load_molecules (mi); mc->which = NRAND(mc->nmolecules); #ifdef STANDALONE mc->no_label_threshold = get_float_resource ("noLabelThreshold", "NoLabelThreshold"); mc->wireframe_threshold = get_float_resource ("wireframeThreshold", "WireframeThreshold"); #else mc->no_label_threshold = 30; mc->wireframe_threshold = 150; #endif if (wire) do_bonds = 1; }
ENTRYPOINT void init_pipes (ModeInfo * mi) { int screen = MI_SCREEN(mi); pipesstruct *pp; if (pipes == NULL) { if ((pipes = (pipesstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (pipesstruct))) == NULL) return; } pp = &pipes[screen]; pp->window = MI_WINDOW(mi); if ((pp->glx_context = init_GL(mi)) != NULL) { reshape_pipes(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); if (rotatepipes) pp->initial_rotation = NRAND(180); /* jwz */ else pp->initial_rotation = -10.0; pinit(mi, 1); if (factory > 0) { pp->valve = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_BigValve); pp->bolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_Bolts3D); pp->betweenbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_PipeBetweenBolts); pp->elbowbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowBolts); pp->elbowcoins = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowCoins); pp->guagehead = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageHead); pp->guageface = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageFace); pp->guagedial = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageDial); pp->guageconnector = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageConnector); pp->teapot = build_teapot(mi); } /* else they are all 0, thanks to calloc(). */ if (MI_COUNT(mi) < 1 || MI_COUNT(mi) > NofSysTypes + 1) { pp->system_type = NRAND(NofSysTypes) + 1; } else { pp->system_type = MI_COUNT(mi); } if (MI_CYCLES(mi) > 0 && MI_CYCLES(mi) < 11) { pp->number_of_systems = MI_CYCLES(mi); } else { pp->number_of_systems = 5; } if (MI_SIZE(mi) < 10) { pp->system_length = 10; } else if (MI_SIZE(mi) > 1000) { pp->system_length = 1000; } else { pp->system_length = MI_SIZE(mi); } } else { MI_CLEARWINDOW(mi); } pp->trackball = gltrackball_init (); generate_system (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); } }
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); } }