static void setupmovedelta(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); puzzlestruct *pp = &puzzles[MI_SCREEN(mi)]; if (pp->bufferBox != None) { XFreePixmap(display, pp->bufferBox); pp->bufferBox = None; } if ((pp->bufferBox = XCreatePixmap(display, MI_WINDOW(mi), pp->boxsize.x, pp->boxsize.y, MI_DEPTH(mi))) == None) { free_puzzle(display, pp); return; } XCopyArea(MI_DISPLAY(mi), MI_WINDOW(mi), pp->bufferBox, pp->backGC, pp->nextcol * pp->boxsize.x + pp->randompos.x + 1, pp->nextrow * pp->boxsize.y + pp->randompos.y + 1, pp->boxsize.x - 2, pp->boxsize.y - 2, 0, 0); XFlush(MI_DISPLAY(mi)); if (pp->nextcol > pp->col) { pp->cfactor = -1; pp->cbs = pp->boxsize.x; pp->cbw = pp->incrementOfMove; } else if (pp->col > pp->nextcol) { pp->cfactor = 1; pp->cbs = -pp->incrementOfMove; pp->cbw = pp->incrementOfMove; } else { pp->cfactor = 0; pp->cbs = 0; pp->cbw = pp->boxsize.x; } if (pp->nextrow > pp->row) { pp->rfactor = -1; pp->rbs = pp->boxsize.y; pp->rbw = pp->incrementOfMove; } else if (pp->row > pp->nextrow) { pp->rfactor = 1; pp->rbs = -pp->incrementOfMove; pp->rbw = pp->incrementOfMove; } else { pp->rfactor = 0; pp->rbs = 0; pp->rbw = pp->boxsize.y; } if (pp->cfactor == 0) pp->lengthOfMove = pp->boxsize.y; else if (pp->rfactor == 0) pp->lengthOfMove = pp->boxsize.x; else pp->lengthOfMove = MIN(pp->boxsize.x, pp->boxsize.y); pp->Lp = pp->incrementOfMove; }
void init_galaxy(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); unistruct *gp; if (universes == NULL) { if ((universes = (unistruct *) calloc(MI_NUM_SCREENS(mi), sizeof (unistruct))) == NULL) return; } gp = &universes[MI_SCREEN(mi)]; gp->f_hititerations = MI_CYCLES(mi); gp->clip.left = 0; gp->clip.top = 0; gp->clip.right = MI_WIDTH(mi); gp->clip.bottom = MI_HEIGHT(mi); gp->scale = (double) (gp->clip.right + gp->clip.bottom) / 8.0; gp->midx = gp->clip.right / 2; gp->midy = gp->clip.bottom / 2; if (MI_IS_FULLRANDOM(mi)) { gp->fisheye = !(NRAND(3)); if (!gp->fisheye) gp->tracks = (Bool) (LRAND() & 1); } else { gp->fisheye = fisheye; gp->tracks = tracks; } if (!startover(mi)) return; if (gp->fisheye) { if (gp->pixmap != None) XFreePixmap(display, gp->pixmap); if ((gp->pixmap = XCreatePixmap(display, MI_WINDOW(mi), MI_WIDTH(mi), MI_HEIGHT(mi), MI_DEPTH(mi))) == None) { gp->fisheye = False; } } if (gp->fisheye) { XSetGraphicsExposures(display, MI_GC(mi), False); gp->scale *= Z_OFFSET; gp->star_scale_Z = (gp->scale * .005); /* don't want any exposure events from XCopyPlane */ } }
ENTRYPOINT void init_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_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); }
static void create_eyes(ModeInfo * mi, Eyes * e, Eyes * eyes, int num_eyes) { EyeScrInfo *ep = &eye_info[MI_SCREEN(mi)]; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int win_width = MI_WIDTH(mi); int win_height = MI_HEIGHT(mi); unsigned long black_pixel = MI_BLACK_PIXEL(mi); unsigned long white_pixel = MI_WHITE_PIXEL(mi); Bool iconic = MI_IS_ICONIC(mi); Pixmap pix = e->pixmap; /* preserve pixmap handle */ int w = e->width; /* remember last w/h */ int h = e->height; int npixels = MI_NPIXELS(mi); /* num colors in colormap */ int cycs = MI_CYCLES(mi); /* affects eye lifetime */ int maxw = win_width / 2; /* widest eyes can be */ int color, lid_color; int i; (void) memset((char *) e, 0, sizeof (Eyes)); /* wipe everything */ e->pixmap = pix; /* remember Pixmap handle */ /* sanity check the cycles value */ if (cycs < 1) cycs = 1; if (cycs > MAX_CYCLES) cycs = MAX_CYCLES; e->time_to_die = (unsigned long) LIFE_MIN + NRAND(LIFE_RANGE); e->time_to_die *= (unsigned long) cycs; /* multiply life by cycles */ e->time_to_die += ep->time; e->pupil_pixel = black_pixel; /* pupil is always black */ if (MI_NPIXELS(mi) <= 2) { /* TODO: stipple the eyelid? */ e->eyelid_pixel = black_pixel; e->eyeball_pixel = white_pixel; } else { lid_color = NRAND(npixels); e->eyelid_pixel = MI_PIXEL(mi, lid_color); while ((color = NRAND(npixels + 5)) == lid_color) { /* empty */ } if (color >= npixels) { /* give white a little better chance */ e->eyeball_pixel = white_pixel; } else { e->eyeball_pixel = MI_PIXEL(mi, color); } } if (iconic) { /* only one pair of eyes, fills entire window */ e->width = win_width; e->height = win_height; } else { if (maxw - MIN_EYE_SIZE > MIN_EYE_SIZE) e->width = NRAND(maxw - MIN_EYE_SIZE) + MIN_EYE_SIZE; else e->width = NRAND(MIN_EYE_SIZE) + MIN_EYE_SIZE; e->x = (win_width - e->width > 0) ? NRAND(win_width - e->width) : 0; e->height = NRAND(e->width * 3 / 4) + (e->width / 4); e->y = (win_height - e->height > 0) ? NRAND(win_height - e->height) : 0; /* check for overlap with other eyes */ for (i = 0; i < num_eyes; i++) { if (&eyes[i] == e) { /* that's me */ continue; } if (eyes_overlap(e, &eyes[i])) { /* collision, force retry on next cycle */ e->time_to_die = 0; break; } } } /* If the Pixmap is smaller than the new size, make it bigger */ if ((e->width > w) || (e->height > h)) { if (e->pixmap != None) { XFreePixmap(display, e->pixmap); } if ((e->pixmap = XCreatePixmap(display, window, e->width, e->height, MI_DEPTH(mi))) == None) { e->width = e->height = 0; return; } } /* Set the transformation matrix for this set of eyes * If iconic, make the eyes image one pixel shorter and * skinnier, they seem to fit in the icon box better that way. */ SetTransform(&e->transform, 0, (iconic) ? e->width - 1 : e->width, (iconic) ? e->height - 1 : e->height, 0, W_MIN_X, W_MAX_X, W_MIN_Y, W_MAX_Y); /* clear the offscreen pixmap to background color */ XSetForeground(display, ep->eyeGC, black_pixel); XFillRectangle(display, (Drawable) e->pixmap, ep->eyeGC, 0, 0, e->width, e->height); /* make the full eye images in the offscreen Pixmap */ make_eye(mi, e->pixmap, e, 0, True); make_eye(mi, e->pixmap, e, 1, True); }
static Bool pickClothes(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); nosestruct *np = &noses[MI_SCREEN(mi)]; XGCValues gcv; Pixmap face_pix, hat_pix, shoe_pix, shoel_pix, shoer_pix; unsigned long hat_color = (MI_NPIXELS(mi) <= 2) ? MI_WHITE_PIXEL(mi) : MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); unsigned long face_color = (MI_NPIXELS(mi) <= 2) ? MI_WHITE_PIXEL(mi) : MI_PIXEL(mi, (YELLOW)); /* Racism? */ unsigned long shoe_color = (MI_NPIXELS(mi) <= 2) ? MI_WHITE_PIXEL(mi) : MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); int i; gcv.graphics_exposures = False; gcv.foreground = MI_BLACK_PIXEL(mi); gcv.background = MI_BLACK_PIXEL(mi); for (i = 0; i < PIXMAPS; i++) { if ((np->position[i] = XCreatePixmap(display, window, PIXMAP_SIZE, PIXMAP_SIZE, MI_DEPTH(mi))) == None) return False; if ((np->noseGC[i] = XCreateGC(display, np->position[i], GCForeground | GCBackground | GCGraphicsExposures, &gcv)) == None) return False; XFillRectangle(display, np->position[i], np->noseGC[i], 0, 0, PIXMAP_SIZE, PIXMAP_SIZE); } XSetBackground(display, gc, MI_BLACK_PIXEL(mi)); XSetFillStyle(display, gc, FillStippled); /* DOWN NOSE GUY */ if ((shoe_pix = XCreateBitmapFromData(display, window, (char *) nose_shoe_front_bits, nose_shoe_front_width, nose_shoe_front_height)) == None) { return False; } COPY(display, gc, shoe_color, shoe_pix, np->position[D], (PIXMAP_SIZE - nose_shoe_front_width) / 2, nose_hat_height + nose_face_front_height + 3, nose_shoe_front_width, nose_shoe_front_height); if ((face_pix = XCreateBitmapFromData(display, window, (char *) nose_face_down_bits, nose_face_down_width, nose_face_down_height)) == None) { XFreePixmap(display, shoe_pix); return False; } COPY(display, gc, face_color, face_pix, np->position[D], (PIXMAP_SIZE - nose_face_down_width) / 2, nose_hat_down_height + 7, nose_face_down_width, nose_face_down_height); XFreePixmap(display, face_pix); if ((hat_pix = XCreateBitmapFromData(display, window, (char *) nose_hat_down_bits, nose_hat_down_width, nose_hat_down_height)) == None) { XFreePixmap(display, shoe_pix); return False; } COPY(display, gc, hat_color, hat_pix, np->position[D], (PIXMAP_SIZE - nose_hat_down_width) / 2, 7, nose_hat_down_width, nose_hat_down_height); XFreePixmap(display, hat_pix); if (MI_NPIXELS(mi) <= 2) { XSetFillStyle(display, gc, FillSolid); XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillRectangle(display, np->position[D], gc, 0, nose_hat_down_height + 6, PIXMAP_SIZE, 1); XSetFillStyle(display, gc, FillStippled); } /* FRONT NOSE GUY */ COPY(display, gc, shoe_color, shoe_pix, np->position[F], (PIXMAP_SIZE - nose_shoe_front_width) / 2, nose_hat_height + nose_face_front_height + 3, nose_shoe_front_width, nose_shoe_front_height); XFreePixmap(display, shoe_pix); if ((hat_pix = XCreateBitmapFromData(display, window, (char *) nose_hat_bits, nose_hat_width, nose_hat_height)) == None) { return False; } COPY(display, gc, hat_color, hat_pix, np->position[F], (PIXMAP_SIZE - nose_hat_width) / 2, 4, nose_hat_width, nose_hat_height); if (MI_NPIXELS(mi) <= 2) { XSetFillStyle(display, gc, FillSolid); XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillRectangle(display, np->position[F], gc, 0, nose_hat_height + 3, PIXMAP_SIZE, 1); XSetFillStyle(display, gc, FillStippled); } if ((face_pix = XCreateBitmapFromData(display, window, (char *) nose_face_front_bits, nose_face_front_width, nose_face_front_height)) == None) { XFreePixmap(display, hat_pix); return False; } COPY(display, gc, face_color, face_pix, np->position[F], (PIXMAP_SIZE - nose_face_front_width) / 2, nose_hat_height + 1, nose_face_front_width, nose_face_front_height); /* FRONT LEFT NOSE GUY */ if ((shoel_pix = XCreateBitmapFromData(display, window, (char *) nose_shoe_left_bits, nose_shoe_left_width, nose_shoe_left_height)) == None) { XFreePixmap(display, hat_pix); XFreePixmap(display, face_pix); return False; } COPY(display, gc, shoe_color, shoel_pix, np->position[LF], (PIXMAP_SIZE - nose_shoe_left_width) / 2 - 4, nose_hat_height + nose_face_front_height + 3, nose_shoe_left_width, nose_shoe_left_height); COPY(display, gc, hat_color, hat_pix, np->position[LF], (PIXMAP_SIZE - nose_hat_width) / 2, 4, nose_hat_width, nose_hat_height); if (MI_NPIXELS(mi) <= 2) { XSetFillStyle(display, gc, FillSolid); XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillRectangle(display, np->position[LF], gc, 0, nose_hat_height + 3, PIXMAP_SIZE, 1); XSetFillStyle(display, gc, FillStippled); } COPY(display, gc, face_color, face_pix, np->position[LF], (PIXMAP_SIZE - nose_face_front_width) / 2, nose_hat_height + 1, nose_face_front_width, nose_face_front_height); /* FRONT RIGHT NOSE GUY */ if ((shoer_pix = XCreateBitmapFromData(display, window, (char *) nose_shoe_right_bits, nose_shoe_right_width, nose_shoe_right_height)) == None) { XFreePixmap(display, hat_pix); XFreePixmap(display, shoel_pix); XFreePixmap(display, face_pix); return False; } COPY(display, gc, shoe_color, shoer_pix, np->position[RF], (PIXMAP_SIZE - nose_shoe_right_width) / 2 + 4, nose_hat_height + nose_face_front_height + 3, nose_shoe_right_width, nose_shoe_right_height); COPY(display, gc, hat_color, hat_pix, np->position[RF], (PIXMAP_SIZE - nose_hat_width) / 2, 4, nose_hat_width, nose_hat_height); if (MI_NPIXELS(mi) <= 2) { XSetFillStyle(display, gc, FillSolid); XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillRectangle(display, np->position[RF], gc, 0, nose_hat_height + 3, PIXMAP_SIZE, 1); XSetFillStyle(display, gc, FillStippled); } COPY(display, gc, face_color, face_pix, np->position[RF], (PIXMAP_SIZE - nose_face_front_width) / 2, nose_hat_height + 1, nose_face_front_width, nose_face_front_height); XFreePixmap(display, face_pix); /* LEFT NOSE GUY */ COPY(display, gc, shoe_color, shoel_pix, np->position[L], (PIXMAP_SIZE - nose_shoe_left_width) / 2 - 4, nose_hat_height + nose_face_front_height + 3, nose_shoe_left_width, nose_shoe_left_height); XFreePixmap(display, shoel_pix); COPY(display, gc, hat_color, hat_pix, np->position[L], (PIXMAP_SIZE - nose_hat_width) / 2, 4, nose_hat_width, nose_hat_height); if (MI_NPIXELS(mi) <= 2) { XSetFillStyle(display, gc, FillSolid); XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillRectangle(display, np->position[L], gc, 0, nose_hat_height + 3, PIXMAP_SIZE, 1); XSetFillStyle(display, gc, FillStippled); } if ((face_pix = XCreateBitmapFromData(display, window, (char *) nose_face_left_bits, nose_face_left_width, nose_face_left_height)) == None) { XFreePixmap(display, hat_pix); XFreePixmap(display, shoer_pix); return False; } COPY(display, gc, face_color, face_pix, np->position[L], (PIXMAP_SIZE - nose_face_left_width) / 2 - 4, nose_hat_height + 4, nose_face_left_width, nose_face_left_height); /* LEFT NOSE GUY STEPPING */ if ((shoel_pix = XCreateBitmapFromData(display, window, (char *) nose_step_left_bits, nose_step_left_width, nose_step_left_height)) == None) { XFreePixmap(display, hat_pix); XFreePixmap(display, face_pix); XFreePixmap(display, shoer_pix); return False; } COPY(display, gc, shoe_color, shoel_pix, np->position[LSTEP], (PIXMAP_SIZE - nose_step_left_width) / 2, nose_hat_height + nose_face_front_height - 1, nose_step_left_width, nose_step_left_height); XFreePixmap(display, shoel_pix); COPY(display, gc, hat_color, hat_pix, np->position[LSTEP], (PIXMAP_SIZE - nose_hat_width) / 2, 4, nose_hat_width, nose_hat_height); if (MI_NPIXELS(mi) <= 2) { XSetFillStyle(display, gc, FillSolid); XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillRectangle(display, np->position[LSTEP], gc, 0, nose_hat_height + 3, PIXMAP_SIZE, 1); XSetFillStyle(display, gc, FillStippled); } COPY(display, gc, face_color, face_pix, np->position[LSTEP], (PIXMAP_SIZE - nose_face_left_width) / 2 - 4, nose_hat_height + 4, nose_face_left_width, nose_face_left_height); XFreePixmap(display, face_pix); /* RIGHT NOSE GUY */ if ((face_pix = XCreateBitmapFromData(display, window, (char *) nose_face_right_bits, nose_face_right_width, nose_face_right_height)) == None) { XFreePixmap(display, hat_pix); XFreePixmap(display, shoer_pix); return False; } COPY(display, gc, shoe_color, shoer_pix, np->position[R], (PIXMAP_SIZE - nose_shoe_right_width) / 2 + 4, nose_hat_height + nose_face_front_height + 3, nose_shoe_right_width, nose_shoe_right_height); XFreePixmap(display, shoer_pix); COPY(display, gc, hat_color, hat_pix, np->position[R], (PIXMAP_SIZE - nose_hat_width) / 2, 4, nose_hat_width, nose_hat_height); if (MI_NPIXELS(mi) <= 2) { XSetFillStyle(display, gc, FillSolid); XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillRectangle(display, np->position[R], gc, 0, nose_hat_height + 3, PIXMAP_SIZE, 1); XSetFillStyle(display, gc, FillStippled); } COPY(display, gc, face_color, face_pix, np->position[R], (PIXMAP_SIZE - nose_face_right_width) / 2 + 4, nose_hat_height + 4, nose_face_right_width, nose_face_right_height); /* RIGHT NOSE GUY STEPPING */ if ((shoer_pix = XCreateBitmapFromData(display, window, (char *) nose_step_right_bits, nose_step_right_width, nose_step_right_height)) == None) { XFreePixmap(display, face_pix); XFreePixmap(display, hat_pix); return False; } COPY(display, gc, shoe_color, shoer_pix, np->position[RSTEP], (PIXMAP_SIZE - nose_step_right_width) / 2, nose_hat_height + nose_face_front_height - 1, nose_step_right_width, nose_step_right_height); XFreePixmap(display, shoer_pix); COPY(display, gc, hat_color, hat_pix, np->position[RSTEP], (PIXMAP_SIZE - nose_hat_width) / 2, 4, nose_hat_width, nose_hat_height); XFreePixmap(display, hat_pix); if (MI_NPIXELS(mi) <= 2) { XSetFillStyle(display, gc, FillSolid); XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); XFillRectangle(display, np->position[RSTEP], gc, 0, nose_hat_height + 3, PIXMAP_SIZE, 1); XSetFillStyle(display, gc, FillStippled); } COPY(display, gc, face_color, face_pix, np->position[RSTEP], (PIXMAP_SIZE - nose_face_right_width) / 2 + 4, nose_hat_height + 4, nose_face_right_width, nose_face_right_height); XFreePixmap(display, face_pix); XSetFillStyle(display, gc, FillSolid); return True; }
void getImage(ModeInfo * mi, XImage ** logo, int default_width, int default_height, unsigned char *default_bits, #ifdef HAVE_XPM int default_xpm, char **name, #endif int *graphics_format, Colormap * ncm, unsigned long *black) { Display *display = MI_DISPLAY(mi); static char *bitmap_local = (char *) NULL; #ifndef STANDALONE #ifdef HAVE_XPM XpmAttributes attrib; #endif #if 0 /* This probably works best in most cases but for random mode used with random selection of a file it will fail often. */ *ncm = None; #else if (!fixedColors(mi)) *ncm = XCreateColormap(display, MI_WINDOW(mi), MI_VISUAL(mi), AllocNone); else *ncm = None; #endif #ifdef HAVE_XPM attrib.visual = MI_VISUAL(mi); if (*ncm == None) { attrib.colormap = MI_COLORMAP(mi); } else { attrib.colormap = *ncm; } attrib.depth = MI_DEPTH(mi); attrib.valuemask = XpmVisual | XpmColormap | XpmDepth; #endif #endif /* !STANDALONE */ *graphics_format = 0; if (bitmap_local != NULL) { free(bitmap_local); bitmap_local = (char *) NULL; } if (MI_BITMAP(mi) && strlen(MI_BITMAP(mi))) { #ifdef STANDALONE bitmap_local = MI_BITMAP(mi); #else if ((bitmap_local = (char *) malloc(256)) == NULL) { (void) fprintf(stderr , "no memory for \"%s\"\n" , MI_BITMAP(mi)); return; } (void) strncpy(bitmap_local, MI_BITMAP(mi), 256); #if HAVE_DIRENT_H getRandomFile(MI_BITMAP(mi), bitmap_local); #endif #endif /* STANDALONE */ } if (bitmap_local && strlen(bitmap_local)) { #if defined( USE_MAGICK ) && !defined( STANDALONE ) if ( readable( bitmap_local ) ) { if ( MI_NPIXELS( mi ) > 2 ) { Colormap magick_colormap; if (*ncm == None) { magick_colormap = MI_COLORMAP(mi); } else { magick_colormap = *ncm; } if ( MagickSuccess == MagickFileToImage( mi , bitmap_local , logo , magick_colormap ) ) { *graphics_format = IS_MAGICKFILE; *black = GetColor(mi, MI_BLACK_PIXEL(mi)); (void) GetColor(mi, MI_WHITE_PIXEL(mi)); (void) GetColor(mi, MI_BG_PIXEL(mi)); (void) GetColor(mi, MI_FG_PIXEL(mi)); } } } else { (void) fprintf(stderr , "could not read file \"%s\"\n" , bitmap_local); } #else # ifndef STANDALONE if (readable(bitmap_local)) { if (MI_NPIXELS(mi) > 2) { Colormap ras_colormap; if (*ncm == None) { ras_colormap = MI_COLORMAP(mi); } else { ras_colormap = *ncm; } if (RasterSuccess == RasterFileToImage(mi, bitmap_local, logo , ras_colormap )) { *graphics_format = IS_RASTERFILE; *black = GetColor(mi, MI_BLACK_PIXEL(mi)); (void) GetColor(mi, MI_WHITE_PIXEL(mi)); (void) GetColor(mi, MI_BG_PIXEL(mi)); (void) GetColor(mi, MI_FG_PIXEL(mi)); } } } else { (void) fprintf(stderr, "could not read file \"%s\"\n", bitmap_local); } #ifdef HAVE_XPM #ifndef USE_MONOXPM if (MI_NPIXELS(mi) > 2) #endif { if (*graphics_format <= 0) { if (*ncm != None) reserveColors(mi, *ncm, black); if (XpmSuccess == XpmReadFileToImage(display, bitmap_local, logo, (XImage **) NULL, &attrib)) *graphics_format = IS_XPMFILE; } } #endif #endif /* !STANDALONE */ if (*graphics_format <= 0) { if (!blogo.data) { if (BitmapSuccess == XbmReadFileToImage(bitmap_local, &blogo.width, &blogo.height, (unsigned char **) &blogo.data)) { blogo.bytes_per_line = (blogo.width + 7) / 8; *graphics_format = IS_XBMFILE; *logo = &blogo; } } else { *graphics_format = IS_XBMDONE; *logo = &blogo; } } #endif if (*graphics_format <= 0 && MI_IS_VERBOSE(mi)) (void) fprintf(stderr, "\"%s\" is in an unrecognized format or not compatible with screen\n", bitmap_local); } #ifndef STANDALONE #ifdef HAVE_XPM if (*graphics_format <= 0 && ((MI_IS_FULLRANDOM(mi)) ? LRAND() & 1: default_xpm)) #ifndef USE_MONOXPM if (MI_NPIXELS(mi) > 2) #endif if (XpmSuccess == XpmCreateImageFromData(display, name, logo, (XImage **) NULL, &attrib)) *graphics_format = IS_XPM; #endif #endif /* STANDALONE */ if (*graphics_format <= 0) { if (!blogo.data) { blogo.data = (char *) default_bits; blogo.width = default_width; blogo.height = default_height; blogo.bytes_per_line = (blogo.width + 7) / 8; *graphics_format = IS_XBM; } else *graphics_format = IS_XBMDONE; *logo = &blogo; } #ifndef STANDALONE /* Come back later */ if (*ncm != None && *graphics_format != IS_RASTERFILE && *graphics_format != IS_XPMFILE && *graphics_format != IS_XPM && *graphics_format != IS_MAGICKFILE) { XFreeColormap(display, *ncm); *ncm = None; } #endif /* STANDALONE */ /* Come back later */ }
/*- * init_swirl * * Initialise things for swirling * * - win is the window to draw in */ void init_swirl(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); swirlstruct *sp; /* does the swirls array exist? */ if (swirls == NULL) { int i; /* allocate an array, one entry for each screen */ if ((swirls = (swirlstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (swirlstruct))) == NULL) return; /* initialise them all */ for (i = 0; i < MI_NUM_SCREENS(mi); i++) initialise_swirl(&swirls[i]); } /* get a pointer to this swirl */ sp = &(swirls[MI_SCREEN(mi)]); sp->mi = mi; /* get window parameters */ sp->width = MI_WIDTH(mi); sp->height = MI_HEIGHT(mi); sp->depth = MI_DEPTH(mi); sp->rdepth = sp->depth; sp->visual = MI_VISUAL(mi); if (sp->depth > 16) sp->depth = 16; /* initialise image for speeding up drawing */ if (!initialise_image(display, sp)) { free_swirl(display, sp); return; } MI_CLEARWINDOW(mi); if (!sp->gc) { if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XColor color; #ifndef STANDALONE sp->fg = MI_FG_PIXEL(mi); sp->bg = MI_BG_PIXEL(mi); #endif sp->blackpixel = MI_BLACK_PIXEL(mi); sp->whitepixel = MI_WHITE_PIXEL(mi); if ((sp->cmap = XCreateColormap(display, window, MI_VISUAL(mi), AllocNone)) == None) { free_swirl(display, sp); return; } XSetWindowColormap(display, window, sp->cmap); (void) XParseColor(display, sp->cmap, "black", &color); (void) XAllocColor(display, sp->cmap, &color); MI_BLACK_PIXEL(mi) = color.pixel; (void) XParseColor(display, sp->cmap, "white", &color); (void) XAllocColor(display, sp->cmap, &color); MI_WHITE_PIXEL(mi) = color.pixel; #ifndef STANDALONE (void) XParseColor(display, sp->cmap, background, &color); (void) XAllocColor(display, sp->cmap, &color); MI_BG_PIXEL(mi) = color.pixel; (void) XParseColor(display, sp->cmap, foreground, &color); (void) XAllocColor(display, sp->cmap, &color); MI_FG_PIXEL(mi) = color.pixel; #endif sp->colors = (XColor *) NULL; sp->ncolors = 0; } if ((sp->gc = XCreateGC(display, MI_WINDOW(mi), (unsigned long) 0, (XGCValues *) NULL)) == None) { free_swirl(display, sp); return; } } MI_CLEARWINDOW(mi); /* Set up colour map */ sp->direction = (LRAND() & 1) ? 1 : -1; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { 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; } sp->ncolors = MI_NCOLORS(mi); if (sp->ncolors < 2) sp->ncolors = 2; if (sp->ncolors <= 2) sp->mono_p = True; else sp->mono_p = False; if (sp->mono_p) sp->colors = (XColor *) NULL; else if ((sp->colors = (XColor *) malloc(sizeof (*sp->colors) * (sp->ncolors + 1))) == NULL) { free_swirl(display, sp); return; } sp->cycle_p = has_writable_cells(mi); if (sp->cycle_p) { if (MI_IS_FULLRANDOM(mi)) { if (!NRAND(8)) sp->cycle_p = False; else sp->cycle_p = True; } else { sp->cycle_p = cycle_p; } } if (!sp->mono_p) { if (!(LRAND() % 10)) make_random_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif sp->cmap, sp->colors, &sp->ncolors, True, True, &sp->cycle_p); else if (!(LRAND() % 2)) make_uniform_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif sp->cmap, sp->colors, &sp->ncolors, True, &sp->cycle_p); else make_smooth_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif sp->cmap, sp->colors, &sp->ncolors, True, &sp->cycle_p); } XInstallColormap(display, sp->cmap); if (sp->ncolors < 2) { sp->ncolors = 2; sp->no_colors = True; } else sp->no_colors = False; if (sp->ncolors <= 2) sp->mono_p = True; if (sp->mono_p) sp->cycle_p = False; } if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (sp->mono_p) { sp->cur_color = MI_BLACK_PIXEL(mi); } } /* resolution starts off chunky */ sp->resolution = MIN_RES + 1; /* calculate the pixel step for this resulution */ sp->r = (1 << (sp->resolution - 1)); /* how many knots? */ sp->n_knots = random_no((unsigned int) MI_COUNT(mi) / 2) + MI_COUNT(mi) + 1; /* what type of knots? */ sp->knot_type = ALL; /* for now */ /* use two_plane mode occaisionally */ if (random_no(100) <= TWO_PLANE_PCNT) { sp->two_plane = sp->first_plane = True; sp->max_resolution = 2; } else sp->two_plane = False; /* fix the knot values */ if (!create_knots(sp)) { free_swirl(display, sp); return; } /* we are off */ sp->started = True; sp->drawing = False; }
void init_goop(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i; XGCValues gcv; int nblobs; unsigned long *plane_masks = NULL; unsigned long base_pixel = 0; goopstruct *gp; if (goops == NULL) { if ((goops = (goopstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (goopstruct))) == NULL) return; } gp = &goops[MI_SCREEN(mi)]; gp->mode = (False /* xor init */ ? xored : (True /* transparent init */ ? transparent : opaque)); gp->width = MI_WIDTH(mi); gp->height = MI_HEIGHT(mi); free_goop(display, gp); gp->nlayers = 0; /* planes init */ if (gp->nlayers <= 0) gp->nlayers = (int) (LRAND() % (MI_DEPTH(mi) - 2)) + 2; if ((gp->layers = (layer *) calloc(gp->nlayers, sizeof (layer))) == NULL) { return; /* free_goop just ran */ } if ((MI_NPIXELS(mi) < 2) && gp->mode == transparent) gp->mode = opaque; /* Try to allocate some color planes before committing to nlayers. */ #if 0 if (gp->mode == transparent) { Bool additive_p = True; /* additive init */ int nplanes = gp->nlayers; /* allocate_alpha_colors (display, MI_COLORMAP(mi), &nplanes, additive_p, &plane_masks, &base_pixel); *//* COME BACK */ if (nplanes > 1) gp->nlayers = nplanes; else { (void) fprintf(stderr, "could not allocate any color planes; turning transparency off.\n"); gp->mode = opaque; } } #else if (gp->mode == transparent) gp->mode = opaque; #endif nblobs = MI_COUNT(mi); if (nblobs < 0) { nblobs = NRAND(-nblobs) + 1; /* Add 1 so its not too boring */ } { int *lblobs; int total = DEF_COUNT; if ((lblobs = (int *) calloc(gp->nlayers, sizeof (int))) == NULL) { free_goop(display, gp); return; } if (nblobs <= 0) while (total) for (i = 0; total && i < gp->nlayers; i++) lblobs[i]++, total--; for (i = 0; i < gp->nlayers; i++) if (!make_layer(mi, &(gp->layers[i]), (nblobs > 0 ? nblobs : lblobs[i]))) free_goop(display, gp); free(lblobs); } if (gp->mode == transparent && plane_masks) { for (i = 0; i < gp->nlayers; i++) gp->layers[i].pixel = base_pixel | plane_masks[i]; gp->background = base_pixel; } if (plane_masks != NULL) free(plane_masks); if (gp->mode != transparent) { gp->background = 0; /* init */ for (i = 0; i < gp->nlayers; i++) { if (MI_NPIXELS(mi) > 2) gp->layers[i].pixel = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); else gp->layers[i].pixel = MI_WHITE_PIXEL(mi); } } if ((gp->pixmap = XCreatePixmap(display, window, MI_WIDTH(mi), MI_HEIGHT(mi), (gp->mode == xored ? 1 : MI_DEPTH(mi)))) == None) { free_goop(display, gp); return; } gcv.background = gp->background; gcv.foreground = 255; /* init */ gcv.line_width = 5; /* thickness init */ if ((gp->pixmap_gc = XCreateGC(display, gp->pixmap, GCLineWidth, &gcv)) == None) { free_goop(display, gp); return; } MI_CLEARWINDOW(mi); }