void reshape_fire(ModeInfo * mi, int width, int height) { firestruct *fs = &fire[MI_SCREEN(mi)]; int size = MI_SIZE(mi); /* Viewport is specified size if size >= MINSIZE && size < screensize */ if (size <= 1) { fs->WIDTH = width; fs->HEIGHT = height; } else if (size < MINSIZE) { fs->WIDTH = MINSIZE; fs->HEIGHT = MINSIZE; } else { fs->WIDTH = (size > width) ? width : size; fs->HEIGHT = (size > height) ? height : size; } glViewport((width - fs->WIDTH) / 2, (height - fs->HEIGHT) / 2, fs->WIDTH, fs->HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(70.0, fs->WIDTH / (float) fs->HEIGHT, 0.1, 30.0); glMatrixMode(GL_MODELVIEW); }
ENTRYPOINT void reshape_sballs(ModeInfo * mi, int width, int height) #endif { sballsstruct *sb = &sballs[MI_SCREEN(mi)]; int size = MI_SIZE(mi); /* Viewport is specified size if size >= MINSIZE && size < screensize */ if (size <= 1) { sb->WIDTH = MI_WIDTH(mi); sb->HEIGHT = MI_HEIGHT(mi); } else if (size < MINSIZE) { sb->WIDTH = MINSIZE; sb->HEIGHT = MINSIZE; } else { sb->WIDTH = (size > MI_WIDTH(mi)) ? MI_WIDTH(mi) : size; sb->HEIGHT = (size > MI_HEIGHT(mi)) ? MI_HEIGHT(mi) : size; } glViewport((MI_WIDTH(mi) - sb->WIDTH) / 2, (MI_HEIGHT(mi) - sb->HEIGHT) / 2, sb->WIDTH, sb->HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(55.0, (float)sb->WIDTH / (float) sb->HEIGHT, 1.0, 300.0); glMatrixMode(GL_MODELVIEW); }
ENTRYPOINT void init_sierpinski(ModeInfo * mi) { int i; sierpinskistruct *sp; if (tris == NULL) { if ((tris = (sierpinskistruct *) calloc(MI_NUM_SCREENS(mi), sizeof (sierpinskistruct))) == NULL) return; } sp = &tris[MI_SCREEN(mi)]; sp->width = MI_WIDTH(mi); sp->height = MI_HEIGHT(mi); sp->total_npoints = MI_COUNT(mi); if (sp->total_npoints < 1) sp->total_npoints = 1; sp->corners = MI_SIZE(mi); if (sp->corners < 3 || sp->corners > 4) { sp->corners = (int) (LRAND() & 1) + 3; } for (i = 0; i < sp->corners; i++) { if (!sp->pointBuffer[i]) if ((sp->pointBuffer[i] = (XPoint *) malloc(sp->total_npoints * sizeof (XPoint))) == NULL) { free_sierpinski(sp); return; } } startover(mi); }
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); } }
static void initlissie(ModeInfo * mi, lissiestruct * lissie) { lissstruct *lp = &lisses[MI_SCREEN(mi)]; int size = MI_SIZE(mi); int i; if (MI_NPIXELS(mi) > 2) lissie->color = NRAND(MI_NPIXELS(mi)); else lissie->color = MI_WHITE_PIXEL(mi); /* Initialize parameters */ if (size < -MINSIZE) lissie->ri = NRAND(MIN(-size, MAX(MINSIZE, MIN(lp->width, lp->height) / 4)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) lissie->ri = MAX(MINSIZE, MIN(lp->width, lp->height) / 4); else lissie->ri = MINSIZE; } else lissie->ri = MIN(size, MAX(MINSIZE, MIN(lp->width, lp->height) / 4)); lissie->xi = INTRAND(lp->width / 4 + lissie->ri, lp->width * 3 / 4 - lissie->ri); lissie->yi = INTRAND(lp->height / 4 + lissie->ri, lp->height * 3 / 4 - lissie->ri); lissie->rx = INTRAND(lp->width / 4, MIN(lp->width - lissie->xi, lissie->xi)) - 2 * lissie->ri; lissie->ry = INTRAND(lp->height / 4, MIN(lp->height - lissie->yi, lissie->yi)) - 2 * lissie->ri; lissie->len = INTRAND(MINLISSIELEN, MAXLISSIELEN - 1); lissie->pos = 0; lissie->redrawing = 0; lissie->tx = FLOATRAND(0, 2 * M_PI); lissie->ty = FLOATRAND(0, 2 * M_PI); lissie->dtx = FLOATRAND(MINDT, MAXDT); lissie->dty = FLOATRAND(MINDT, MAXDT); for (i = 0; i < MAXLISSIELEN; i++) lissie->loc[i].x = lissie->loc[i].y = 0; /* Draw lissie */ drawlissie(mi, lissie); }
void init_voters(ModeInfo * mi) { int size = MI_SIZE(mi); int i, col, row, colrow; voterstruct *vp; if (voters == NULL) { if ((voters = (voterstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (voterstruct))) == NULL) return; } vp = &voters[MI_SCREEN(mi)]; vp->generation = 0; if (!vp->first) { /* Genesis of democracy */ icon_width = donkey_width; icon_height = donkey_height; if (!init_list(vp)) { free_voters(vp); return; } for (i = 0; i < BITMAPS; i++) { logo[i].width = icon_width; logo[i].height = icon_height; logo[i].bytes_per_line = (icon_width + 7) / 8; } } else /* Exterminate all free thinking individuals */ flush_list(vp); if (MI_IS_FULLRANDOM(mi)) { vp->vertical = (Bool) (LRAND() & 1); } else { vp->vertical = vertical; } vp->width = MI_WIDTH(mi); vp->height = MI_HEIGHT(mi); for (i = 0; i < NEIGHBORKINDS; i++) { if (neighbors == plots[i]) { vp->neighbors = neighbors; break; } if (i == NEIGHBORKINDS - 1) { #if 0 vp->neighbors = plots[NRAND(NEIGHBORKINDS)]; vp->neighbors = (LRAND() & 1) ? 4 : 8; #else vp->neighbors = 8; #endif break; } } if (vp->neighbors == 6) { int nccols, ncrows, sides; if (!vp->vertical) { vp->height = MI_WIDTH(mi); vp->width = MI_HEIGHT(mi); } if (vp->width < 8) vp->width = 8; if (vp->height < 8) vp->height = 8; if (size < -MINSIZE) vp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(vp->width, vp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) vp->ys = MAX(MINSIZE, MIN(vp->width, vp->height) / MINGRIDSIZE); else vp->ys = MINSIZE; } else vp->ys = MIN(size, MAX(MINSIZE, MIN(vp->width, vp->height) / MINGRIDSIZE)); vp->xs = vp->ys; vp->pixelmode = True; nccols = MAX(vp->width / vp->xs - 2, 2); ncrows = MAX(vp->height / vp->ys - 1, 4); vp->ncols = nccols / 2; vp->nrows = 2 * (ncrows / 4); vp->xb = (vp->width - vp->xs * nccols) / 2 + vp->xs / 2; vp->yb = (vp->height - vp->ys * (ncrows / 2) * 2) / 2 + vp->ys - 2; for (sides = 0; sides < 6; sides++) { if (vp->vertical) { vp->shape.hexagon[sides].x = (vp->xs - 1) * hexagonUnit[sides].x; vp->shape.hexagon[sides].y = ((vp->ys - 1) * hexagonUnit[sides].y / 2) * 4 / 3; } else { vp->shape.hexagon[sides].y = (vp->xs - 1) * hexagonUnit[sides].x; vp->shape.hexagon[sides].x = ((vp->ys - 1) * hexagonUnit[sides].y / 2) * 4 / 3; } } } else if (vp->neighbors == 4 || vp->neighbors == 8) { if (vp->width < 2) vp->width = 2; if (vp->height < 2) vp->height = 2; if (size == 0 || MINGRIDSIZE * size > vp->width || MINGRIDSIZE * size > vp->height) { if (vp->width > MINGRIDSIZE * icon_width && vp->height > MINGRIDSIZE * icon_height) { vp->pixelmode = False; vp->xs = icon_width; vp->ys = icon_height; } else { vp->pixelmode = True; vp->xs = vp->ys = MAX(MINSIZE, MIN(vp->width, vp->height) / MINGRIDSIZE); } } else { vp->pixelmode = True; if (size < -MINSIZE) vp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(vp->width, vp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) vp->ys = MINSIZE; else vp->ys = MIN(size, MAX(MINSIZE, MIN(vp->width, vp->height) / MINGRIDSIZE)); vp->xs = vp->ys; } vp->ncols = MAX(vp->width / vp->xs, 2); vp->nrows = MAX(vp->height / vp->ys, 2); vp->xb = (vp->width - vp->xs * vp->ncols) / 2; vp->yb = (vp->height - vp->ys * vp->nrows) / 2; } else { /* TRI */ int orient, sides; if (!vp->vertical) { vp->height = MI_WIDTH(mi); vp->width = MI_HEIGHT(mi); } if (vp->width < 2) vp->width = 2; if (vp->height < 2) vp->height = 2; if (size < -MINSIZE) vp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(vp->width, vp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) vp->ys = MAX(MINSIZE, MIN(vp->width, vp->height) / MINGRIDSIZE); else vp->ys = MINSIZE; } else vp->ys = MIN(size, MAX(MINSIZE, MIN(vp->width, vp->height) / MINGRIDSIZE)); vp->xs = (int) (1.52 * vp->ys); vp->pixelmode = True; vp->ncols = (MAX(vp->width / vp->xs - 1, 2) / 2) * 2; vp->nrows = (MAX(vp->height / vp->ys - 1, 2) / 2) * 2; vp->xb = (vp->width - vp->xs * vp->ncols) / 2 + vp->xs / 2; vp->yb = (vp->height - vp->ys * vp->nrows) / 2 + vp->ys / 2; for (orient = 0; orient < 2; orient++) { for (sides = 0; sides < 3; sides++) { if (vp->vertical) { vp->shape.triangle[orient][sides].x = (vp->xs - 2) * triangleUnit[orient][sides].x; vp->shape.triangle[orient][sides].y = (vp->ys - 2) * triangleUnit[orient][sides].y; } else { vp->shape.triangle[orient][sides].y = (vp->xs - 2) * triangleUnit[orient][sides].x; vp->shape.triangle[orient][sides].x = (vp->ys - 2) * triangleUnit[orient][sides].y; } } } } vp->npositions = vp->ncols * vp->nrows; if (vp->arr != NULL) free(vp->arr); if ((vp->arr = (char *) calloc(vp->npositions, sizeof (char))) == NULL) { free_voters(vp); return; } /* Play G-d with these numbers */ vp->nparties = MI_COUNT(mi); if (vp->nparties < MINPARTIES || vp->nparties > BITMAPS) vp->nparties = NRAND(BITMAPS - MINPARTIES + 1) + MINPARTIES; if (vp->pixelmode) vp->nparties = 2; vp->busyLoop = 0; MI_CLEARWINDOW(mi); vp->painted = False; for (i = 0; i < BITMAPS; i++) vp->number_in_party[i] = 0; for (row = 0; row < vp->nrows; row++) for (col = 0; col < vp->ncols; col++) { colrow = col + row * vp->ncols; if (vp->nparties == 2) i = (NRAND(vp->nparties) + 2) % BITMAPS; else i = NRAND(vp->nparties); vp->arr[colrow] = (char) i; drawcell(mi, col, row, (unsigned long) (MI_NPIXELS(mi) * i / BITMAPS), i, False); vp->number_in_party[i]++; } }
/* Called to init the mode. */ void init_penrose(ModeInfo * mi) { tiling_c *tp; fringe_node_c *fp; int i, size; if (tilings == NULL) { if ((tilings = (tiling_c *) calloc(MI_NUM_SCREENS(mi), sizeof (tiling_c))) == NULL) return; } tp = &tilings[MI_SCREEN(mi)]; if (MI_IS_FULLRANDOM(mi)) tp->ammann = (Bool) (LRAND() & 1); else tp->ammann = ammann; tp->done = False; tp->busyLoop = 0; tp->failures = 0; tp->width = MI_WIDTH(mi); tp->height = MI_HEIGHT(mi); if (MI_NPIXELS(mi) > 2) { tp->thick_color = NRAND(MI_NPIXELS(mi)); /* Insure good contrast */ tp->thin_color = (NRAND(2 * MI_NPIXELS(mi) / 3) + tp->thick_color + MI_NPIXELS(mi) / 6) % MI_NPIXELS(mi); } else { if (LRAND() & 1) { tp->thick_color = MI_WHITE_PIXEL(mi); tp->thin_color = MI_BLACK_PIXEL(mi); } else { tp->thick_color = MI_BLACK_PIXEL(mi); tp->thin_color = MI_WHITE_PIXEL(mi); } } size = MI_SIZE(mi); if (size < -MINSIZE) tp->edge_length = NRAND(MIN(-size, MAX(MINSIZE, MIN(tp->width, tp->height) / 2)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) tp->edge_length = MAX(MINSIZE, MIN(tp->width, tp->height) / 2); else tp->edge_length = MINSIZE; } else tp->edge_length = MIN(size, MAX(MINSIZE, MIN(tp->width, tp->height) / 2)); tp->origin.x = (tp->width / 2 + NRAND(tp->width)) / 2; tp->origin.y = (tp->height / 2 + NRAND(tp->height)) / 2; tp->fringe.n_nodes = 2; if (tp->fringe.nodes != NULL) free_penrose(tp); if (tp->fringe.nodes != NULL || tp->forced.first != 0) { if (MI_IS_VERBOSE(mi)) { (void) fprintf(stderr, "Weirdness in init_penrose()\n"); (void) fprintf(stderr, "tp->fringe.nodes = NULL && tp->forced.first = 0\n"); } free_penrose(tp); /* Try again */ tp->done = True; } tp->forced.n_nodes = tp->forced.n_visible = 0; if ((fp = tp->fringe.nodes = ALLOC_NODE(fringe_node_c)) == NULL) { free_penrose(tp); return; } if (fp == 0) { if (MI_IS_VERBOSE(mi)) { (void) fprintf(stderr, "Weirdness in init_penrose()\n"); (void) fprintf(stderr, "fp = 0\n"); } if ((fp = tp->fringe.nodes = ALLOC_NODE(fringe_node_c)) == NULL) { free_penrose(tp); return; } tp->done = True; } /* First vertex. */ fp->rule_mask = (1 << N_VERTEX_RULES) - 1; fp->list_ptr = 0; if ((fp->prev = fp->next = ALLOC_NODE(fringe_node_c)) == NULL) { free_penrose(tp); return; } if (fp->next == 0) { if (MI_IS_VERBOSE(mi)) { (void) fprintf(stderr, "Weirdness in init_penrose()\n"); (void) fprintf(stderr, "fp->next = 0\n"); } if ((fp->prev = fp->next = ALLOC_NODE(fringe_node_c)) == NULL) { free_penrose(tp); return; } tp->done = True; } fp->n_tiles = 0; fp->loc = tp->origin; fp->off_screen = False; for (i = 0; i < 5; i++) fp->fived[i] = 0; /* Second vertex. */ *(fp->next) = *fp; fp->next->prev = fp->next->next = fp; fp = fp->next; i = NRAND(5); fp->fived[i] = 2 * NRAND(2) - 1; fived_to_loc(fp->fived, tp, &(fp->loc)); /* That's it! We have created our first edge. */ }
ENTRYPOINT void init_demon (ModeInfo * mi) { Display *display = MI_DISPLAY(mi); int size = MI_SIZE(mi), nk; demonstruct *dp; if (demons == NULL) { if ((demons = (demonstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (demonstruct))) == NULL) return; } dp = &demons[MI_SCREEN(mi)]; dp->generation = 0; dp->redrawing = 0; #ifdef DO_STIPPLE if (MI_NPIXELS(mi) < NUMSTIPPLES) { Window window = MI_WINDOW(mi); if (dp->stippledGC == None) { XGCValues gcv; gcv.fill_style = FillOpaqueStippled; if ((dp->stippledGC = XCreateGC(display, window, GCFillStyle, &gcv)) == None) { free_demon(display, dp); return; } } if (dp->init_bits == 0) { int i; for (i = 1; i < NUMSTIPPLES; i++) { DEMONBITS(stipples[i], STIPPLESIZE, STIPPLESIZE); } } } #endif /* DO_STIPPLE */ free_struct(dp); for (nk = 0; nk < NEIGHBORKINDS; nk++) { if (neighbors == plots[0][nk]) { dp->neighbors = plots[0][nk]; break; } if (nk == NEIGHBORKINDS - 1) { nk = NRAND(NEIGHBORKINDS); dp->neighbors = plots[0][nk]; break; } } dp->states = MI_COUNT(mi); if (dp->states < -MINSTATES) dp->states = NRAND(-dp->states - MINSTATES + 1) + MINSTATES; else if (dp->states < MINSTATES) dp->states = plots[1][nk]; if ((dp->cellList = (CellList **) calloc(dp->states, sizeof (CellList *))) == NULL) { free_demon(display, dp); return; } if ((dp->ncells = (int *) calloc(dp->states, sizeof (int))) == NULL) { free_demon(display, dp); return; } dp->state = 0; dp->width = MI_WIDTH(mi); dp->height = MI_HEIGHT(mi); if (dp->neighbors == 6) { int nccols, ncrows, i; if (dp->width < 8) dp->width = 8; if (dp->height < 8) dp->height = 8; if (size < -MINSIZE) dp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) dp->ys = MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE); else dp->ys = MINSIZE; } else dp->ys = MIN(size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)); dp->xs = dp->ys; nccols = MAX(dp->width / dp->xs - 2, 2); ncrows = MAX(dp->height / dp->ys - 1, 4); dp->ncols = nccols / 2; dp->nrows = 2 * (ncrows / 4); dp->xb = (dp->width - dp->xs * nccols) / 2 + dp->xs / 2; dp->yb = (dp->height - dp->ys * (ncrows / 2) * 2) / 2 + dp->ys - 2; for (i = 0; i < 6; i++) { dp->shape.hexagon[i].x = (dp->xs - 1) * hexagonUnit[i].x; dp->shape.hexagon[i].y = ((dp->ys - 1) * hexagonUnit[i].y / 2) * 4 / 3; } } else if (dp->neighbors == 4 || dp->neighbors == 8) { if (size < -MINSIZE) dp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) dp->ys = MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE); else dp->ys = MINSIZE; } else dp->ys = MIN(size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)); dp->xs = dp->ys; dp->ncols = MAX(dp->width / dp->xs, 2); dp->nrows = MAX(dp->height / dp->ys, 2); dp->xb = (dp->width - dp->xs * dp->ncols) / 2; dp->yb = (dp->height - dp->ys * dp->nrows) / 2; } else { /* TRI */ int orient, i; if (dp->width < 2) dp->width = 2; if (dp->height < 2) dp->height = 2; if (size < -MINSIZE) dp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) dp->ys = MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE); else dp->ys = MINSIZE; } else dp->ys = MIN(size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)); dp->xs = (int) (1.52 * dp->ys); dp->ncols = (MAX(dp->width / dp->xs - 1, 2) / 2) * 2; dp->nrows = (MAX(dp->height / dp->ys - 1, 2) / 2) * 2; dp->xb = (dp->width - dp->xs * dp->ncols) / 2 + dp->xs / 2; dp->yb = (dp->height - dp->ys * dp->nrows) / 2 + dp->ys / 2; for (orient = 0; orient < 2; orient++) { for (i = 0; i < 3; i++) { dp->shape.triangle[orient][i].x = (dp->xs - 2) * triangleUnit[orient][i].x; dp->shape.triangle[orient][i].y = (dp->ys - 2) * triangleUnit[orient][i].y; } } } MI_CLEARWINDOW(mi); if ((dp->oldcell = (unsigned char *) malloc(dp->ncols * dp->nrows * sizeof (unsigned char))) == NULL) { free_demon(display, dp); return; } if ((dp->newcell = (unsigned char *) malloc(dp->ncols * dp->nrows * sizeof (unsigned char))) == NULL) { free_demon(display, dp); return; } RandomSoup(mi); }
void init_coral(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); coralstruct *cp; int size = MI_SIZE(mi); int i; if (reefs == NULL) { if ((reefs = (coralstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (coralstruct))) == NULL) return; } cp = &reefs[MI_SCREEN(mi)]; cp->width = MAX(MI_WIDTH(mi), 4); cp->height = MAX(MI_HEIGHT(mi), 4); cp->widthb = ((cp->width + 31) >> 5); if (cp->reef != NULL) free(cp->reef); if ((cp->reef = (unsigned int *) calloc((cp->widthb + 1) * cp->height, sizeof (unsigned int))) == NULL) { free_coral(cp); return; } if (size < -MINSIZE) cp->density = NRAND(MIN(MAXSIZE, -size) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) cp->density = MINSIZE; else cp->density = MIN(MAXSIZE, size); cp->nwalkers = MAX((cp->width * cp->height * cp->density) / 100, 1); if (cp->walkers != NULL) free(cp->walkers); if ((cp->walkers = (XPoint *) calloc(cp->nwalkers, sizeof (XPoint))) == NULL) { free_coral(cp); return; } cp->seeds = MI_COUNT(mi); if (cp->seeds < -MINSEEDS) cp->seeds = NRAND(-cp->seeds - MINSEEDS + 1) + MINSEEDS; else if (cp->seeds < MINSEEDS) cp->seeds = MINSEEDS; MI_CLEARWINDOW(mi); if (MI_NPIXELS(mi) > 2) { cp->colorindex = NRAND(MI_NPIXELS(mi) * COLORTHRESH); XSetForeground(display, gc, MI_PIXEL(mi, cp->colorindex / COLORTHRESH)); } else XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); for (i = 0; i < cp->seeds; i++) { int x, y; do { x = NRAND(cp->width); y = NRAND(cp->height); } while (getdot(x, y)); setdot((x - 1), (y - 1)); setdot(x, (y - 1)); setdot((x + 1), (y - 1)); setdot((x - 1), y); setdot(x, y); setdot((x + 1), y); setdot((x - 1), (y + 1)); setdot(x, (y + 1)); setdot((x + 1), (y + 1)); XDrawPoint(display, window, gc, x, y); } for (i = 0; i < cp->nwalkers; i++) { cp->walkers[i].x = NRAND(cp->width - 2) + 1; cp->walkers[i].y = NRAND(cp->height - 2) + 1; } if (cp->pointbuf) { free(cp->pointbuf); } if ((cp->pointbuf = (XPoint *) calloc((MAXPOINTS + 2), sizeof (XPoint))) == NULL) { free_coral(cp); return; } }
void init_swarm(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int b, t; swarmstruct *sp; if (swarms == NULL) { if ((swarms = (swarmstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (swarmstruct))) == NULL) return; } sp = &swarms[MI_SCREEN(mi)]; sp->beecount = MI_COUNT(mi); if (sp->beecount < -MINBEES) { sp->beecount = NRAND(-sp->beecount - MINBEES + 1) + MINBEES; /* if sp->beecount is random ... the size can change */ free_bees(sp); } else if (sp->beecount < MINBEES) sp->beecount = MINBEES; sp->taillen = MI_SIZE(mi); if (sp->taillen < -MINTRAIL) { /* Change by sqr so its seems more variable */ sp->taillen = NRAND((int) sqrt((double) (-sp->taillen - MINTRAIL + 1))); sp->taillen = sp->taillen * sp->taillen + MINTRAIL; free_segs(sp); } else if (sp->taillen < MINTRAIL) sp->taillen = MINTRAIL; sp->width = MI_WIDTH(mi); sp->height = MI_HEIGHT(mi); sp->border = (sp->width + sp->height) / 50; sp->tick = 0; sp->rolloverflag = 0; if (trackmouse && !sp->cursor) { /* Create an invisible cursor */ Pixmap bit; XColor black; black.red = 0; black.green = 0; black.blue = 0; black.flags = DoRed | DoGreen | DoBlue; if ((bit = XCreatePixmapFromBitmapData(display, window, (char *) "\000", 1, 1, MI_BLACK_PIXEL(mi), MI_BLACK_PIXEL(mi), 1)) == None) { free_bees(sp); /* Do not need to free cursor */ return; } if ((sp->cursor = XCreatePixmapCursor(display, bit, bit, &black, &black, 0, 0)) == None) { XFreePixmap(display, bit); free_bees(sp); return; } XFreePixmap(display, bit); } XDefineCursor(display, window, sp->cursor); MI_CLEARWINDOW(mi); /* Allocate memory. */ if (sp->segs == NULL) { if (((sp->segs = (XSegment *) malloc(sizeof (XSegment) * sp->beecount)) == NULL) || ((sp->old_segs = (XSegment *) malloc(sizeof (XSegment) * sp->beecount)) == NULL) || ((sp->x = (float *) malloc(sizeof (float) * sp->beecount * sp->taillen)) == NULL) || ((sp->y = (float *) malloc(sizeof (float) * sp->beecount * sp->taillen)) == NULL) || ((sp->xv = (float *) malloc(sizeof (float) * sp->beecount)) == NULL) || ((sp->yv = (float *) malloc(sizeof (float) * sp->beecount)) == NULL)) { free_swarm(display, sp); return; } } /* Initialize point positions, velocities, etc. */ if (MI_NPIXELS(mi) > 2) sp->pix = NRAND(MI_NPIXELS(mi)); /* wasp */ sp->wx[0] = sp->border + NRAND(sp->width - 2 * sp->border); sp->wy[0] = sp->border + NRAND(sp->height - 2 * sp->border); sp->wx[1] = sp->wx[0]; sp->wy[1] = sp->wy[0]; sp->wxv = 0; sp->wyv = 0; /* bees */ for (b = 0; b < sp->beecount; b++) { X(0, b) = NRAND(sp->width); Y(0, b) = NRAND(sp->height); for (t = 1; t < sp->taillen; t++) { X(t, b) = X(0, b); Y(t, b) = Y(0, b); } sp->xv[b] = balance_rand(7); sp->yv[b] = balance_rand(7); } }
void init_bouboule(ModeInfo * mi) /***************/ /*- * The stars init part was first inspirated from the net3d game starfield * code. But net3d starfield is not really 3d starfield, and I needed real 3d, * so only remains the net3d starfield initialization main idea, that is * the stars distribution on a sphere (theta and omega computing) */ { StarField *sp; int size = MI_SIZE(mi); int i; double theta, omega; if (starfield == NULL) { if ((starfield = (StarField *) calloc(MI_NUM_SCREENS(mi), sizeof (StarField))) == NULL) return; } sp = &starfield[MI_SCREEN(mi)]; sp->width = MI_WIDTH(mi); sp->height = MI_HEIGHT(mi); /* use the right `black' pixel values: */ if (MI_IS_INSTALL(mi) && MI_IS_USE3D(mi)) { MI_CLEARWINDOWCOLOR(mi, MI_NONE_COLOR(mi)); } else { MI_CLEARWINDOW(mi); } if (size < -MINSIZE) sp->max_star_size = NRAND(-size - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) sp->max_star_size = MINSIZE; else sp->max_star_size = size; sp->NbStars = MI_COUNT(mi); if (sp->NbStars < -MINSTARS) { free_stars(sp); sp->NbStars = NRAND(-sp->NbStars - MINSTARS + 1) + MINSTARS; } else if (sp->NbStars < MINSTARS) sp->NbStars = MINSTARS; /* We get memory for lists of objects */ if (sp->star == NULL) { if ((sp->star = (Star *) malloc(sp->NbStars * sizeof (Star))) == NULL) { free_bouboule(sp); return; } } if (sp->xarc == NULL) { if ((sp->xarc = (XArc *) malloc(sp->NbStars * sizeof (XArc))) == NULL) { free_bouboule(sp); return; } } if (MI_IS_USE3D(mi) && sp->xarcleft == NULL) { if ((sp->xarcleft = (XArc *) malloc(sp->NbStars * sizeof (XArc))) == NULL) { free_bouboule(sp); return; } } #if ((USEOLDXARCS == 1) || (ADAPT_ERASE == 1)) if (sp->oldxarc == NULL) { if ((sp->oldxarc = (XArc *) malloc(sp->NbStars * sizeof (XArc))) == NULL) { free_bouboule(sp); return; } } if (MI_IS_USE3D(mi) && sp->oldxarcleft == NULL) { if ((sp->oldxarcleft = (XArc *) malloc(sp->NbStars * sizeof (XArc))) == NULL) { free_bouboule(sp); return; } } #endif { /* We initialize evolving variables */ if (!sininit(&sp->x, NRAND(3142) / 1000.0, M_PI / (NRAND(100) + 100.0), ((double) sp->width) / 4.0, 3.0 * ((double) sp->width) / 4.0, POSCANRAND)) { free_bouboule(sp); return; } if (!sininit(&sp->y, NRAND(3142) / 1000.0, M_PI / (NRAND(100) + 100.0), ((double) sp->height) / 4.0, 3.0 * ((double) sp->height) / 4.0, POSCANRAND)) { free_bouboule(sp); return; } /* for z, we have to ensure that the bouboule does not get behind */ /* the eyes of the viewer. His/Her eyes are at 0. Because the */ /* bouboule uses the x-radius for the z-radius, too, we have to */ /* use the x-values. */ if (!sininit(&sp->z, NRAND(3142) / 1000.0, M_PI / (NRAND(100) + 100.0), ((double) sp->width / 2.0 + MINZVAL), ((double) sp->width / 2.0 + MAXZVAL), POSCANRAND)) { free_bouboule(sp); return; } if (!sininit(&sp->sizex, NRAND(3142) / 1000.0, M_PI / (NRAND(100) + 100.0), MIN(((double) sp->width) - sp->x.value, sp->x.value) / 5.0, MIN(((double) sp->width) - sp->x.value, sp->x.value), SIZECANRAND)) { free_bouboule(sp); return; } if (!sininit(&sp->sizey, NRAND(3142) / 1000.0, M_PI / (NRAND(100) + 100.0), MAX(sp->sizex.value / MAX_SIZEX_SIZEY, sp->sizey.maximum / 5.0), MIN(sp->sizex.value * MAX_SIZEX_SIZEY, MIN(((double) sp->height) - sp->y.value, sp->y.value)), SIZECANRAND)) { free_bouboule(sp); return; } if (!sininit(&sp->thetax, NRAND(3142) / 1000.0, M_PI / (NRAND(200) + 200.0), -M_PI, M_PI, THETACANRAND)) { free_bouboule(sp); return; } if (!sininit(&sp->thetay, NRAND(3142) / 1000.0, M_PI / (NRAND(200) + 200.0), -M_PI, M_PI, THETACANRAND)) { free_bouboule(sp); return; } if (!sininit(&sp->thetaz, NRAND(3142) / 1000.0, M_PI / (NRAND(400) + 400.0), -M_PI, M_PI, THETACANRAND)) { free_bouboule(sp); return; } } for (i = 0; i < sp->NbStars; i++) { Star *star; XArc *arc, *arcleft = (XArc *) NULL; #if ((USEOLDXARCS == 1) || (ADAPT_ERASE == 1)) XArc *oarc, *oarcleft = (XArc *) NULL; #endif star = &(sp->star[i]); arc = &(sp->xarc[i]); if (MI_IS_USE3D(mi)) arcleft = &(sp->xarcleft[i]); #if ((USEOLDXARCS == 1) || (ADAPT_ERASE == 1)) oarc = &(sp->oldxarc[i]); if (MI_IS_USE3D(mi)) oarcleft = &(sp->oldxarcleft[i]); #endif /* Elevation and bearing of the star */ theta = dtor((NRAND(1800)) / 10.0 - 90.0); omega = dtor((NRAND(3600)) / 10.0 - 180.0); /* Stars coordinates in a 3D space */ star->x = cos(theta) * sin(omega); star->y = sin(omega) * sin(theta); star->z = cos(omega); /* We set the stars size */ star->size = NRAND(2 * sp->max_star_size); if (star->size < sp->max_star_size) star->size = 0; else star->size -= sp->max_star_size; /* We set default values for the XArc lists elements, but offscreen */ arc->x = MI_WIDTH(mi); arc->y = MI_HEIGHT(mi); if (MI_IS_USE3D(mi)) { arcleft->x = MI_WIDTH(mi); arcleft->y = MI_HEIGHT(mi); } #if ((USEOLDXARCS == 1) || (ADAPT_ERASE == 1)) oarc->x = MI_WIDTH(mi); oarc->y = MI_HEIGHT(mi); if (MI_IS_USE3D(mi)) { oarcleft->x = MI_WIDTH(mi); oarcleft->y = MI_HEIGHT(mi); } #endif arc->width = 2 + star->size; arc->height = 2 + star->size; if (MI_IS_USE3D(mi)) { arcleft->width = 2 + star->size; arcleft->height = 2 + star->size; } #if ((USEOLDXARCS == 1) || (ADAPT_ERASE == 1)) oarc->width = 2 + star->size; oarc->height = 2 + star->size; if (MI_IS_USE3D(mi)) { oarcleft->width = 2 + star->size; oarcleft->height = 2 + star->size; } #endif arc->angle1 = 0; arc->angle2 = 360 * 64; if (MI_IS_USE3D(mi)) { arcleft->angle1 = 0; arcleft->angle2 = 360 * 64; } #if ((USEOLDXARCS == 1) || (ADAPT_ERASE == 1)) oarc->angle1 = 0; oarc->angle2 = 360 * 64; /* ie. we draw whole disks: * from 0 to 360 degrees */ if (MI_IS_USE3D(mi)) { oarcleft->angle1 = 0; oarcleft->angle2 = 360 * 64; } #endif } if (MI_NPIXELS(mi) > 2) sp->colorp = NRAND(MI_NPIXELS(mi)); /* We set up the starfield color */ if (!MI_IS_USE3D(mi) && MI_NPIXELS(mi) > 2) sp->color = MI_PIXEL(mi, sp->colorp); else sp->color = MI_WHITE_PIXEL(mi); #if (ADAPT_ERASE == 1) /* We initialize the adaptation code for screen erasing */ sp->hasbeenchecked = ADAPT_CHECKS * 2; sp->rect_time = 0; sp->xarc_time = 0; #endif }
/* Hook function, sets state to initial position. */ void init_pacman(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int size = MI_SIZE(mi); pacmangamestruct *pp; XGCValues gcv; int dir, mouth; GC fg_gc, bg_gc; XPoint points[9]; if (pacmangames == NULL) { if ((pacmangames = (pacmangamestruct *) calloc((size_t)MI_NUM_SCREENS(mi), sizeof (pacmangamestruct))) == NULL) return; } pp = &pacmangames[MI_SCREEN(mi)]; pp->width = (unsigned short)MI_WIDTH(mi); pp->height = (unsigned short)MI_HEIGHT(mi); if (pp->ghostPixmap != None) { XFreePixmap(display, pp->ghostPixmap); pp->ghostPixmap = None; pp->graphics_format = IS_NONE; } if (size == 0 || MINGRIDSIZE * size > (int)pp->width || MINGRIDSIZE * size > (int)pp->height) { pp->ys = pp->xs = MAX(MIN(pp->width/LEVWIDTH, pp->height/LEVHEIGHT), 1); } else { if (size < -MINSIZE) pp->ys = (short)(NRAND( MIN( -size, MAX( MINSIZE, MIN( pp->width, pp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE); else if (size < MINSIZE) pp->ys = MINSIZE; else pp->ys = (short)(MIN(size, MAX(MINSIZE, MIN(pp->width, pp->height) / MINGRIDSIZE))); pp->xs = pp->ys; } pp->wallwidth = (unsigned int)(pp->xs + pp->ys) >> 4; if (pp->wallwidth < 1) pp->wallwidth = 1; pp->incx = (pp->xs >> 3) + 1; pp->incy = (pp->ys >> 3) + 1; pp->ncols = (unsigned short)MAX(LEVWIDTH, 2); pp->nrows = (unsigned short)MAX(LEVHEIGHT, 2); pp->xb = (pp->width - pp->ncols * pp->xs) >> 1; pp->yb = (pp->height - pp->nrows * pp->ys) >> 1; pp->spritexs = MAX(pp->xs + (pp->xs >> 1) - 1, 1); pp->spriteys = MAX(pp->ys + (pp->ys >> 1) - 1, 1); pp->spritedx = (pp->xs - pp->spritexs) >> 1; pp->spritedy = (pp->ys - pp->spriteys) >> 1; if ((pp->ghostPixmap = XCreatePixmap(display, window, pp->spritexs, pp->spriteys, 1)) == None) { free_pacman(display, pp); return; } gcv.foreground = 0; gcv.background = 1; if ((bg_gc = XCreateGC(display, pp->ghostPixmap, GCForeground | GCBackground, &gcv)) == None) { free_pacman(display, pp); return; } gcv.foreground = 1; gcv.background = 0; if ((fg_gc = XCreateGC(display, pp->ghostPixmap, GCForeground | GCBackground, &gcv)) == None) { XFreeGC(display, bg_gc); free_pacman(display, pp); return; } #define SETPOINT(p, xp, yp) p.x = xp; p.y = yp /* draw the triangles on the bottom (scalable) */ SETPOINT(points[0], 1, pp->spriteys * 5 / 6); SETPOINT(points[1], pp->spritexs / 6, pp->spriteys); SETPOINT(points[2], pp->spritexs / 3, pp->spriteys * 5 / 6); SETPOINT(points[3], pp->spritexs / 2, pp->spriteys); SETPOINT(points[4], pp->spritexs * 2 / 3, pp->spriteys * 5 / 6); SETPOINT(points[5], pp->spritexs * 5 / 6, pp->spriteys); SETPOINT(points[6], pp->spritexs, pp->spriteys * 5 / 6); SETPOINT(points[7], pp->spritexs, pp->spriteys / 2); SETPOINT(points[8], 1, pp->spriteys / 2); XFillRectangle(display, pp->ghostPixmap, bg_gc, 0, 0, pp->spritexs, pp->spriteys); XFillArc(display, pp->ghostPixmap, fg_gc, 0, 0, pp->spritexs, pp->spriteys, 0, 11520); XFillPolygon(display, pp->ghostPixmap, fg_gc, points, 9, Nonconvex, CoordModeOrigin); XFreeGC(display, bg_gc); XFreeGC(display, fg_gc); if (!pp->stippledGC) { gcv.foreground = MI_BLACK_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); if ((pp->stippledGC = XCreateGC(display, window, GCForeground | GCBackground, &gcv)) == None) { free_pacman(display, pp); return; } } if (pp->pacmanPixmap[0][0] != None) for (dir = 0; dir < 4; dir++) for (mouth = 0; mouth < MAXMOUTH; mouth++) XFreePixmap(display, pp->pacmanPixmap[dir] [mouth]); for (dir = 0; dir < 4; dir++) for (mouth = 0; mouth < MAXMOUTH; mouth++) { if ((pp->pacmanPixmap[dir][mouth] = XCreatePixmap( display, MI_WINDOW(mi), pp->spritexs, pp->spriteys, 1)) == None) { free_pacman(display, pp); return; } gcv.foreground = 1; gcv.background = 0; if ((fg_gc = XCreateGC(display, pp->pacmanPixmap[dir][mouth], GCForeground | GCBackground, &gcv)) == None) { free_pacman(display, pp); return; } gcv.foreground = 0; gcv.background = 0; if ((bg_gc = XCreateGC(display, pp->pacmanPixmap[dir][mouth], GCForeground | GCBackground, &gcv)) == None) { XFreeGC(display, fg_gc); free_pacman(display, pp); return; } XFillRectangle(display, pp->pacmanPixmap[dir][mouth], bg_gc, 0, 0, pp->spritexs, pp->spriteys); if (pp->spritexs == 1 && pp->spriteys == 1) XFillRectangle(display, pp->pacmanPixmap[dir][mouth], fg_gc, 0, 0, pp->spritexs, pp->spriteys); else XFillArc(display, pp->pacmanPixmap[dir][mouth], fg_gc, 0, 0, pp->spritexs, pp->spriteys, ((90 - dir * 90) + mouth * 5) * 64, (360 + (-2 * mouth * 5)) * 64); XFreeGC(display, fg_gc); XFreeGC(display, bg_gc); } pp->pacman.lastbox = START; pp->pacman.mouthdirection = 1; pp->pacman.nextcol = NOWHERE; pp->pacman.nextrow = NOWHERE; if (pp->ghosts != NULL) { free(pp->ghosts); pp->ghosts = (ghoststruct *) NULL; } pp->nghosts = GHOSTS; if (!pp->ghosts) if ((pp->ghosts = (ghoststruct *) calloc((size_t)pp->nghosts, sizeof (ghoststruct))) == NULL) { free_pacman(display, pp); return; } pp->pacman.mouthstage = MAXMOUTH - 1; MI_CLEARWINDOW(mi); repopulate(mi); }
void init_wire(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i, size = MI_SIZE(mi), n; circuitstruct *wp; XGCValues gcv; if (circuits == NULL) { if ((circuits = (circuitstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (circuitstruct))) == NULL) return; } wp = &circuits[MI_SCREEN(mi)]; wp->redrawing = 0; if ((MI_NPIXELS(mi) <= 2) && (wp->init_bits == 0)) { if (wp->stippledGC == None) { gcv.fill_style = FillOpaqueStippled; if ((wp->stippledGC = XCreateGC(display, window, GCFillStyle, &gcv)) == None) { free_wire(display, wp); return; } } WIREBITS(stipples[NUMSTIPPLES - 1], STIPPLESIZE, STIPPLESIZE); WIREBITS(stipples[NUMSTIPPLES - 3], STIPPLESIZE, STIPPLESIZE); WIREBITS(stipples[2], STIPPLESIZE, STIPPLESIZE); } if (MI_NPIXELS(mi) > 2) { wp->colors[0] = (NRAND(MI_NPIXELS(mi))); wp->colors[1] = (wp->colors[0] + MI_NPIXELS(mi) / 6 + NRAND(MI_NPIXELS(mi) / 4 + 1)) % MI_NPIXELS(mi); wp->colors[2] = (wp->colors[1] + MI_NPIXELS(mi) / 6 + NRAND(MI_NPIXELS(mi) / 4 + 1)) % MI_NPIXELS(mi); } free_list(wp); wp->generation = 0; if (MI_IS_FULLRANDOM(mi)) { wp->vertical = (Bool) (LRAND() & 1); } else { wp->vertical = vertical; } wp->width = MI_WIDTH(mi); wp->height = MI_HEIGHT(mi); for (i = 0; i < NEIGHBORKINDS; i++) { if (neighbors == plots[i]) { wp->neighbors = plots[i]; break; } if (i == NEIGHBORKINDS - 1) { i = NRAND(NEIGHBORKINDS - 3) + 1; /* Skip triangular ones */ wp->neighbors = plots[i]; break; } } wp->prob_array[wp->neighbors - 1] = 100; if (wp->neighbors == 3) { wp->prob_array[1] = 67; wp->prob_array[0] = 33; } else { int incr = 24 / wp->neighbors; for (i = wp->neighbors - 2; i >= 0; i--) { wp->prob_array[i] = wp->prob_array[i + 1] - incr - incr * ((i + 1) != wp->neighbors / 2); } } if (wp->neighbors == 6) { int nccols, ncrows; wp->polygon = 6; if (!wp->vertical) { wp->height = MI_WIDTH(mi); wp->width = MI_HEIGHT(mi); } if (wp->width < 8) wp->width = 8; if (wp->height < 8) wp->height = 8; if (size < -MINSIZE) wp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) wp->ys = MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE); else wp->ys = MINSIZE; } else wp->ys = MIN(size, MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE)); wp->xs = wp->ys; nccols = MAX(wp->width / wp->xs - 2, 16); ncrows = MAX(wp->height / wp->ys - 1, 16); wp->ncols = nccols / 2; wp->nrows = ncrows / 2; wp->nrows -= !(wp->nrows & 1); /* Must be odd */ wp->xb = (wp->width - wp->xs * nccols) / 2 + wp->xs; wp->yb = (wp->height - wp->ys * ncrows) / 2 + wp->ys; for (i = 0; i < 6; i++) { if (wp->vertical) { wp->shape.hexagon[i].x = (wp->xs - 1) * hexagonUnit[i].x; wp->shape.hexagon[i].y = ((wp->ys - 1) * hexagonUnit[i].y / 2) * 4 / 3; } else { wp->shape.hexagon[i].y = (wp->xs - 1) * hexagonUnit[i].x; wp->shape.hexagon[i].x = ((wp->ys - 1) * hexagonUnit[i].y / 2) * 4 / 3; } } } else if (wp->neighbors == 4 || wp->neighbors == 8) { wp->polygon = 4; if (size < -MINSIZE) wp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) wp->ys = MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE); else wp->ys = MINSIZE; } else wp->ys = MIN(size, MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE)); wp->xs = wp->ys; wp->ncols = MAX(wp->width / wp->xs, 8); wp->nrows = MAX(wp->height / wp->ys, 8); wp->xb = (wp->width - wp->xs * wp->ncols) / 2; wp->yb = (wp->height - wp->ys * wp->nrows) / 2; } else { /* TRI */ int orient; wp->polygon = 3; if (!wp->vertical) { wp->height = MI_WIDTH(mi); wp->width = MI_HEIGHT(mi); } if (wp->width < 4) wp->width = 4; if (wp->height < 2) wp->height = 2; if (size < -MINSIZE) wp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) wp->ys = MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE); else wp->ys = MINSIZE; } else wp->ys = MIN(size, MAX(MINSIZE, MIN(wp->width, wp->height) / MINGRIDSIZE)); wp->xs = (int) (1.52 * wp->ys); wp->ncols = (MAX(wp->width / wp->xs - 1, 8) / 2) * 2; wp->nrows = (MAX(wp->height / wp->ys - 1, 8) / 2) * 2 - 1; wp->xb = (wp->width - wp->xs * wp->ncols) / 2 + wp->xs / 2; wp->yb = (wp->height - wp->ys * wp->nrows) / 2 + wp->ys; for (orient = 0; orient < 2; orient++) { for (i = 0; i < 3; i++) { if (wp->vertical) { wp->shape.triangle[orient][i].x = (wp->xs - 2) * triangleUnit[orient][i].x; wp->shape.triangle[orient][i].y = (wp->ys - 2) * triangleUnit[orient][i].y; } else { wp->shape.triangle[orient][i].y = (wp->xs - 2) * triangleUnit[orient][i].x; wp->shape.triangle[orient][i].x = (wp->ys - 2) * triangleUnit[orient][i].y; } } } } /* * I am being a bit naughty here wasting a little bit of memory * but it will give me a real headache to figure out the logic * and to refigure the mappings to save a few bytes * ncols should only need a border of 2 and nrows should only need * a border of 4 when in the neighbors = 9 or 12 */ wp->bncols = wp->ncols + 4; wp->bnrows = wp->nrows + 4; if (MI_IS_VERBOSE(mi)) (void) fprintf(stdout, "neighbors %d, ncols %d, nrows %d\n", wp->neighbors, wp->ncols, wp->nrows); MI_CLEARWINDOW(mi); if (wp->oldcells != NULL) { free(wp->oldcells); wp->oldcells = (unsigned char *) NULL; } if ((wp->oldcells = (unsigned char *) calloc(wp->bncols * wp->bnrows, sizeof (unsigned char))) == NULL) { free_wire(display, wp); return; } if (wp->newcells != NULL) { free(wp->newcells); wp->newcells = (unsigned char *) NULL; } if ((wp->newcells = (unsigned char *) calloc(wp->bncols * wp->bnrows, sizeof (unsigned char))) == NULL) { free_wire(display, wp); return; } n = MI_COUNT(mi); i = (1 + (wp->neighbors == 6)) * wp->ncols * wp->nrows / 4; if (n < -MINWIRES && i > MINWIRES) { n = NRAND(MIN(-n, i) - MINWIRES + 1) + MINWIRES; } else if (n < MINWIRES) { n = MINWIRES; } else if (n > i) { n = MAX(MINWIRES, i); } create_path(wp, n); }
void init_dilemma(ModeInfo * mi) { int size = MI_SIZE(mi); int i, col, row, colrow, mrow; dilemmastruct *dp; if (dilemmas == NULL) { if ((dilemmas = (dilemmastruct *) calloc(MI_NUM_SCREENS(mi), sizeof (dilemmastruct))) == NULL) return; } dp = &dilemmas[MI_SCREEN(mi)]; dp->generation = 0; dp->redrawing = 0; dp->state = 0; free_dilemma(dp); if (!dp->initialized) { /* Genesis */ icon_width = cooperat_width; icon_height = cooperat_height; dp->initialized = 1; for (i = 0; i < BITMAPS; i++) { logo[i].width = icon_width; logo[i].height = icon_height; logo[i].bytes_per_line = (icon_width + 7) / 8; } } if (MI_IS_FULLRANDOM(mi)) { dp->vertical = (Bool) (LRAND() & 1); } else { dp->vertical = vertical; } dp->width = MI_WIDTH(mi); dp->height = MI_HEIGHT(mi); for (i = 0; i < NEIGHBORKINDS; i++) { if (neighbors == plots[i]) { dp->neighbors = neighbors; break; } if (i == NEIGHBORKINDS - 1) { #if 0 dp->neighbors = plots[NRAND(NEIGHBORKINDS)]; dp->neighbors = (LRAND() & 1) ? 4 : 8; #else dp->neighbors = 8; #endif break; } } if (dp->neighbors == 6) { int nccols, ncrows, sides; if (!dp->vertical) { dp->height = MI_WIDTH(mi); dp->width = MI_HEIGHT(mi); } if (dp->width < 2) dp->width = 2; if (dp->height < 4) dp->height = 4; if (size < -MINSIZE) dp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) dp->ys = MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE); else dp->ys = MINSIZE; } else dp->ys = MIN(size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)); dp->xs = dp->ys; dp->pixelmode = True; nccols = MAX(dp->width / dp->xs - 2, 2); ncrows = MAX(dp->height / dp->ys - 1, 2); dp->ncols = nccols / 2; dp->nrows = 2 * (ncrows / 4); dp->xb = (dp->width - dp->xs * nccols) / 2 + dp->xs / 2; dp->yb = (dp->height - dp->ys * (ncrows / 2) * 2) / 2 + dp->ys - 2; for (sides = 0; sides < 6; sides++) { if (dp->vertical) { dp->shape.hexagon[sides].x = (dp->xs - 1) * hexagonUnit[sides].x; dp->shape.hexagon[sides].y = ((dp->ys - 1) * hexagonUnit[sides].y / 2) * 4 / 3; } else { dp->shape.hexagon[sides].y = (dp->xs - 1) * hexagonUnit[sides].x; dp->shape.hexagon[sides].x = ((dp->ys - 1) * hexagonUnit[sides].y / 2) * 4 / 3; } } } else if (dp->neighbors == 4 || dp->neighbors == 8) { if (dp->width < 2) dp->width = 2; if (dp->height < 2) dp->height = 2; if (size == 0 || MINGRIDSIZE * size > dp->width || MINGRIDSIZE * size > dp->height) { if (dp->width > MINGRIDSIZE * icon_width && dp->height > MINGRIDSIZE * icon_height) { dp->pixelmode = False; dp->xs = icon_width; dp->ys = icon_height; } else { dp->pixelmode = True; dp->xs = dp->ys = MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE); } } else { dp->pixelmode = True; if (size < -MINSIZE) dp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) dp->ys = MINSIZE; else dp->ys = MIN(size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)); dp->xs = dp->ys; } dp->ncols = MAX(dp->width / dp->xs, 2); dp->nrows = MAX(dp->height / dp->ys, 2); dp->xb = (dp->width - dp->xs * dp->ncols) / 2; dp->yb = (dp->height - dp->ys * dp->nrows) / 2; } else { /* TRI */ int orient; if (!dp->vertical) { dp->height = MI_WIDTH(mi); dp->width = MI_HEIGHT(mi); } if (dp->width < 2) dp->width = 2; if (dp->height < 2) dp->height = 2; if (size < -MINSIZE) dp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) dp->ys = MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE); else dp->ys = MINSIZE; } else dp->ys = MIN(size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)); dp->xs = (int) (1.52 * dp->ys); dp->pixelmode = True; dp->ncols = (MAX(dp->width / dp->xs - 1, 2) / 2) * 2; dp->nrows = (MAX(dp->height / dp->ys - 1, 2) / 2) * 2; dp->xb = (dp->width - dp->xs * dp->ncols) / 2 + dp->xs / 2; dp->yb = (dp->height - dp->ys * dp->nrows) / 2 + dp->ys / 2; for (orient = 0; orient < 2; orient++) { for (i = 0; i < 3; i++) { if (dp->vertical) { dp->shape.triangle[orient][i].x = (dp->xs - 2) * triangleUnit[orient][i].x; dp->shape.triangle[orient][i].y = (dp->ys - 2) * triangleUnit[orient][i].y; } else { dp->shape.triangle[orient][i].y = (dp->xs - 2) * triangleUnit[orient][i].x; dp->shape.triangle[orient][i].x = (dp->ys - 2) * triangleUnit[orient][i].y; } } } } dp->npositions = dp->ncols * dp->nrows; dp->pm[0][0] = 1, dp->pm[0][1] = 0; if (bonus < 1.0 || bonus > 4.0) dp->pm[1][0] = 1.85; else dp->pm[1][0] = bonus; dp->pm[1][1] = 0; if (MI_NPIXELS(mi) >= COLORS) { dp->colors[0][0] = MI_PIXEL(mi, BLUE); /* COOPERATING, was cooperating */ dp->colors[0][1] = MI_PIXEL(mi, GREEN); /* COOPERATING, was defecting */ dp->colors[1][0] = MI_PIXEL(mi, YELLOW); /* DEFECTING, was cooperating */ dp->colors[1][1] = MI_PIXEL(mi, RED); /* DEFECTING, was defecting */ } else { dp->colors[0][0] = MI_WHITE_PIXEL(mi); dp->colors[0][1] = MI_WHITE_PIXEL(mi); dp->colors[1][0] = MI_WHITE_PIXEL(mi); dp->colors[1][1] = MI_WHITE_PIXEL(mi); } alloc_dilemma(dp); if (dp->s == NULL) return; MI_CLEARWINDOW(mi); dp->defectors = MI_COUNT(mi); if (dp->defectors < -MINDEFECT) { dp->defectors = NRAND(-dp->defectors - MINDEFECT + 1) + MINDEFECT; } else if (dp->defectors < MINDEFECT) dp->defectors = MINDEFECT; if (dp->defectors > dp->npositions) dp->defectors = dp->npositions; for (i = 0; i < dp->defectors; i++) { do { colrow = NRAND(dp->npositions); } while (dp->sn[colrow]); dp->sn[colrow] = 1; } #if 0 /* if p was a float... */ mrow = 0; for (row = 0; row < dp->nrows; row++) { for (col = 0; col < dp->ncols; col++) { dp->sn[col + mrow] = ((float) LRAND() / MAXRAND < dp->p); } mrow += dp->ncols; } #endif dp->defectors = 0; /* Show initial state... real important for debugging */ 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; } }
void init_toneclock(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i, size_hour, istart; toneclockstruct *tclock; /* initialize */ if (toneclocks == NULL) { if ((toneclocks = (toneclockstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (toneclockstruct))) == NULL) return; } tclock = &toneclocks[MI_SCREEN(mi)]; tclock->mi = mi; if (tclock->gc == None) { if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XColor color; #ifndef STANDALONE tclock->fg = MI_FG_PIXEL(mi); tclock->bg = MI_BG_PIXEL(mi); #endif tclock->blackpixel = MI_BLACK_PIXEL(mi); tclock->whitepixel = MI_WHITE_PIXEL(mi); if ((tclock->cmap = XCreateColormap(display, window, MI_VISUAL(mi), AllocNone)) == None) { free_toneclock(display, tclock); return; } XSetWindowColormap(display, window, tclock->cmap); (void) XParseColor(display, tclock->cmap, "black", &color); (void) XAllocColor(display, tclock->cmap, &color); MI_BLACK_PIXEL(mi) = color.pixel; (void) XParseColor(display, tclock->cmap, "white", &color); (void) XAllocColor(display, tclock->cmap, &color); MI_WHITE_PIXEL(mi) = color.pixel; #ifndef STANDALONE (void) XParseColor(display, tclock->cmap, background, &color); (void) XAllocColor(display, tclock->cmap, &color); MI_BG_PIXEL(mi) = color.pixel; (void) XParseColor(display, tclock->cmap, foreground, &color); (void) XAllocColor(display, tclock->cmap, &color); MI_FG_PIXEL(mi) = color.pixel; #endif tclock->colors = (XColor *) NULL; tclock->ncolors = 0; } if ((tclock->gc = XCreateGC(display, MI_WINDOW(mi), (unsigned long) 0, (XGCValues *) NULL)) == None) { free_toneclock(display, tclock); return; } } /* Clear Display */ MI_CLEARWINDOW(mi); tclock->painted = False; XSetFunction(display, tclock->gc, GXxor); /*Set up toneclock data */ if (MI_IS_FULLRANDOM(mi)) { if (NRAND(10)) tclock->original = False; else tclock->original = True; } else { tclock->original = original; } tclock->direction = (LRAND() & 1) ? 1 : -1; tclock->win_width = MI_WIDTH(mi); tclock->win_height = MI_HEIGHT(mi); if (tclock->hour != NULL) free_hour(tclock); if ( tclock->original ) { tclock->num_hour = 12; } else { tclock->num_hour = MI_COUNT(mi); } tclock->x0 = tclock->win_width / 2; tclock->y0 = tclock->win_height / 2; if (tclock->num_hour == 0) { tclock->num_hour = DEF_NUM_hour; } else if (tclock->num_hour < 0) { tclock->num_hour = NRAND(-tclock->num_hour) + 1; } if ( tclock->num_hour < 12 ) istart = NRAND( 12 - tclock->num_hour ); else istart = 0; if ((tclock->hour = (toneclockhour *) calloc(tclock->num_hour, sizeof (toneclockhour))) == NULL) { free_toneclock(display, tclock); return; } if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { /* Set up colour map */ if (tclock->colors != NULL) { if (tclock->ncolors && !tclock->no_colors) free_colors(display, tclock->cmap, tclock->colors, tclock->ncolors); free(tclock->colors); tclock->colors = (XColor *) NULL; } tclock->ncolors = MI_NCOLORS(mi); if (tclock->ncolors < 2) tclock->ncolors = 2; if (tclock->ncolors <= 2) tclock->mono_p = True; else tclock->mono_p = False; if (tclock->mono_p) tclock->colors = (XColor *) NULL; else if ((tclock->colors = (XColor *) malloc(sizeof (*tclock->colors) * (tclock->ncolors + 1))) == NULL) { free_toneclock(display, tclock); return; } tclock->cycle_p = has_writable_cells(mi); if (tclock->cycle_p) { if (MI_IS_FULLRANDOM(mi)) { if (!NRAND(8)) tclock->cycle_p = False; else tclock->cycle_p = True; } else { tclock->cycle_p = cycle_p; } } if (!tclock->mono_p) { if (!(LRAND() % 10)) make_random_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tclock->cmap, tclock->colors, &tclock->ncolors, True, True, &tclock->cycle_p); else if (!(LRAND() % 2)) make_uniform_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tclock->cmap, tclock->colors, &tclock->ncolors, True, &tclock->cycle_p); else make_smooth_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tclock->cmap, tclock->colors, &tclock->ncolors, True, &tclock->cycle_p); } XInstallColormap(display, tclock->cmap); if (tclock->ncolors < 2) { tclock->ncolors = 2; tclock->no_colors = True; } else tclock->no_colors = False; if (tclock->ncolors <= 2) tclock->mono_p = True; if (tclock->mono_p) tclock->cycle_p = False; } #ifndef NO_DBUF if (tclock->dbuf != None) XFreePixmap(display, tclock->dbuf); tclock->dbuf = XCreatePixmap(display, window, tclock->win_width, tclock->win_height, MI_DEPTH(mi)); /* Allocation checked */ if (tclock->dbuf != None) { XGCValues gcv; gcv.foreground = 0; gcv.background = 0; gcv.graphics_exposures = False; gcv.function = GXcopy; if (tclock->dbuf_gc != None) XFreeGC(display, tclock->dbuf_gc); if ((tclock->dbuf_gc = XCreateGC(display, (Drawable) tclock->dbuf, GCForeground | GCBackground | GCGraphicsExposures | GCFunction, &gcv)) == None) { XFreePixmap(display, tclock->dbuf); tclock->dbuf = None; } else { XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc, 0, 0, tclock->win_width, tclock->win_height); /*XSetBackground(display, MI_GC(mi), MI_BLACK_PIXEL(mi)); XSetFunction(display, MI_GC(mi), GXcopy);*/ } } #endif tclock->angle = NRAND(360) * PI_RAD; tclock->velocity = (NRAND(7) - 3) * PI_RAD; size_hour = MIN( tclock->win_width , tclock->win_height) / 3; tclock->pulsating = False; tclock->moving = False; tclock->anglex = 0.0; tclock->angley = 0.0; tclock->fill = 0; tclock->radius = size_hour; tclock->max_radius =0.0; if ( ( !tclock->original && NRAND( 15 ) == 3 ) || tclock->num_hour > 12 ) tclock->randomhour = True; else tclock->randomhour = False; if ( !tclock->original && tclock->win_width > 20 ) { if ( abs( MI_SIZE(mi) ) > size_hour ) { if ( MI_SIZE( mi ) < 0 ) { size_hour = -size_hour; } } else { size_hour = MI_SIZE(mi); } if ( size_hour < 0 ) { tclock->radius = MIN(NRAND( size_hour - 10) + 10, tclock->radius ); } else { tclock->radius = MIN( size_hour , tclock->radius ); } if ( MI_IS_FULLRANDOM( mi ) ) { if ( NRAND(2) ) tclock->pulsating = True; else tclock->pulsating = False; tclock->fill = NRAND( 101 ); } else { tclock->pulsating = pulsating; tclock->fill = fill; } } tclock->phase = 0.0; if ( tclock->pulsating ) tclock->ph_vel = (NRAND(7) - 3) * PI_RAD; for (i = 0; i < tclock->num_hour; i++) { toneclockhour *hour0; hour0 = &tclock->hour[i]; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (tclock->ncolors > 2) hour0->colour = NRAND(tclock->ncolors - 2) + 2; else hour0->colour = 1; /* Just in case */ XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel); } else { if (MI_NPIXELS(mi) > 2) hour0->colour = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); else hour0->colour = 1; /*Xor'red so WHITE may not be appropriate */ XSetForeground(display, tclock->gc, hour0->colour); } hour0->angle = NRAND(360) * PI_RAD; hour0->velocity = (NRAND(7) - 3) * PI_RAD; hour0->radius = tclock->radius / 5.0; tclock->max_radius = MAX( tclock->max_radius , hour0->radius ); hour0->num_point = 12; hour0->num_point1 = 16; if ( tclock->randomhour ) { int j; hour0->point_numbers = tclock->hexadecimal_clock + i * hour0->num_point1; if ( NRAND( 14 ) == 4 ) { for (j = 0; j < ( hour0->num_point1 / 4 ) - 1 ; j++) { hour0->point_numbers[ j * 4 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 1 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 2 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 3 ] = NRAND( 12 ) + 1; } hour0->point_numbers[ hour0->num_point1 / 4 ] = 1; hour0->point_numbers[ 1 + hour0->num_point1 / 4 ] = 1; hour0->point_numbers[ 2 + hour0->num_point1 / 4 ] = 1; hour0->point_numbers[ 3 + hour0->num_point1 / 4 ] = 1; } else { for (j = 0; j < hour0->num_point1 / 4 ; j++) { hour0->point_numbers[ j * 4 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 1 ] = hour0->point_numbers[ j * 4 ]; hour0->point_numbers[ j * 4 + 2 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 3 ] = NRAND( 12 ) + 1; } } } else hour0->point_numbers = original_clock[i+istart]; if ( NRAND( 100 ) >= tclock->fill ) hour0->draw = True; else hour0->draw = False; #ifdef NO_DBUF { 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 ) ); toneclock_drawhour(mi , hour0 , x0 , y0 ); } #endif } tclock->a_x = 0; tclock->a_y = 0; if ( !tclock->original && tclock->win_width > 20 ) { if ( tclock->radius < MIN( tclock->win_width , tclock->win_height) / 4 ) { if ( MI_IS_FULLRANDOM( mi ) ) { if ( NRAND(2) ) tclock->moving = True; } else { tclock->moving = move_clock; } if ( tclock->moving ) { tclock->a_x = (int) floor( ( tclock->win_width / 2 ) - 1.05 * ( tclock->radius + tclock->max_radius ) ); tclock->a_y = (int) floor( ( tclock->win_height / 2 ) - 1.05 * ( tclock->radius + tclock->max_radius ) ); tclock->vx = (NRAND(15) - 7) * PI_RAD; tclock->vy = (NRAND(15) - 7) * PI_RAD; } } } XFlush(display); XSetFunction(display, tclock->gc, GXcopy); }
ENTRYPOINT void init_flow (ModeInfo * mi) { flowstruct *sp; char *name; if (flows == NULL) { if ((flows = (flowstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (flowstruct))) == NULL) return; } sp = &flows[MI_SCREEN(mi)]; sp->count2 = 0; sp->taillen = MI_SIZE(mi); if (sp->taillen < -MINTRAIL) { /* Change by sqrt so it seems more variable */ sp->taillen = NRAND((int)sqrt((double) (-sp->taillen - MINTRAIL + 1))); sp->taillen = sp->taillen * sp->taillen + MINTRAIL; } else if (sp->taillen < MINTRAIL) { sp->taillen = MINTRAIL; } if(!rotatep && !ridep) rotatep = True; /* We need at least one viewpoint */ /* Start camera at Orbit or Bee */ if(rotatep) { sp->chaseto = ORBIT; } else { sp->chaseto = BEE; } sp->chasetime = 1; /* Go directly to target */ sp->lyap = 0; sp->yperiod = 0; sp->step2 = INITIALSTEP; /* Zero parameter set */ memset(sp->par2, 0, N_PARS * sizeof(dvector)); /* Set up standard examples */ switch (NRAND((periodicp) ? 5 : 3)) { case 0: /* x' = a(y - x) y' = x(b - z) - y z' = xy - cz */ name = "Lorentz"; sp->par2[Y].x = 10 + balance_rand(5*0); /* a */ sp->par2[X].x = - sp->par2[Y].x; /* -a */ sp->par2[X].y = 28 + balance_rand(5*0); /* b */ sp->par2[XZ].y = -1; sp->par2[Y].y = -1; sp->par2[XY].z = 1; sp->par2[Z].z = - 2 + balance_rand(1*0); /* -c */ break; case 1: /* x' = -(y + az) y' = x + by z' = c + z(x - 5.7) */ name = "Rossler"; sp->par2[Y].x = -1; sp->par2[Z].x = -2 + balance_rand(1); /* a */ sp->par2[X].y = 1; sp->par2[Y].y = 0.2 + balance_rand(0.1); /* b */ sp->par2[C].z = 0.2 + balance_rand(0.1); /* c */ sp->par2[XZ].z = 1; sp->par2[Z].z = -5.7; break; case 2: /* x' = -(y + az) y' = x + by - cz^2 z' = 0.2 + z(x - 5.7) */ name = "RosslerCone"; sp->par2[Y].x = -1; sp->par2[Z].x = -2; /* a */ sp->par2[X].y = 1; sp->par2[Y].y = 0.2; /* b */ sp->par2[ZZ].y = -0.331 + balance_rand(0.01); /* c */ sp->par2[C].z = 0.2; sp->par2[XZ].z = 1; sp->par2[Z].z = -5.7; break; case 3: /* x' = -z + b sin(y) y' = c z' = 0.7x + az(0.1 - x^2) */ name = "Birkhoff"; sp->par2[Z].x = -1; sp->par2[SINY].x = 0.35 + balance_rand(0.25); /* b */ sp->par2[C].y = 1.57; /* c */ sp->par2[X].z = 0.7; sp->par2[Z].z = 1 + balance_rand(0.5); /* a/10 */ sp->par2[XXZ].z = -10 * sp->par2[Z].z; /* -a */ sp->yperiod = 2 * M_PI; break; default: /* x' = -ax - z/2 - z^3/8 + b sin(y) y' = c z' = 2x */ name = "Duffing"; sp->par2[X].x = -0.2 + balance_rand(0.1); /* a */ sp->par2[Z].x = -0.5; sp->par2[ZZZ].x = -0.125; sp->par2[SINY].x = 27.0 + balance_rand(3.0); /* b */ sp->par2[C].y = 1.33; /* c */ sp->par2[X].z = 2; sp->yperiod = 2 * M_PI; break; } sp->range.x = 5; sp->range.z = 5; if(sp->yperiod > 0) { sp->ODE = Periodic; /* periodic flows show either uniform distribution or a snapshot on the 'time' axis */ sp->range.y = NRAND(2)? sp->yperiod : 0; } else { sp->range.y = 5; sp->ODE = Cubic; } /* Run discoverer to set up bounding box, etc. Lyapunov will probably be innaccurate, since we're only running it once, but we're using known strange attractors so it should be ok. */ discover(mi); if(MI_IS_VERBOSE(mi)) fprintf(stdout, "flow: Lyapunov exponent: %g, step: %g, size: %g (%s)\n", sp->lyap2, sp->step2, sp->size2, name); /* Install new params */ sp->lyap = sp->lyap2; sp->size = sp->size2; sp->mid = sp->mid2; sp->step = sp->step2; memcpy(sp->par, sp->par2, sizeof(sp->par2)); sp->count2 = 0; /* Reset search */ free_flow(sp); sp->beecount = MI_COUNT(mi); if (sp->beecount < 0) { /* random variations */ sp->beecount = NRAND(-sp->beecount) + 1; /* Minimum 1 */ } # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ dbufp = False; # endif if(dbufp) { /* Set up double buffer */ if (sp->buffer != None) XFreePixmap(MI_DISPLAY(mi), sp->buffer); sp->buffer = XCreatePixmap(MI_DISPLAY(mi), MI_WINDOW(mi), MI_WIDTH(mi), MI_HEIGHT(mi), MI_DEPTH(mi)); } else { sp->buffer = MI_WINDOW(mi); } /* no "NoExpose" events from XCopyArea wanted */ XSetGraphicsExposures(MI_DISPLAY(mi), MI_GC(mi), False); /* Make sure we're using 'thin' lines */ XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), 0, LineSolid, CapNotLast, JoinMiter); /* Clear the background (may be slow depending on user prefs). */ MI_CLEARWINDOW(mi); /* Allocate memory. */ if (sp->csegs == NULL) { allocate(sp->csegs, XSegment, (sp->beecount + BOX_L) * MI_NPIXELS(mi) * sp->taillen); allocate(sp->cnsegs, int, MI_NPIXELS(mi)); allocate(sp->old_segs, XSegment, sp->beecount * sp->taillen); allocate(sp->p, dvector, sp->beecount * sp->taillen); }
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); }
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); }
void init_tik_tak(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i, max_objects, size_object; tik_takstruct *tiktak; /* initialize */ if (tik_taks == NULL) { if ((tik_taks = (tik_takstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (tik_takstruct))) == NULL) return; } tiktak = &tik_taks[MI_SCREEN(mi)]; tiktak->mi = mi; if (tiktak->gc == None) { if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XColor color; #ifndef STANDALONE tiktak->fg = MI_FG_PIXEL(mi); tiktak->bg = MI_BG_PIXEL(mi); #endif tiktak->blackpixel = MI_BLACK_PIXEL(mi); tiktak->whitepixel = MI_WHITE_PIXEL(mi); if ((tiktak->cmap = XCreateColormap(display, window, MI_VISUAL(mi), AllocNone)) == None) { free_tik_tak(display, tiktak); return; } XSetWindowColormap(display, window, tiktak->cmap); (void) XParseColor(display, tiktak->cmap, "black", &color); (void) XAllocColor(display, tiktak->cmap, &color); MI_BLACK_PIXEL(mi) = color.pixel; (void) XParseColor(display, tiktak->cmap, "white", &color); (void) XAllocColor(display, tiktak->cmap, &color); MI_WHITE_PIXEL(mi) = color.pixel; #ifndef STANDALONE (void) XParseColor(display, tiktak->cmap, background, &color); (void) XAllocColor(display, tiktak->cmap, &color); MI_BG_PIXEL(mi) = color.pixel; (void) XParseColor(display, tiktak->cmap, foreground, &color); (void) XAllocColor(display, tiktak->cmap, &color); MI_FG_PIXEL(mi) = color.pixel; #endif tiktak->colors = (XColor *) NULL; tiktak->ncolors = 0; } if ((tiktak->gc = XCreateGC(display, MI_WINDOW(mi), (unsigned long) 0, (XGCValues *) NULL)) == None) { free_tik_tak(display, tiktak); return; } } /* Clear Display */ MI_CLEARWINDOW(mi); tiktak->painted = False; XSetFunction(display, tiktak->gc, GXxor); /*Set up tik_tak data */ tiktak->direction = (LRAND() & 1) ? 1 : -1; tiktak->win_width = MI_WIDTH(mi); tiktak->win_height = MI_HEIGHT(mi); tiktak->num_object = MI_COUNT(mi); tiktak->x0 = tiktak->win_width / 2; tiktak->y0 = tiktak->win_height / 2; max_objects = MI_COUNT(mi); if (tiktak->num_object == 0) { tiktak->num_object = DEF_NUM_OBJECT; max_objects = DEF_NUM_OBJECT; } else if (tiktak->num_object < 0) { max_objects = -tiktak->num_object; tiktak->num_object = NRAND(-tiktak->num_object) + 1; } if (tiktak->object == NULL) if ((tiktak->object = (tik_takobject *) calloc(max_objects, sizeof (tik_takobject))) == NULL) { free_tik_tak(display, tiktak); return; } size_object = MIN( tiktak->win_width , tiktak->win_height) / 3; if ( abs( MI_SIZE(mi) ) > size_object) { if ( MI_SIZE( mi ) < 0 ) { size_object = -size_object; } } else { size_object = MI_SIZE(mi); } if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { /* Set up colour map */ if (tiktak->colors != NULL) { if (tiktak->ncolors && !tiktak->no_colors) free_colors(display, tiktak->cmap, tiktak->colors, tiktak->ncolors); free(tiktak->colors); tiktak->colors = (XColor *) NULL; } tiktak->ncolors = MI_NCOLORS(mi); if (tiktak->ncolors < 2) tiktak->ncolors = 2; if (tiktak->ncolors <= 2) tiktak->mono_p = True; else tiktak->mono_p = False; if (tiktak->mono_p) tiktak->colors = (XColor *) NULL; else if ((tiktak->colors = (XColor *) malloc(sizeof (*tiktak->colors) * (tiktak->ncolors + 1))) == NULL) { free_tik_tak(display, tiktak); return; } tiktak->cycle_p = has_writable_cells(mi); if (tiktak->cycle_p) { if (MI_IS_FULLRANDOM(mi)) { if (!NRAND(8)) tiktak->cycle_p = False; else tiktak->cycle_p = True; } else { tiktak->cycle_p = cycle_p; } } if (!tiktak->mono_p) { if (!(LRAND() % 10)) make_random_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tiktak->cmap, tiktak->colors, &tiktak->ncolors, True, True, &tiktak->cycle_p); else if (!(LRAND() % 2)) make_uniform_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tiktak->cmap, tiktak->colors, &tiktak->ncolors, True, &tiktak->cycle_p); else make_smooth_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tiktak->cmap, tiktak->colors, &tiktak->ncolors, True, &tiktak->cycle_p); } XInstallColormap(display, tiktak->cmap); if (tiktak->ncolors < 2) { tiktak->ncolors = 2; tiktak->no_colors = True; } else tiktak->no_colors = False; if (tiktak->ncolors <= 2) tiktak->mono_p = True; if (tiktak->mono_p) tiktak->cycle_p = False; } for (i = 0; i < tiktak->num_object; i++) { tik_takobject *object0; object0 = &tiktak->object[i]; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (tiktak->ncolors > 2) object0->colour = NRAND(tiktak->ncolors - 2) + 2; else object0->colour = 1; /* Just in case */ XSetForeground(display, tiktak->gc, tiktak->colors[object0->colour].pixel); } else { if (MI_NPIXELS(mi) > 2) object0->colour = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); else object0->colour = 1; /*Xor'red so WHITE may not be appropriate */ XSetForeground(display, tiktak->gc, object0->colour); } object0->angle = NRAND(90) * PI_RAD; object0->angle1 = NRAND(90) * PI_RAD; object0->velocity_a = (NRAND(7) - 3) * PI_RAD; object0->velocity_a1 = (NRAND(7) - 3) * PI_RAD; if (size_object == 0) object0->size_ob = 9; else if (size_object > 0) object0->size_ob = size_object; else object0->size_ob = NRAND(-size_object) + 1; object0->size_ob++; object0->num_point = NRAND(6)+3; if (LRAND() & 1) object0->size_mult = 1.0; else { object0->num_point *= 2; object0->size_mult = 1.0 - ( 1.0 / (float) ((LRAND() & 1) + 2 ) ); } if (object0->xy != NULL) free(object0->xy); if ((object0->xy = (XPoint *) malloc(sizeof( XPoint ) * (2 * object0->num_point + 2))) == NULL) { free_tik_tak(display, tiktak); return; } if ((LRAND() & 1) || object0->size_ob < 10 ) { object0->inner = False; if ( object0->xy1 != NULL ) free( object0->xy1 ); object0->xy1 = (XPoint *) NULL; } else { object0->inner = True; object0->size_ob1 = object0->size_ob - NRAND( object0->size_ob / 5 ) - 1; object0->num_point1 = NRAND(6)+3; if (LRAND() & 1) object0->size_mult1 = 1.0; else { object0->num_point1 *= 2; object0->size_mult1 = 1.0 - ( 1.0 / (float) ((LRAND() & 1) + 2 ) ); } if (object0->xy1 != NULL) free(object0->xy1); if ((object0->xy1 = (XPoint *) malloc(sizeof( XPoint ) * (2 * object0->num_point1 + 2))) == NULL) { free_tik_tak(display, tiktak); return; } object0->size_mult1 = 1.0; } tik_tak_setupobject( mi , object0); tik_tak_reset_object( object0); tik_tak_drawobject(mi, object0 ); } XFlush(display); XSetFunction(display, tiktak->gc, GXcopy); }
ENTRYPOINT void init_worm (ModeInfo * mi) { wormstruct *wp; int size = MI_SIZE(mi); int i, j; if (worms == NULL) { if ((worms = (wormstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (wormstruct))) == NULL) return; } wp = &worms[MI_SCREEN(mi)]; if (MI_NPIXELS(mi) <= 2 || MI_WIN_IS_USE3D(mi)) wp->nc = 2; else wp->nc = MI_NPIXELS(mi); if (wp->nc > NUMCOLORS) wp->nc = NUMCOLORS; free_worms(wp); wp->nw = MI_BATCHCOUNT(mi); if (wp->nw < -MINWORMS) wp->nw = NRAND(-wp->nw - MINWORMS + 1) + MINWORMS; else if (wp->nw < MINWORMS) wp->nw = MINWORMS; if (!wp->worm) wp->worm = (wormstuff *) malloc(wp->nw * sizeof (wormstuff)); if (!wp->size) wp->size = (int *) malloc(NUMCOLORS * sizeof (int)); wp->maxsize = (REDRAWSTEP + 1) * wp->nw; /* / wp->nc + 1; */ if (!wp->rects) wp->rects = (XRectangle *) malloc(wp->maxsize * NUMCOLORS * sizeof (XRectangle)); if (!init_table) { init_table = 1; for (i = 0; i < SEGMENTS; i++) { sintab[i] = SINF(i * 2.0 * M_PI / SEGMENTS); costab[i] = COSF(i * 2.0 * M_PI / SEGMENTS); } } wp->xsize = MI_WIN_WIDTH(mi); wp->ysize = MI_WIN_HEIGHT(mi); wp->zsize = MAXZ - MINZ + 1; if (MI_NPIXELS(mi) > 2) wp->chromo = NRAND(MI_NPIXELS(mi)); if (size < -MINSIZE) wp->circsize = NRAND(-size - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) wp->circsize = MINSIZE; else wp->circsize = size; for (i = 0; i < wp->nc; i++) { for (j = 0; j < wp->maxsize; j++) { wp->rects[i * wp->maxsize + j].width = wp->circsize; wp->rects[i * wp->maxsize + j].height = wp->circsize; } } (void) memset((char *) wp->size, 0, wp->nc * sizeof (int)); wp->wormlength = (int) sqrt(wp->xsize + wp->ysize) * MI_CYCLES(mi) / 8; /* Fudge this to something reasonable */ for (i = 0; i < wp->nw; i++) { wp->worm[i].circ = (XPoint *) malloc(wp->wormlength * sizeof (XPoint)); wp->worm[i].diffcirc = (int *) malloc(wp->wormlength * sizeof (int)); for (j = 0; j < wp->wormlength; j++) { wp->worm[i].circ[j].x = wp->xsize / 2; wp->worm[i].circ[j].y = wp->ysize / 2; if (MI_WIN_IS_USE3D(mi)) wp->worm[i].diffcirc[j] = 0; } wp->worm[i].dir = NRAND(SEGMENTS); wp->worm[i].dir2 = NRAND(SEGMENTS); wp->worm[i].tail = 0; wp->worm[i].x = wp->xsize / 2; wp->worm[i].y = wp->ysize / 2; wp->worm[i].z = SCREENZ - MINZ; wp->worm[i].redrawing = 0; } if (MI_WIN_IS_INSTALL(mi) && MI_WIN_IS_USE3D(mi)) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_NONE_COLOR(mi)); XFillRectangle(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), 0, 0, wp->xsize, wp->ysize); } else XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi)); }
static Bool initlisa(ModeInfo * mi, lisas * loop) { lisacons *lc = &Lisa[MI_SCREEN(mi)]; lisafuncs **lf = loop->function; XPoint *lp; int phase, pctr, fctr, xctr, yctr, extra_points; double xprod, yprod, xsum, ysum; xMaxLines = (XMaxRequestSize(MI_DISPLAY(mi))-3)/2; /* printf("Got xMaxLines = %d\n", xMaxLines); */ loop->nsteps = MI_CYCLES(mi); if (loop->nsteps == 0) loop->nsteps = 1; if (MI_NPIXELS(mi) > 2) { loop->color = STARTCOLOR; loop->cstep = (loop->nsteps > MI_NPIXELS(mi)) ? loop->nsteps / MI_NPIXELS(mi) : 1; } else { loop->color = MI_WHITE_PIXEL(mi); loop->cstep = 0; } extra_points = loop->cstep - (loop->nsteps % loop->cstep); lc->maxcycles = (MAXCYCLES * loop->nsteps) - 1; loop->cstep = ( loop->nsteps > MI_NPIXELS(mi) ) ? loop->nsteps / MI_NPIXELS(mi) : 1; /* printf("Got cstep = %d\n", loop->cstep); */ loop->melting = 0; loop->nfuncs = 1; loop->pistep = 2.0 * M_PI / (double) loop->nsteps; loop->center.x = lc->width / 2; loop->center.y = lc->height / 2; loop->radius = (int) MI_SIZE(mi); CHECK_RADIUS(loop, lc); loop->dx = NRAND(XVMAX); loop->dy = NRAND(YVMAX); loop->dx++; loop->dy++; #if defined STARTFUNC lf[0] = &Function[STARTFUNC]; #else /* STARTFUNC */ lf[0] = &Function[NRAND(NUMSTDFUNCS)]; #endif /* STARTFUNC */ if ((lp = loop->lastpoint = (XPoint *) calloc(loop->nsteps+extra_points, sizeof (XPoint))) == NULL) { free_lisa(lc); return False; } phase = lc->loopcount % loop->nsteps; #if defined DEBUG printf( "nsteps = %d\tcstep = %d\tmrs = %d\textra_points = %d\n", loop->nsteps, loop->cstep, xMaxLines, extra_points ); PRINT_FUNC(lf[0]); #endif /* DEBUG */ for (pctr = 0; pctr < loop->nsteps; pctr++) { loop->phi = (double) (pctr - phase) * loop->pistep; loop->theta = (double) (pctr + phase) * loop->pistep; fctr = loop->nfuncs; xsum = ysum = 0.0; while (fctr--) { xprod = yprod = (double) loop->radius; xctr = lf[fctr]->nx; yctr = lf[fctr]->ny; while (xctr--) xprod *= sin(lf[fctr]->xcoeff[xctr] * loop->theta); while (yctr--) yprod *= sin(lf[fctr]->ycoeff[yctr] * loop->phi); xsum += xprod; ysum += yprod; } if (loop->nfuncs > 1) { xsum /= 2.0; ysum /= 2.0; } xsum += (double) loop->center.x; ysum += (double) loop->center.y; lp[pctr].x = (int) ceil(xsum); lp[pctr].y = (int) ceil(ysum); } /* this fills in the extra points, so we can use segment-drawing calls */ for (pctr = loop->nsteps; pctr < loop->nsteps + extra_points; pctr++) { lp[pctr].x=lp[pctr - loop->nsteps].x; lp[pctr].y=lp[pctr - loop->nsteps].y; } #if defined DRAWLINES loop->linewidth = LINEWIDTH; /* #### make this a resource */ if (loop->linewidth == 0) loop->linewidth = 1; if (loop->linewidth < 0) loop->linewidth = NRAND(-loop->linewidth) + 1; XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), loop->linewidth, LINESTYLE, LINECAP, LINEJOIN); #endif /* DRAWLINES */ if ( loop->cstep < xMaxLines ) { /* we can send each color segment in a single request * because the max request length is long enough * and because we have padded out the array to have extra elements * to support calls which would otherwise fall off the end*/ for (pctr = 0; pctr < loop->nsteps; pctr+=loop->cstep) { /* Set the color */ SET_COLOR(); #if defined DRAWLINES XDrawLines(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), &lp[pctr], loop->cstep, CoordModeOrigin ); #else /* DRAWLINES */ XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), &lp[pctr], loop->cstep, CoordModeOrigin ); #endif /* DRAWLINES */ } } else { /* do it one by one as before */ for (pctr = 0; pctr < loop->nsteps; pctr++ ) { SET_COLOR(); #if defined DRAWLINES XDrawLine(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), lp[pctr].x, lp[pctr].y, lp[pctr+1 % loop->nsteps].x, lp[pctr+1 % loop->nsteps].y); #else /* DRAWLINES */ XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), lp[pctr].x, lp[pctr].y); #endif /* DRAWLINES */ } } #if defined DRAWLINES XSetLineAttributes(MI_DISPLAY(mi), MI_GC(mi), 1, LINESTYLE, LINECAP, LINEJOIN); #endif /* DRAWLINES */ return True; }
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); }
void init_dragon(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int size = MI_SIZE(mi); dragonstruct *dp; if (dragons == NULL) { if ((dragons = (dragonstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (dragonstruct))) == NULL) return; } dp = &dragons[MI_SCREEN(mi)]; dp->generation = 0; dp->redrawing = 0; if (MI_NPIXELS(mi) <= 2) { if (dp->stippledGC == None) { XGCValues gcv; gcv.fill_style = FillOpaqueStippled; if ((dp->stippledGC = XCreateGC(display, window, GCFillStyle, &gcv)) == None) { free_dragon(display, dp); return; } } if (dp->graypix == None) { if ((dp->graypix = XCreateBitmapFromData(display, window, (char *) gray1_bits, gray1_width, gray1_height)) == None) { free_dragon(display, dp); return; } } } free_struct(dp); if (MI_NPIXELS(mi) > 2) dp->color = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); if ((dp->cellList = (CellList **) calloc(STATES, sizeof (CellList *))) == NULL) { free_dragon(display, dp); return; } if ((dp->ncells = (int *) calloc(STATES, sizeof (int))) == NULL) { free_dragon(display, dp); return; } dp->addlist = 0; dp->width = MI_WIDTH(mi); dp->height = MI_HEIGHT(mi); { int nccols, ncrows, i; if (dp->width < 8) dp->width = 8; if (dp->height < 8) dp->height = 8; if (size < -MINSIZE) dp->ys = NRAND(MIN(-size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)) - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) { if (!size) dp->ys = MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE); else dp->ys = MINSIZE; } else dp->ys = MIN(size, MAX(MINSIZE, MIN(dp->width, dp->height) / MINGRIDSIZE)); dp->xs = dp->ys; nccols = MAX(dp->width / dp->xs - 2, 2); ncrows = MAX(dp->height / dp->ys - 1, 4); dp->ncols = nccols / 2; dp->nrows = 2 * (ncrows / 4); dp->xb = (dp->width - dp->xs * nccols) / 2 + dp->xs / 2; dp->yb = (dp->height - dp->ys * (ncrows / 2) * 2) / 2 - dp->ys / 4; for (i = 0; i < 6; i++) { dp->hexagon[i].x = dp->xs * hexagonUnit[i].x; dp->hexagon[i].y = ((dp->ys + 1) * hexagonUnit[i].y / 2) * 4 / 3; } } MI_CLEARWINDOW(mi); if ((dp->oldcell = (unsigned char *) calloc(dp->ncols * dp->nrows, sizeof (unsigned char))) == NULL) { free_dragon(display, dp); return; } if (!SetSoup(mi)) { free_dragon(display, dp); return; } }
ENTRYPOINT void init_braid(ModeInfo * mi) { braidtype *braid; int used[MAXSTRANDS]; int i, count, comp, c; float min_length; if (braids == NULL) { if ((braids = (braidtype *) calloc(MI_NUM_SCREENS(mi), sizeof (braidtype))) == NULL) return; } braid = &braids[MI_SCREEN(mi)]; braid->center_x = MI_WIDTH(mi) / 2; braid->center_y = MI_HEIGHT(mi) / 2; braid->age = 0; /* jwz: go in the other direction sometimes. */ braid->color_direction = ((LRAND() & 1) ? 1 : -1); #ifndef STANDALONE MI_CLEARWINDOW(mi); #endif min_length = (braid->center_x > braid->center_y) ? braid->center_y : braid->center_x; braid->min_radius = min_length * 0.30; braid->max_radius = min_length * 0.90; if (MI_COUNT(mi) < MINSTRANDS) braid->nstrands = MINSTRANDS; else braid->nstrands = INTRAND(MINSTRANDS, MAX(MIN(MIN(MAXSTRANDS, MI_COUNT(mi)), (int) ((braid->max_radius - braid->min_radius) / 5.0)), MINSTRANDS)); braid->braidlength = INTRAND(MINLENGTH, MIN(MAXLENGTH, braid->nstrands * 6)); for (i = 0; i < braid->braidlength; i++) { braid->braidword[i] = INTRAND(1, braid->nstrands - 1) * (INTRAND(1, 2) * 2 - 3); if (i > 0) while (braid->braidword[i] == -braid->braidword[i - 1]) braid->braidword[i] = INTRAND(1, braid->nstrands - 1) * (INTRAND(1, 2) * 2 - 3); } while (braid->braidword[0] == -braid->braidword[braid->braidlength - 1]) braid->braidword[braid->braidlength - 1] = INTRAND(1, braid->nstrands - 1) * (INTRAND(1, 2) * 2 - 3); do { (void) memset((char *) used, 0, sizeof (used)); count = 0; for (i = 0; i < braid->braidlength; i++) used[ABS(braid->braidword[i])]++; for (i = 0; i < braid->nstrands; i++) count += (used[i] > 0) ? 1 : 0; if (count < braid->nstrands - 1) { braid->braidword[braid->braidlength] = INTRAND(1, braid->nstrands - 1) * (INTRAND(1, 2) * 2 - 3); while (braid->braidword[braid->braidlength] == -braid->braidword[braid->braidlength - 1] && braid->braidword[0] == -braid->braidword[braid->braidlength]) braid->braidword[braid->braidlength] = INTRAND(1, braid->nstrands - 1) * (INTRAND(1, 2) * 2 - 3); braid->braidlength++; } } while (count < braid->nstrands - 1 && braid->braidlength < MAXLENGTH); braid->startcolor = (MI_NPIXELS(mi) > 2) ? (float) NRAND(MI_NPIXELS(mi)) : 0.0; /* XSetLineAttributes (display, MI_GC(mi), 2, LineSolid, CapRound, JoinRound); */ (void) memset((char *) braid->components, 0, sizeof (braid->components)); c = 1; comp = 0; braid->components[0] = 1; do { i = comp; do { i = applyword(braid, i, 0); braid->components[i] = braid->components[comp]; } while (i != comp); count = 0; for (i = 0; i < braid->nstrands; i++) if (braid->components[i] == 0) count++; if (count > 0) { for (comp = 0; braid->components[comp] != 0; comp++); braid->components[comp] = ++c; } } while (count > 0); braid->linewidth = MI_SIZE(mi); if (braid->linewidth < 0) braid->linewidth = NRAND(-braid->linewidth) + 1; if (braid->linewidth * braid->linewidth * 8 > MIN(MI_WIDTH(mi), MI_HEIGHT(mi))) braid->linewidth = MIN(1, (int) sqrt((double) MIN(MI_WIDTH(mi), MI_HEIGHT(mi)) / 8)); for (i = 0; i < braid->nstrands; i++) if (!(braid->components[i] & 1)) braid->components[i] *= -1; }
static Bool startover(ModeInfo * mi) { unistruct *gp = &universes[MI_SCREEN(mi)]; int size = (int) MI_SIZE(mi); int i, j; /* more tmp */ double w1, w2; /* more tmp */ double d, v, w, h; /* yet more tmp */ gp->step = 0; if (MI_COUNT(mi) < -MINGALAXIES) free_galaxies(gp); gp->ngalaxies = MI_COUNT(mi); if (gp->ngalaxies < -MINGALAXIES) gp->ngalaxies = NRAND(-gp->ngalaxies - MINGALAXIES + 1) + MINGALAXIES; else if (gp->ngalaxies < MINGALAXIES) gp->ngalaxies = MINGALAXIES; if (gp->galaxies == NULL) if ((gp->galaxies = (Galaxy *) calloc(gp->ngalaxies, sizeof (Galaxy))) == NULL) { free_galaxy(MI_DISPLAY(mi), gp); return False; } for (i = 0; i < gp->ngalaxies; ++i) { Galaxy *gt = &gp->galaxies[i]; double sinw1, sinw2, cosw1, cosw2; if (MI_NPIXELS(mi) >= COLORS) do { gt->galcol = NRAND(COLORBASE) * COLORS; } while (gt->galcol + COLORBASE / 2 < GREEN + NOTGREEN && gt->galcol + COLORBASE / 2 > GREEN - NOTGREEN); else gt->galcol = 0; /* Galaxies still may have some green stars but are not all green. */ if (gt->stars != NULL) { free(gt->stars); gt->stars = (Star *) NULL; } gt->nstars = (NRAND(MAX_STARS / 2)) + MAX_STARS / 2; if ((gt->stars = (Star *) malloc(gt->nstars * sizeof (Star))) == NULL) { free_galaxy(MI_DISPLAY(mi), gp); return False; } w1 = 2.0 * M_PI * FLOATRAND; w2 = 2.0 * M_PI * FLOATRAND; sinw1 = SINF(w1); sinw2 = SINF(w2); cosw1 = COSF(w1); cosw2 = COSF(w2); gp->mat[0][0] = cosw2; gp->mat[0][1] = -sinw1 * sinw2; gp->mat[0][2] = cosw1 * sinw2; gp->mat[1][0] = 0.0; gp->mat[1][1] = cosw1; gp->mat[1][2] = sinw1; gp->mat[2][0] = -sinw2; gp->mat[2][1] = -sinw1 * cosw2; gp->mat[2][2] = cosw1 * cosw2; gt->vel[0] = FLOATRAND * 2.0 - 1.0; gt->vel[1] = FLOATRAND * 2.0 - 1.0; gt->vel[2] = FLOATRAND * 2.0 - 1.0; gt->pos[0] = -gt->vel[0] * DELTAT * gp->f_hititerations + FLOATRAND - 0.5; gt->pos[1] = -gt->vel[1] * DELTAT * gp->f_hititerations + FLOATRAND - 0.5; gt->pos[2] = (-gt->vel[2] * DELTAT * gp->f_hititerations + FLOATRAND - 0.5) + Z_OFFSET; gt->mass = (int) (FLOATRAND * 1000.0) + 1; gp->size = GALAXYRANGESIZE * FLOATRAND + GALAXYMINSIZE; for (j = 0; j < gt->nstars; ++j) { Star *st = >->stars[j]; double sinw, cosw; w = 2.0 * M_PI * FLOATRAND; sinw = SINF(w); cosw = COSF(w); d = FLOATRAND * gp->size; h = FLOATRAND * exp(-2.0 * (d / gp->size)) / 5.0 * gp->size; if (FLOATRAND < 0.5) h = -h; st->pos[0] = gp->mat[0][0] * d * cosw + gp->mat[1][0] * d * sinw + gp->mat[2][0] * h + gt->pos[0]; st->pos[1] = gp->mat[0][1] * d * cosw + gp->mat[1][1] * d * sinw + gp->mat[2][1] * h + gt->pos[1]; st->pos[2] = gp->mat[0][2] * d * cosw + gp->mat[1][2] * d * sinw + gp->mat[2][2] * h + gt->pos[2]; v = sqrt(gt->mass * QCONS / sqrt(d * d + h * h)); st->vel[0] = -gp->mat[0][0] * v * sinw + gp->mat[1][0] * v * cosw + gt->vel[0]; st->vel[1] = -gp->mat[0][1] * v * sinw + gp->mat[1][1] * v * cosw + gt->vel[1]; st->vel[2] = -gp->mat[0][2] * v * sinw + gp->mat[1][2] * v * cosw + gt->vel[2]; st->vel[0] *= DELTAT; st->vel[1] *= DELTAT; st->vel[2] *= DELTAT; st->px = 0; st->py = 0; if (size < -MINSIZE) st->size = NRAND(-size - MINSIZE + 1) + MINSIZE; else if (size < MINSIZE) st->size = MINSIZE; else st->size = size; st->Z_size = st->size; } } MI_CLEARWINDOW(mi); #if 0 (void) printf("ngalaxies=%d, f_hititerations=%d\n", gp->ngalaxies, gp->f_hititerations); (void) printf("f_deltat=%g\n", DELTAT); (void) printf("Screen: "); (void) printf("%dx%d pixel (%d-%d, %d-%d)\n", (gp->clip.right - gp->clip.left), (gp->clip.bottom - gp->clip.top), gp->clip.left, gp->clip.right, gp->clip.top, gp->clip.bottom); #endif return True; }