static void drawcell(ModeInfo * mi, int col, int row, unsigned char color) { antfarmstruct *ap = &antfarms[MI_SCREEN(mi)]; GC gc; if (!color) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi)); gc = MI_GC(mi); } else if (MI_NPIXELS(mi) > 2) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, ap->colors[color - 1])); gc = MI_GC(mi); } else { XGCValues gcv; gcv.stipple = ap->pixmaps[color - 1]; gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); XChangeGC(MI_DISPLAY(mi), ap->stippledGC, GCStipple | GCForeground | GCBackground, &gcv); gc = ap->stippledGC; } fillcell(mi, gc, col, row); }
static Bool draw_state(ModeInfo * mi, int state) { dragonstruct *dp = &dragons[MI_SCREEN(mi)]; Display *display = MI_DISPLAY(mi); GC gc; CellList *current; if (!state) { XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi)); gc = MI_GC(mi); } else if (state == 1) { XSetForeground(display, MI_GC(mi), MI_BLACK_PIXEL(mi)); gc = MI_GC(mi); } else if (MI_NPIXELS(mi) > 2) { XSetForeground(display, MI_GC(mi), dp->color); gc = MI_GC(mi); } else { XGCValues gcv; gcv.stipple = dp->graypix; gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); XChangeGC(display, dp->stippledGC, GCStipple | GCForeground | GCBackground, &gcv); gc = dp->stippledGC; } { /* Draw right away, slow */ current = dp->cellList[state]; while (current) { int col, row, ccol, crow; col = current->pt.x; row = current->pt.y; ccol = 2 * col + !(row & 1), crow = 2 * row; if (dp->vertical) { dp->hexagon[0].x = dp->xb + ccol * dp->xs; dp->hexagon[0].y = dp->yb + crow * dp->ys; } else { dp->hexagon[0].y = dp->xb + ccol * dp->xs; dp->hexagon[0].x = dp->yb + crow * dp->ys; } if (dp->xs == 1 && dp->ys == 1) XDrawPoint(display, MI_WINDOW(mi), gc, dp->hexagon[0].x, dp->hexagon[0].y); else XFillPolygon(display, MI_WINDOW(mi), gc, dp->hexagon, 6, Convex, CoordModePrevious); current = current->next; } } XFlush(MI_DISPLAY(mi)); return True; }
static void drawlissie(ModeInfo * mi, lissiestruct * lissie) { Display *display = MI_DISPLAY(mi); GC gc = MI_GC(mi); lissstruct *lp = &lisses[MI_SCREEN(mi)]; int p = (++lissie->pos) % MAXLISSIELEN; int oldp = (lissie->pos - lissie->len + MAXLISSIELEN) % MAXLISSIELEN; /* Let time go by ... */ lissie->tx += lissie->dtx; lissie->ty += lissie->dty; if (lissie->tx > 2 * M_PI) lissie->tx -= 2 * M_PI; if (lissie->ty > 2 * M_PI) lissie->ty -= 2 * M_PI; /* vary both (x/y) speeds by max. 1% */ lissie->dtx *= FLOATRAND(0.99, 1.01); lissie->dty *= FLOATRAND(0.99, 1.01); if (lissie->dtx < MINDT) lissie->dtx = MINDT; else if (lissie->dtx > MAXDT) lissie->dtx = MAXDT; if (lissie->dty < MINDT) lissie->dty = MINDT; else if (lissie->dty > MAXDT) lissie->dty = MAXDT; lissie->loc[p].x = lissie->xi + (int) (sin(lissie->tx) * lissie->rx); lissie->loc[p].y = lissie->yi + (int) (sin(lissie->ty) * lissie->ry); /* Mask */ XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); Lissie(oldp); /* Redraw */ if (MI_NPIXELS(mi) > 2) { XSetForeground(display, gc, MI_PIXEL(mi, lissie->color)); if (++lissie->color >= (unsigned) MI_NPIXELS(mi)) lissie->color = 0; } else XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); Lissie(p); if (lissie->redrawing) { int i; lissie->redrawpos++; /* This compensates for the changed p since the last callback. */ for (i = 0; i < REDRAWSTEP; i++) { Lissie((p - lissie->redrawpos + MAXLISSIELEN) % MAXLISSIELEN); if (++(lissie->redrawpos) >= lissie->len) { lissie->redrawing = 0; break; } } } }
static void initialize_transparency_colormap (Display *dpy, Colormap cmap, int nplanes, unsigned long base_pixel, unsigned long *plane_masks, XColor *colors, Bool additive_p , ModeInfo* mi ) { int i; int total_colors = i_exp (2, nplanes); XColor *all_colors = (XColor *) calloc (total_colors, sizeof (XColor)); for (i = 0; i < nplanes; i++) colors[i].pixel = base_pixel | plane_masks [i]; permute_colors (colors, all_colors, nplanes, plane_masks, additive_p); /* clone the default background of the window into our "base" pixel */ all_colors [total_colors - 1].pixel = MI_BLACK_PIXEL( mi ); XQueryColor (dpy, cmap, &all_colors [total_colors - 1]); all_colors [total_colors - 1].pixel = base_pixel; for (i = 0; i < total_colors; i++) all_colors[i].flags = DoRed|DoGreen|DoBlue; XStoreColors (dpy, cmap, all_colors, total_colors); XFree ((XPointer) all_colors); }
void reserveColors(ModeInfo * mi, Colormap cmap, unsigned long *black) { Display *display = MI_DISPLAY(mi); XColor blackcolor, whitecolor; blackcolor.flags = DoRed | DoGreen | DoBlue; blackcolor.pixel = MI_BLACK_PIXEL(mi); blackcolor.red = 0; blackcolor.green = 0; blackcolor.blue = 0; whitecolor.flags = DoRed | DoGreen | DoBlue; whitecolor.pixel = MI_WHITE_PIXEL(mi); whitecolor.red = 0xFFFF; whitecolor.green = 0xFFFF; whitecolor.blue = 0xFFFF; /* If they fail what should I do? */ (void) XAllocColor(display, cmap, &blackcolor); (void) XAllocColor(display, cmap, &whitecolor); *black = blackcolor.pixel; #if 0 { XColor bgcolor, fgcolor; bgcolor.pixel = MI_BG_PIXEL(mi); fgcolor.pixel = MI_FG_PIXEL(mi); XQueryColor(display, cmap, &bgcolor); XQueryColor(display, cmap, &fgcolor); (void) XAllocColor(display, cmap, &bgcolor); (void) XAllocColor(display, cmap, &fgcolor); } #endif }
static void free_mandelbrot(Display *display, mandelstruct *mp) { ModeInfo *mi = mp->mi; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { MI_WHITE_PIXEL(mi) = mp->whitepixel; MI_BLACK_PIXEL(mi) = mp->blackpixel; #ifndef STANDALONE MI_FG_PIXEL(mi) = mp->fg; MI_BG_PIXEL(mi) = mp->bg; #endif if (mp->colors != NULL) { if (mp->ncolors && !mp->no_colors) free_colors(display, mp->cmap, mp->colors, mp->ncolors); free(mp->colors); mp->colors = (XColor *) NULL; } if (mp->cmap != None) { XFreeColormap(display, mp->cmap); mp->cmap = None; } } if (mp->gc != None) { XFreeGC(display, mp->gc); mp->gc = None; } }
static void draw_planet(ModeInfo * mi, planetstruct * planet) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); gravstruct *gp = &gravs[MI_SCREEN(mi)]; double D; /* A distance variable to work with */ register unsigned char cmpt; D = POS(X) * POS(X) + POS(Y) * POS(Y) + POS(Z) * POS(Z); if (D < COLLIDE) D = COLLIDE; D = sqrt(D); D = D * D * D; for (cmpt = X; cmpt < DIMENSIONS; cmpt++) { ACC(cmpt) = POS(cmpt) * GRAV / D; if (decay) { if (ACC(cmpt) > MaxA) ACC(cmpt) = MaxA; else if (ACC(cmpt) < -MaxA) ACC(cmpt) = -MaxA; VEL(cmpt) = VEL(cmpt) + ACC(cmpt); VEL(cmpt) *= DAMP; } else { /* update velocity */ VEL(cmpt) = VEL(cmpt) + ACC(cmpt); } /* update position */ POS(cmpt) = POS(cmpt) + VEL(cmpt); } gp->x = planet->xi; gp->y = planet->yi; if (POS(Z) > -ALMOST) { planet->xi = (int) ((double) gp->width * (HALF + POS(X) / (POS(Z) + DIST))); planet->yi = (int) ((double) gp->height * (HALF + POS(Y) / (POS(Z) + DIST))); } else planet->xi = planet->yi = -1; /* Mask */ XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); Planet(gp->x, gp->y); if (trail) { XSetForeground(display, gc, planet->colors); XDrawPoint(display, MI_WINDOW(mi), gc, gp->x, gp->y); } /* Move */ gp->x = planet->xi; gp->y = planet->yi; planet->ri = RADIUS; /* Redraw */ XSetForeground(display, gc, planet->colors); Planet(gp->x, gp->y); }
static void drawcell(ModeInfo * mi, int col, int row, unsigned char state) { dragonstruct *dp = &dragons[MI_SCREEN(mi)]; Display *display = MI_DISPLAY(mi); GC gc; if (!state) { XSetForeground(display, MI_GC(mi), MI_WHITE_PIXEL(mi)); gc = MI_GC(mi); } else if (state == 1) { XSetForeground(display, MI_GC(mi), MI_BLACK_PIXEL(mi)); gc = MI_GC(mi); } else if (MI_NPIXELS(mi) > 2) { XSetForeground(display, MI_GC(mi), dp->color); gc = MI_GC(mi); } else { XGCValues gcv; gcv.stipple = dp->graypix; gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); XChangeGC(display, dp->stippledGC, GCStipple | GCForeground | GCBackground, &gcv); gc = dp->stippledGC; } { int ccol = 2 * col + !(row & 1), crow = 2 * row; if (dp->vertical) { dp->hexagon[0].x = dp->xb + ccol * dp->xs; dp->hexagon[0].y = dp->yb + crow * dp->ys; } else { dp->hexagon[0].y = dp->xb + ccol * dp->xs; dp->hexagon[0].x = dp->yb + crow * dp->ys; } if (dp->xs == 1 && dp->ys == 1) XDrawPoint(display, MI_WINDOW(mi), gc, dp->hexagon[0].x, dp->hexagon[0].y); else XFillPolygon(display, MI_WINDOW(mi), gc, dp->hexagon, 6, Convex, CoordModePrevious); } }
ENTRYPOINT void draw_grav(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); register unsigned char ball; gravstruct *gp; if (gravs == NULL) return; gp = &gravs[MI_SCREEN(mi)]; if (gp->planets == NULL) return; if (!MI_IS_DRAWN(mi)) { for (ball = 0; ball < (unsigned char) gp->nplanets; ball++) { planetstruct *planet = &gp->planets[ball]; /* Draw planets */ Planet(planet->xi, planet->yi); } /* Draw centrepoint */ XDrawArc(display, MI_WINDOW(mi), gc, gp->width / 2 - gp->sr / 2, gp->height / 2 - gp->sr / 2, gp->sr, gp->sr, 0, 23040); } MI_IS_DRAWN(mi) = True; /* Mask centrepoint */ XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XDrawArc(display, window, gc, gp->width / 2 - gp->sr / 2, gp->height / 2 - gp->sr / 2, gp->sr, gp->sr, 0, 23040); /* Resize centrepoint */ switch (NRAND(4)) { case 0: if (gp->sr < (int) STARRADIUS) gp->sr++; break; case 1: if (gp->sr > 2) gp->sr--; } /* Draw centrepoint */ XSetForeground(display, gc, gp->starcolor); XDrawArc(display, window, gc, gp->width / 2 - gp->sr / 2, gp->height / 2 - gp->sr / 2, gp->sr, gp->sr, 0, 23040); for (ball = 0; ball < (unsigned char) gp->nplanets; ball++) draw_planet(mi, &gp->planets[ball]); }
ENTRYPOINT void draw_fadeplot (ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); int i, j, temp; fadeplotstruct *fp; if (fadeplots == NULL) return; fp = &fadeplots[MI_SCREEN(mi)]; if (fp->stab == NULL) return; MI_IS_DRAWN(mi) = True; XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XDrawPoints(display, window, gc, fp->pts, fp->maxpts, CoordModeOrigin); if (MI_NPIXELS(mi) > 2) { XSetForeground(display, gc, MI_PIXEL(mi, fp->pix)); if (++fp->pix >= MI_NPIXELS(mi)) fp->pix = 0; } else XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); temp = 0; for (j = 0; j < fp->nbstep; j++) { for (i = 0; i < fp->maxpts / fp->nbstep; i++) { fp->pts[temp].x = fp->stab[(fp->st.x + fp->speed.x * j + i * fp->step.x) % fp->angles] * fp->factor.x + fp->width / 2 - fp->min; fp->pts[temp].y = fp->stab[(fp->st.y + fp->speed.y * j + i * fp->step.y) % fp->angles] * fp->factor.y + fp->height / 2 - fp->min; temp++; } } XDrawPoints(display, window, gc, fp->pts, temp, CoordModeOrigin); fp->st.x = (fp->st.x + fp->speed.x) % fp->angles; fp->st.y = (fp->st.y + fp->speed.y) % fp->angles; fp->temps++; if ((fp->temps % (fp->angles / 2)) == 0) { fp->temps = fp->temps % fp->angles * 5; if ((fp->temps % (fp->angles)) == 0) fp->speed.y = (fp->speed.y + 1) % 30 + 1; if ((fp->temps % (fp->angles * 2)) == 0) fp->speed.x = (fp->speed.x) % 20; if ((fp->temps % (fp->angles * 3)) == 0) fp->step.y = (fp->step.y + 1) % 2 + 1; MI_CLEARWINDOW(mi); } }
static void unpaint_fly(ModeInfo * mi, Fly * f) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); if (MI_IS_ICONIC(mi)) { XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillArc(display, window, gc, f->oldx, f->oldy, f->width, f->height, 90 * 64, 360 * 64); } else { XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); #ifdef FLASH XFillRectangle(display, window, gc, f->oldx, f->oldy, f->width, f->height); #else ERASE_IMAGE(display, window, gc, f->x, f->y, f->oldx, f->oldy, f->width, f->height); #endif } }
static void drawtruchet(ModeInfo * mi, int col, int row, unsigned char color, unsigned char truchetstate) { antfarmstruct *ap = &antfarms[MI_SCREEN(mi)]; if (!color) XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_WHITE_PIXEL(mi)); else if (MI_NPIXELS(mi) > 2 || color > ap->ncolors / 2) XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi)); else XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_WHITE_PIXEL(mi)); truchetcell(mi, col, row, truchetstate); }
static void free_tik_tak(Display *display, tik_takstruct *tiktak) { ModeInfo *mi = tiktak->mi; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { MI_WHITE_PIXEL(mi) = tiktak->whitepixel; MI_BLACK_PIXEL(mi) = tiktak->blackpixel; #ifndef STANDALONE MI_FG_PIXEL(mi) = tiktak->fg; MI_BG_PIXEL(mi) = tiktak->bg; #endif 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; } if (tiktak->cmap != None) { XFreeColormap(display, tiktak->cmap); tiktak->cmap = None; } } if (tiktak->gc != None) { XFreeGC(display, tiktak->gc); tiktak->gc = None; } if (tiktak->object != NULL) { int i; for (i = 0; i < tiktak->num_object; i++) { tik_takobject *object0; object0 = &tiktak->object[i]; if (object0->xy1 != NULL) free(object0->xy1); if (object0->xy != NULL) free(object0->xy); } free(tiktak->object); tiktak->object = (tik_takobject *) NULL; } }
/* Checks for death of any ghosts/pacman and updates. It also makes a new level if all ghosts are dead or all dots are eaten. */ static void check_death(ModeInfo * mi, pacmangamestruct *pp) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); unsigned int ghost; int alldead; alldead = 1; for (ghost = 0; ghost < pp->nghosts; ghost++) { if (pp->ghosts[ghost].dead == True) continue; if ((pp->ghosts[ghost].nextrow == NOWHERE && pp->ghosts[ghost].nextcol == NOWHERE)) { alldead = 0; continue; } if (((pp->ghosts[ghost].nextrow == pp->pacman.nextrow) && (pp->ghosts[ghost].nextcol == pp->pacman.nextcol)) || ((pp->ghosts[ghost].nextrow == pp->pacman.row) && (pp->ghosts[ghost].nextcol == pp->pacman.col) && (pp->ghosts[ghost].row == pp->pacman.nextrow) && (pp->ghosts[ghost].col == pp->pacman.nextcol))) { pp->ghosts[ghost].dead = 1; XSetForeground(display, pp->stippledGC, MI_BLACK_PIXEL(mi)); XFillRectangle(display, window, pp->stippledGC, pp->ghosts[ghost].cf, pp->ghosts[ghost].rf, pp->spritexs, pp->spriteys); } else alldead = 0; } if (alldead == 1 || pp->dotsleft == 0) repopulate(mi); }
static Bool initLogo(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); imagestruct *ip = &ims[MI_SCREEN(mi)]; if (ip->logo == None) { getImage(mi, &ip->logo, IMAGE_WIDTH, IMAGE_HEIGHT, IMAGE_BITS, #ifdef HAVE_XPM DEFAULT_XPM, IMAGE_NAME, #endif &ip->graphics_format, &ip->cmap, &ip->black); if (ip->logo == None) { free_image(display, ip); return False; } ip->pixw = ip->logo->width; ip->pixh = ip->logo->height; } #ifndef STANDALONE if (ip->cmap != None) { setColormap(display, window, ip->cmap, MI_IS_INWINDOW(mi)); if (ip->bgGC == None) { XGCValues xgcv; xgcv.background = ip->black; if ((ip->bgGC = XCreateGC(display, window, GCBackground, &xgcv)) == None) { free_image(display, ip); return False; } } } else #endif /* STANDALONE */ { ip->black = MI_BLACK_PIXEL(mi); ip->bgGC = MI_GC(mi); } return True; }
static void drawCell(ModeInfo * mi, int col, int row, unsigned char state) { circuitstruct *wp = &circuits[MI_SCREEN(mi)]; GC gc; if (MI_NPIXELS(mi) > 2) { gc = MI_GC(mi); XSetForeground(MI_DISPLAY(mi), gc, MI_PIXEL(mi, wp->colors[state])); } else { XGCValues gcv; gcv.stipple = wp->pixmaps[state]; gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); XChangeGC(MI_DISPLAY(mi), wp->stippledGC, GCStipple | GCForeground | GCBackground, &gcv); gc = wp->stippledGC; } fillcell(mi, gc, col, row); }
static void free_toneclock(Display *display, toneclockstruct *tclock) { ModeInfo *mi = tclock->mi; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { MI_WHITE_PIXEL(mi) = tclock->whitepixel; MI_BLACK_PIXEL(mi) = tclock->blackpixel; #ifndef STANDALONE MI_FG_PIXEL(mi) = tclock->fg; MI_BG_PIXEL(mi) = tclock->bg; #endif 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; } if (tclock->cmap != None) { XFreeColormap(display, tclock->cmap); tclock->cmap = None; } } if (tclock->gc != None) { XFreeGC(display, tclock->gc); tclock->gc = None; } free_hour(tclock); #ifndef NO_DBUF if (tclock->dbuf != None) { XFreePixmap(display, tclock->dbuf); tclock->dbuf = None; } if (tclock->dbuf_gc != None) { XFreeGC(display, tclock->dbuf_gc); tclock->dbuf_gc = None; } #endif }
static void drawCell_notused(ModeInfo * mi, int col, int row, unsigned char state) { circuitstruct *wp = &circuits[MI_SCREEN(mi)]; XGCValues gcv; GC gc; if (MI_NPIXELS(mi) > 2) { gc = MI_GC(mi); XSetForeground(MI_DISPLAY(mi), gc, MI_PIXEL(mi, wp->colors[state])); } else { gcv.stipple = wp->pixmaps[state]; gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); XChangeGC(MI_DISPLAY(mi), wp->stippledGC, GCStipple | GCForeground | GCBackground, &gcv); gc = wp->stippledGC; } XFillRectangle(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), wp->xb + wp->xs * col, wp->yb + wp->ys * row, wp->xs - (wp->xs > 3), wp->ys - (wp->ys > 3)); }
static Bool init_stuff(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); puzzlestruct *pp = &puzzles[MI_SCREEN(mi)]; if (pp->logo == None) getImage(mi, &pp->logo, PUZZLE_WIDTH, PUZZLE_HEIGHT, PUZZLE_BITS, #ifdef HAVE_XPM DEFAULT_XPM, PUZZLE_NAME, #endif &pp->graphics_format, &pp->cmap, &pp->black); if (pp->logo == None) { free_puzzle(display, pp); return False; } #ifndef STANDALONE if (pp->cmap != None) { setColormap(display, window, pp->cmap, MI_IS_INWINDOW(mi)); if (pp->backGC == None) { XGCValues xgcv; xgcv.background = pp->black; if ((pp->backGC = XCreateGC(display, window, GCBackground, &xgcv)) == None) { free_puzzle(display, pp); return False; } } } else #endif /* STANDALONE */ { pp->black = MI_BLACK_PIXEL(mi); pp->backGC = MI_GC(mi); } return True; }
static Bool init_stuff(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); life1dstruct *lp = &life1ds[MI_SCREEN(mi)]; if (lp->logo == None) { getImage(mi, &lp->logo, CELL_WIDTH, CELL_HEIGHT, CELL_BITS, #ifdef HAVE_XPM DEFAULT_XPM, CELL_NAME, #endif &lp->graphics_format, &lp->cmap, &lp->black); if (lp->logo == None) { return False; } } #ifndef STANDALONE if (lp->cmap != None) { setColormap(display, window, lp->cmap, MI_IS_INWINDOW(mi)); if (lp->backGC == None) { XGCValues xgcv; xgcv.background = lp->black; if ((lp->backGC = XCreateGC(display, window, GCBackground, &xgcv)) == None) { return False; } } } else #endif /* STANDALONE */ { lp->black = MI_BLACK_PIXEL(mi); lp->backGC = MI_GC(mi); } return True; }
static void free_swirl(Display *display, swirlstruct *sp) { ModeInfo *mi = sp->mi; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { MI_WHITE_PIXEL(mi) = sp->whitepixel; MI_BLACK_PIXEL(mi) = sp->blackpixel; #ifndef STANDALONE MI_FG_PIXEL(mi) = sp->fg; MI_BG_PIXEL(mi) = sp->bg; #endif if (sp->colors != NULL) { if (sp->ncolors && !sp->no_colors) free_colors(display, sp->cmap, sp->colors, sp->ncolors); free(sp->colors); sp->colors = (XColor *) NULL; } if (sp->cmap != None) { XFreeColormap(display, sp->cmap); sp->cmap = None; } } if (sp->gc != None) { XFreeGC(display, sp->gc); sp->gc = None; } if (sp->ximage != None) { (void) XDestroyImage(sp->ximage); sp->ximage = None; } if (sp->knots != NULL) { free(sp->knots); sp->knots = (KNOT_P) NULL; } }
static Bool NumberScreen(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); puzzlestruct *pp = &puzzles[MI_SCREEN(mi)]; if (mode_font == None) mode_font = getFont(display); if (!pp->done) { XGCValues gcv; pp->done = 1; gcv.font = mode_font->fid; gcv.graphics_exposures = False; gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); if ((pp->gc = XCreateGC(display, window, GCForeground | GCBackground | GCGraphicsExposures | GCFont, &gcv)) == None) { free_puzzle(display, pp); return False; } pp->ascent = mode_font->ascent; pp->fontHeight = font_height(mode_font); pp->fontWidth = font_width(mode_font, '5'); } XSetForeground(display, pp->gc, MI_WHITE_PIXEL(mi)); { XPoint pos, letter; int count = 1, digitOffset = 1, temp, letterOffset; int i, j, mult = pp->count.x * pp->count.y; char buf[16]; letter.x = pp->boxsize.x / 2 - 3; letter.y = pp->boxsize.y / 2 + pp->ascent / 2 - 1; letterOffset = pp->fontWidth / 2; pos.y = 0; for (j = 0; j < pp->count.y; j++) { pos.x = 0; for (i = 0; i < pp->count.x; i++) { if (count < mult) { if (pp->boxsize.x > 2 * pp->fontWidth && pp->boxsize.y > pp->fontHeight) { (void) sprintf(buf, "%d", count); (void) XDrawString(display, window, pp->gc, pos.x + letter.x - letterOffset * digitOffset + pp->randompos.x, pos.y + letter.y + pp->randompos.y, buf, digitOffset); } XDrawRectangle(display, window, pp->gc, pos.x + 1 + pp->randompos.x, pos.y + 1 + pp->randompos.y, pp->boxsize.x - 3, pp->boxsize.y - 3); count++; digitOffset = 0; temp = count; while (temp >= 1) { temp /= 10; digitOffset++; } } pos.x += pp->boxsize.x; } pos.y += pp->boxsize.y; } } return True; }
void draw_mandelbrot(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int h; complex c; double demrange; mandelstruct *mp; if (mandels == NULL) return; mp = &mandels[MI_SCREEN(mi)]; MI_IS_DRAWN(mi) = True; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (mp->mono_p) { XSetForeground(display, mp->gc, mp->cur_color); } else { mp->cur_color = (mp->cur_color + 1) % mp->ncolors; XSetForeground(display, mp->gc, mp->colors[mp->cur_color].pixel); } } else { if (MI_NPIXELS(mi) > 2) XSetForeground(display, mp->gc, MI_PIXEL(mi, mp->cur_color)); else if (mp->cur_color) XSetForeground(display, mp->gc, MI_BLACK_PIXEL(mi)); else XSetForeground(display, mp->gc, MI_WHITE_PIXEL(mi)); if (++mp->cur_color >= (unsigned int) MI_NPIXELS(mi)) mp->cur_color = 0; } /* Rotate colours */ if (mp->cycle_p) { rotate_colors(display, mp->cmap, mp->colors, mp->ncolors, mp->direction); if (!(LRAND() % 1000)) mp->direction = -mp->direction; } /* so we iterate columns beyond the width of the physical screen, so that ** we just wait around and show what we've done */ if ((!mp->backwards && (mp->column >= 3 * mp->screen_width)) || (mp->backwards && (mp->column < -2 * mp->screen_width))) { /* reset to left edge of screen, bump power */ mp->backwards = (Bool) (LRAND() & 1); if (mp->backwards) mp->column = mp->screen_width - 1; else mp->column = 0; mp->power = NRAND(3) + MINPOWER; /* select a new region! */ Select(&mp->extreme_ul,&mp->extreme_lr, mp->screen_width,mp->screen_height, (int) mp->power,mp->reptop, mp->pow, mp->sin, &mp->ul,&mp->lr); } else if (mp->column >= mp->screen_width || mp->column < 0) { /* delay a while */ if (mp->backwards) mp->column--; else mp->column++; mp->counter++; return; } /* demrange is used to give some idea of scale */ demrange = mp->dem ? fabs(mp->ul.real - mp->lr.real) / 2 : 0; for (h = 0; h < mp->screen_height; h++) { unsigned int color; int result; /* c.real = 1.3 - (double) mp->column / mp->screen_width * 3.4; */ /* c.imag = -1.6 + (double) h / mp->screen_height * 3.2; */ c.real = mp->ul.real + (mp->ul.real-mp->lr.real)*(((double)(mp->column))/mp->screen_width); c.imag = mp->ul.imag + (mp->ul.imag - mp->lr.imag)*(((double) h) / mp->screen_height); result = reps(c, mp->power, mp->reptop, mp->binary, mp->interior, demrange, mp->pow, mp->sin); if (result < 0 || result >= mp->reptop) XSetForeground(display, mp->gc, MI_BLACK_PIXEL(mi)); else { color=(unsigned int) ((MI_NPIXELS(mi) * (float)result) / mp->reptop); XSetForeground(display, mp->gc, MI_PIXEL(mi, color)); } /* we no longer have vertical symmetry - so we compute all points ** and don't draw with redundancy */ XDrawPoint(display, window, mp->gc, mp->column, h); } if (mp->backwards) mp->column--; else mp->column++; mp->counter++; if (mp->counter > MI_CYCLES(mi)) { init_mandelbrot(mi); } }
void 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); }
void draw_toneclock(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i; toneclockstruct *tclock; if (toneclocks == NULL) return; tclock = &toneclocks[MI_SCREEN(mi)]; if (tclock->hour == NULL) return; if (tclock->no_colors) { free_toneclock(display, tclock); init_toneclock(mi); return; } XSetFunction(display, tclock->gc, GXxor); #ifndef NO_DBUF XSetForeground(display,tclock->dbuf_gc,MI_BLACK_PIXEL(mi)); XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc, 0, 0, tclock->win_width, tclock->win_height); #endif tclock->painted = True; MI_IS_DRAWN(mi) = True; /* Rotate colours */ if (tclock->cycle_p) { rotate_colors(display, tclock->cmap, tclock->colors, tclock->ncolors, tclock->direction); if (!(LRAND() % 1000)) tclock->direction = -tclock->direction; } for (i = 0; i < tclock->num_hour; i++) { toneclockhour *hour0; int x0 , y0; x0 = (int) (tclock->radius * sin( -tclock->angle - PI_RAD * i * 360.0 / tclock->num_hour ) * 0.5 * ( 1 + cos( tclock->phase ) ) + tclock->x0 + tclock->a_x * sin( tclock->anglex ) ); y0 = (int) (tclock->radius * cos( -tclock->angle - PI_RAD * i * 360.0 / tclock->num_hour ) * 0.5 * ( 1 + cos( tclock->phase ) ) + tclock->y0 + tclock->a_y * sin( tclock->angley ) ); hour0 = &tclock->hour[i]; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel); } else { XSetForeground(display, tclock->gc, hour0->colour); } toneclock_drawhour(mi, hour0 , x0 , y0); hour0->velocity += ((float) NRAND(1001) - 500.0) / 200000.0; hour0->angle += hour0->velocity; } tclock->velocity += ((float) NRAND(1001) - 500.0) / 200000.0; tclock->angle += tclock->velocity; if ( tclock->pulsating ) tclock->phase += tclock->ph_vel; if ( tclock->moving ) { tclock->anglex += tclock->vx; tclock->angley += tclock->vy; } #ifdef NO_DBUF for (i = 0; i < tclock->num_hour; i++) { toneclockhour *hour0; int x0 , y0; x0 = (int) (tclock->radius * sin( -tclock->angle - PI_RAD * i * 360.0 / tclock->num_hour ) * 0.5 * ( 1 + cos( tclock->phase ) ) + tclock->x0 + tclock->a_x * sin( tclock->anglex ) ); y0 = (int) (tclock->radius * cos( -tclock->angle - PI_RAD * i * 360.0 / tclock->num_hour ) * 0.5 * ( 1 + cos( tclock->phase ) ) + tclock->y0 + tclock->a_y * sin( tclock->angley ) ); hour0 = &tclock->hour[i]; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel); } else { XSetForeground(display, tclock->gc, hour0->colour); } toneclock_drawhour(mi, hour0 , x0 , y0); } #else XFlush(display); XCopyArea (display, (Drawable) tclock->dbuf, window, tclock->dbuf_gc, 0, 0, tclock->win_width, tclock->win_height, 0, 0); XFlush(display); XSetForeground(display,tclock->dbuf_gc,MI_BLACK_PIXEL(mi)); XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc, 0, 0, tclock->win_width, tclock->win_height); #endif XSetFunction(display, tclock->gc, GXcopy); }
static void drawcell(ModeInfo * mi, int col, int row, unsigned char state) { demonstruct *dp = &demons[MI_SCREEN(mi)]; GC gc; if (!state) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi)); gc = MI_GC(mi); } else if (MI_NPIXELS(mi) >= NUMSTIPPLES) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, (((int) state - 1) * MI_NPIXELS(mi) / (dp->states - 1)) % MI_NPIXELS(mi))); gc = MI_GC(mi); } else { XGCValues gcv; #ifdef DO_STIPPLE gcv.stipple = dp->pixmaps[(state - 1) % (NUMSTIPPLES - 1)]; #endif /* DO_STIPPLE */ gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); XChangeGC(MI_DISPLAY(mi), dp->stippledGC, GCStipple | GCForeground | GCBackground, &gcv); gc = dp->stippledGC; } if (dp->neighbors == 6) { int ccol = 2 * col + !(row & 1), crow = 2 * row; dp->shape.hexagon[0].x = dp->xb + ccol * dp->xs; dp->shape.hexagon[0].y = dp->yb + crow * dp->ys; if (dp->xs == 1 && dp->ys == 1) XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), gc, dp->shape.hexagon[0].x, dp->shape.hexagon[0].y); else XFillPolygon(MI_DISPLAY(mi), MI_WINDOW(mi), gc, dp->shape.hexagon, 6, Convex, CoordModePrevious); } else if (dp->neighbors == 4 || dp->neighbors == 8) { XFillRectangle(MI_DISPLAY(mi), MI_WINDOW(mi), gc, dp->xb + dp->xs * col, dp->yb + dp->ys * row, dp->xs - (dp->xs > 3), dp->ys - (dp->ys > 3)); } else { /* TRI */ int orient = (col + row) % 2; /* O left 1 right */ dp->shape.triangle[orient][0].x = dp->xb + col * dp->xs; dp->shape.triangle[orient][0].y = dp->yb + row * dp->ys; if (dp->xs <= 3 || dp->ys <= 3) XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), gc, ((orient) ? -1 : 1) + dp->shape.triangle[orient][0].x, dp->shape.triangle[orient][0].y); else { if (orient) dp->shape.triangle[orient][0].x += (dp->xs / 2 - 1); else dp->shape.triangle[orient][0].x -= (dp->xs / 2 - 1); XFillPolygon(MI_DISPLAY(mi), MI_WINDOW(mi), gc, dp->shape.triangle[orient], 3, Convex, CoordModePrevious); } } }
void init_laser(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); int i, c = 0; lasersstruct *lp; if (lasers == NULL) { if ((lasers = (lasersstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (lasersstruct))) == NULL) return; } lp = &lasers[MI_SCREEN(mi)]; lp->width = MI_WIDTH(mi); lp->height = MI_HEIGHT(mi); lp->time = 0; lp->ln = MI_COUNT(mi); if (lp->ln < -MINLASER) { /* if lp->ln is random ... the size can change */ if (lp->laser != NULL) { free(lp->laser); lp->laser = (laserstruct *) NULL; } lp->ln = NRAND(-lp->ln - MINLASER + 1) + MINLASER; } else if (lp->ln < MINLASER) lp->ln = MINLASER; if (lp->laser == NULL) { if ((lp->laser = (laserstruct *) malloc(lp->ln * sizeof (laserstruct))) == NULL) { free_laser(display, lp); return; } } if (lp->stippledGC == None) { XGCValues gcv; gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); lp->gcv_black.foreground = MI_BLACK_PIXEL(mi); if ((lp->stippledGC = XCreateGC(display, MI_WINDOW(mi), GCForeground | GCBackground, &gcv)) == None) { free_laser(display, lp); return; } } MI_CLEARWINDOWCOLORMAPFAST(mi, MI_GC(mi), MI_BLACK_PIXEL(mi)); if (MINDIST < lp->width - MINDIST) lp->cx = RANGE_RAND(MINDIST, lp->width - MINDIST); else lp->cx = RANGE_RAND(0, lp->width); if (MINDIST < lp->height - MINDIST) lp->cy = RANGE_RAND(MINDIST, lp->height - MINDIST); else lp->cy = RANGE_RAND(0, lp->height); lp->lw = RANGE_RAND(MINWIDTH, MAXWIDTH); lp->lr = RANGE_RAND(MINREDRAW, MAXREDRAW); lp->sw = 0; lp->so = 0; if (MI_NPIXELS(mi) > 2) c = NRAND(MI_NPIXELS(mi)); for (i = 0; i < lp->ln; i++) { laserstruct *l = &lp->laser[i]; l->bn = (border) NRAND(4); switch (l->bn) { case TOP: l->bx = NRAND(lp->width); l->by = 0; break; case RIGHT: l->bx = lp->width; l->by = NRAND(lp->height); break; case BOTTOM: l->bx = NRAND(lp->width); l->by = lp->height; break; case LEFT: l->bx = 0; l->by = NRAND(lp->height); } l->dir = (int) (LRAND() & 1); l->speed = ((RANGE_RAND(MINSPEED, MAXSPEED) * lp->width) / 1000) + 1; if (MI_NPIXELS(mi) > 2) { l->gcv.foreground = MI_PIXEL(mi, c); c = (c + COLORSTEP) % MI_NPIXELS(mi); } else l->gcv.foreground = MI_WHITE_PIXEL(mi); } }
static Bool draw_state(ModeInfo * mi, int state) { demonstruct *dp = &demons[MI_SCREEN(mi)]; GC gc; XRectangle *rects; CellList *current; if (!state) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_BLACK_PIXEL(mi)); gc = MI_GC(mi); } else if (MI_NPIXELS(mi) >= NUMSTIPPLES) { XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, (((int) state - 1) * MI_NPIXELS(mi) / (dp->states - 1)) % MI_NPIXELS(mi))); gc = MI_GC(mi); } else { XGCValues gcv; #ifdef DO_STIPPLE gcv.stipple = dp->pixmaps[(state - 1) % (NUMSTIPPLES - 1)]; #endif /* DO_STIPPLE */ gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); XChangeGC(MI_DISPLAY(mi), dp->stippledGC, GCStipple | GCForeground | GCBackground, &gcv); gc = dp->stippledGC; } if (dp->neighbors == 6) { /* Draw right away, slow */ current = dp->cellList[state]; while (current) { int col, row, ccol, crow; col = current->pt.x; row = current->pt.y; ccol = 2 * col + !(row & 1), crow = 2 * row; dp->shape.hexagon[0].x = dp->xb + ccol * dp->xs; dp->shape.hexagon[0].y = dp->yb + crow * dp->ys; if (dp->xs == 1 && dp->ys == 1) XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), gc, dp->shape.hexagon[0].x, dp->shape.hexagon[0].y); else XFillPolygon(MI_DISPLAY(mi), MI_WINDOW(mi), gc, dp->shape.hexagon, 6, Convex, CoordModePrevious); current = current->next; } } else if (dp->neighbors == 4 || dp->neighbors == 8) { /* Take advantage of XDrawRectangles */ int ncells = 0; /* Create Rectangle list from part of the cellList */ if ((rects = (XRectangle *) malloc(dp->ncells[state] * sizeof (XRectangle))) == NULL) { return False; } current = dp->cellList[state]; while (current) { rects[ncells].x = dp->xb + current->pt.x * dp->xs; rects[ncells].y = dp->yb + current->pt.y * dp->ys; rects[ncells].width = dp->xs - (dp->xs > 3); rects[ncells].height = dp->ys - (dp->ys > 3); current = current->next; ncells++; } /* Finally get to draw */ XFillRectangles(MI_DISPLAY(mi), MI_WINDOW(mi), gc, rects, ncells); /* Free up rects list and the appropriate part of the cellList */ (void) free((void *) rects); } else { /* TRI */ current = dp->cellList[state]; while (current) { int col, row, orient; col = current->pt.x; row = current->pt.y; orient = (col + row) % 2; /* O left 1 right */ dp->shape.triangle[orient][0].x = dp->xb + col * dp->xs; dp->shape.triangle[orient][0].y = dp->yb + row * dp->ys; if (dp->xs <= 3 || dp->ys <= 3) XDrawPoint(MI_DISPLAY(mi), MI_WINDOW(mi), gc, ((orient) ? -1 : 1) + dp->shape.triangle[orient][0].x, dp->shape.triangle[orient][0].y); else { if (orient) dp->shape.triangle[orient][0].x += (dp->xs / 2 - 1); else dp->shape.triangle[orient][0].x -= (dp->xs / 2 - 1); XFillPolygon(MI_DISPLAY(mi), MI_WINDOW(mi), gc, dp->shape.triangle[orient], 3, Convex, CoordModePrevious); } current = current->next; } } free_state(dp, state); return True; }
ENTRYPOINT void draw_strange(ModeInfo * mi) { int i, j, n, Cur_Pt; PRM x, y, xo, yo; DBL u; XPoint *Buf; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); DBL Lx, Ly; void (*Iterate) (ATTRACTOR *, PRM, PRM, PRM *, PRM *); PRM xmin, xmax, ymin, ymax; ATTRACTOR *A; if (Root == NULL) return; A = &Root[MI_SCREEN(mi)]; if (A->Fold == NULL) return; Cur_Pt = A->Cur_Pt; Iterate = A->Iterate; u = (DBL) (A->Count) / 1000.0; for (j = MAX_PRM - 1; j >= 0; --j) A->Prm[j] = DBL_To_PRM((1.0 - u) * A->Prm1[j] + u * A->Prm2[j]); x = y = DBL_To_PRM(.0); for (n = SKIP_FIRST; n; --n) { (*Iterate) (A, x, y, &xo, &yo); x = xo + NRAND(8) - 4; y = yo + NRAND(8) - 4; } xmax = 0; xmin = UNIT * 4; ymax = 0; ymin = UNIT * 4; A->Cur_Pt = 0; Buf = A->Buffer2; Lx = (DBL) A->Width / UNIT / 2.2; Ly = (DBL) A->Height / UNIT / 2.2; for (n = A->Max_Pt; n; --n) { (*Iterate) (A, x, y, &xo, &yo); Buf->x = (int) (Lx * (x + DBL_To_PRM(1.1))); Buf->y = (int) (Ly * (DBL_To_PRM(1.1) - y)); /* (void) fprintf( stderr, "X,Y: %d %d ", Buf->x, Buf->y ); */ Buf++; A->Cur_Pt++; if (xo > xmax) xmax = xo; else if (xo < xmin) xmin = xo; if (yo > ymax) ymax = yo; else if (yo < ymin) ymin = yo; x = xo + NRAND(8) - 4; y = yo + NRAND(8) - 4; } MI_IS_DRAWN(mi) = True; XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); if (A->dbuf != None) { /* jwz */ XSetForeground(display, A->dbuf_gc, 0); /* XDrawPoints(display, A->dbuf, A->dbuf_gc, A->Buffer1, Cur_Pt,CoordModeOrigin); */ XFillRectangle(display, A->dbuf, A->dbuf_gc, 0, 0, A->Width, A->Height); } else XDrawPoints(display, window, gc, A->Buffer1, Cur_Pt, CoordModeOrigin); if (MI_NPIXELS(mi) < 2) XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); else XSetForeground(display, gc, MI_PIXEL(mi, A->Col % MI_NPIXELS(mi))); if (A->dbuf != None) { XSetForeground(display, A->dbuf_gc, 1); XDrawPoints(display, A->dbuf, A->dbuf_gc, A->Buffer2, A->Cur_Pt, CoordModeOrigin); XCopyPlane(display, A->dbuf, window, gc, 0, 0, A->Width, A->Height, 0, 0, 1); } else XDrawPoints(display, window, gc, A->Buffer2, A->Cur_Pt, CoordModeOrigin); Buf = A->Buffer1; A->Buffer1 = A->Buffer2; A->Buffer2 = Buf; if ((xmax - xmin < DBL_To_PRM(.2)) && (ymax - ymin < DBL_To_PRM(.2))) A->Count += 4 * A->Speed; else A->Count += A->Speed; if (A->Count >= 1000) { for (i = MAX_PRM - 1; i >= 0; --i) A->Prm1[i] = A->Prm2[i]; Random_Prm(A->Prm2); A->Count = 0; } A->Col++; }
ENTRYPOINT void init_strange(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); #ifndef NO_DBUF Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); #endif ATTRACTOR *Attractor; if (Root == NULL) { if ((Root = (ATTRACTOR *) calloc(MI_NUM_SCREENS(mi), sizeof (ATTRACTOR))) == NULL) return; } Attractor = &Root[MI_SCREEN(mi)]; if (Attractor->Fold == NULL) { int i; if ((Attractor->Fold = (PRM *) calloc(UNIT2 + 1, sizeof (PRM))) == NULL) { free_strange(display, Attractor); return; } for (i = 0; i <= UNIT2; ++i) { DBL x; /* x = ( DBL )(i)/UNIT2; */ /* x = sin( M_PI/2.0*x ); */ /* x = sqrt( x ); */ /* x = x*x; */ /* x = x*(1.0-x)*4.0; */ x = (DBL) (i) / UNIT; x = sin(x); Attractor->Fold[i] = DBL_To_PRM(x); } } if (Attractor->Buffer1 == NULL) if ((Attractor->Buffer1 = (XPoint *) calloc(MAX_POINTS, sizeof (XPoint))) == NULL) { free_strange(display, Attractor); return; } if (Attractor->Buffer2 == NULL) if ((Attractor->Buffer2 = (XPoint *) calloc(MAX_POINTS, sizeof (XPoint))) == NULL) { free_strange(display, Attractor); return; } Attractor->Max_Pt = MAX_POINTS; Attractor->Width = MI_WIDTH(mi); Attractor->Height = MI_HEIGHT(mi); Attractor->Cur_Pt = 0; Attractor->Count = 0; Attractor->Col = NRAND(MI_NPIXELS(mi)); Attractor->Speed = 4; Attractor->Iterate = Funcs[NRAND(2)]; Random_Prm(Attractor->Prm1); Random_Prm(Attractor->Prm2); #ifndef NO_DBUF if (Attractor->dbuf != None) XFreePixmap(display, Attractor->dbuf); Attractor->dbuf = XCreatePixmap(display, window, Attractor->Width, Attractor->Height, 1); /* Allocation checked */ if (Attractor->dbuf != None) { XGCValues gcv; gcv.foreground = 0; gcv.background = 0; #ifndef HAVE_COCOA gcv.graphics_exposures = False; #endif /* HAVE_COCOA */ gcv.function = GXcopy; if (Attractor->dbuf_gc != None) XFreeGC(display, Attractor->dbuf_gc); if ((Attractor->dbuf_gc = XCreateGC(display, Attractor->dbuf, #ifndef HAVE_COCOA GCGraphicsExposures | #endif /* HAVE_COCOA */ GCFunction | GCForeground | GCBackground, &gcv)) == None) { XFreePixmap(display, Attractor->dbuf); Attractor->dbuf = None; } else { XFillRectangle(display, Attractor->dbuf, Attractor->dbuf_gc, 0, 0, Attractor->Width, Attractor->Height); XSetBackground(display, gc, MI_BLACK_PIXEL(mi)); XSetFunction(display, gc, GXcopy); } } #endif MI_CLEARWINDOW(mi); /* Do not want any exposure events from XCopyPlane */ XSetGraphicsExposures(display, MI_GC(mi), False); }