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); } }
ENTRYPOINT void init_mountain (ModeInfo * mi) { int i, j, x, y; XGCValues gcv; mountainstruct *mp; if (mountains == NULL) { if ((mountains = (mountainstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (mountainstruct))) == NULL) return; } mp = &mountains[MI_SCREEN(mi)]; mp->width = MI_WIDTH(mi); mp->height = MI_HEIGHT(mi); mp->pixelmode = (mp->width + mp->height < 200); mp->stage = 0; mp->time = 0; mp->x = mp->y = 0; if (MI_IS_FULLRANDOM(mi)) { mp->joke = (Bool) (NRAND(10) == 0); mp->wireframe = (Bool) (LRAND() & 1); } else { mp->joke = False; mp->wireframe = MI_IS_WIREFRAME(mi); } if (mp->stippledGC == None) { gcv.foreground = MI_WHITE_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); if ((mp->stippledGC = XCreateGC(MI_DISPLAY(mi), MI_WINDOW(mi), GCForeground | GCBackground, &gcv)) == None) return; } MI_CLEARWINDOW(mi); for (y = 0; y < (int) WORLDWIDTH; y++) for (x = 0; x < (int) WORLDWIDTH; x++) mp->h[x][y] = 0; j = MI_COUNT(mi); if (j < 0) j = NRAND(-j) + 1; for (i = 0; i < j; i++) mp->h[RANGE_RAND(1, WORLDWIDTH - 1)][RANGE_RAND(1, WORLDWIDTH - 1)] = NRAND(MAXHEIGHT); for (y = 0; y < WORLDWIDTH; y++) for (x = 0; x < WORLDWIDTH; x++) spread(mp->h, x, y); for (y = 0; y < WORLDWIDTH; y++) for (x = 0; x < WORLDWIDTH; x++) { mp->h[x][y] = mp->h[x][y] + NRAND(10) - 5; if (mp->h[x][y] < 10) mp->h[x][y] = 0; } if (MI_NPIXELS(mi) > 2) mp->offset = NRAND(MI_NPIXELS(mi)); else mp->offset = 0; }