ENTRYPOINT void change_fire(ModeInfo * mi) { firestruct *fs = &fire[MI_SCREEN(mi)]; if (!fs->glx_context) return; glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(fs->glx_context)); /* if available, randomly change some values */ if (do_fog) fs->fog = LRAND() & 1; if (do_shadows) fs->shadows = LRAND() & 1; /* reset observer position */ frame = 0; vinit(fs->obs, DEF_OBS[0], DEF_OBS[1], DEF_OBS[2]); fs->v = 0.0; /* particle randomisation */ fs->eject_r = 0.1 + NRAND(10) * 0.03; fs->ridtri = 0.1 + NRAND(10) * 0.005; if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tnum_part=%d\n\ttrees=%d\n\tfog=%s\n\tshadows=%s\n\teject_r=%.3f\n\tridtri=%.3f\n", MI_NAME(mi), fs->np, fs->num_trees, fs->fog ? "on" : "off", fs->shadows ? "on" : "off", fs->eject_r, fs->ridtri); } }
static Bool Init(ModeInfo * mi) { int i; firestruct *fs = &fire[MI_SCREEN(mi)]; /* default settings */ fs->eject_r = 0.1 + NRAND(10) * 0.03; fs->dt = 0.015; fs->eject_vy = 4; fs->eject_vl = 1; fs->ridtri = 0.1 + NRAND(10) * 0.005; fs->maxage = 1.0 / fs->dt; vinit(fs->obs, DEF_OBS[0], DEF_OBS[1], DEF_OBS[2]); fs->v = 0.0; fs->alpha = DEF_ALPHA; fs->beta = DEF_BETA; /* initialise texture stuff */ if (do_texture) inittextures(mi); else { fs->ttexture = (XImage*) NULL; fs->gtexture = (XImage*) NULL; } if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tnum_part=%d\n\ttrees=%d\n\tfog=%s\n\tshadows=%s\n\teject_r=%.3f\n\tridtri=%.3f\n", MI_NAME(mi), fs->np, fs->num_trees, fs->fog ? "on" : "off", fs->shadows ? "on" : "off", fs->eject_r, fs->ridtri); } /* initialise particles and trees */ for (i = 0; i < fs->np; i++) { setnewpart(fs, &(fs->p[i])); } if (fs->num_trees) if (!inittree(mi)) { return False; } /* if no fire particles then initialise rain particles */ if (!fs->np) { vinit(fs->min,-7.0f,-0.2f,-7.0f); vinit(fs->max,7.0f,8.0f,7.0f); for (i = 0; i < NUMPART; i++) { setnewrain(fs, &(fs->r[i])); } } return True; }
ENTRYPOINT void init_atlantis(ModeInfo * mi) { int screen = MI_SCREEN(mi); atlantisstruct *ap; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); if (atlantis == NULL) { if ((atlantis = (atlantisstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (atlantisstruct))) == NULL) return; } ap = &atlantis[screen]; ap->num_sharks = MI_COUNT(mi); if (ap->sharks == NULL) { if ((ap->sharks = (fishRec *) calloc(ap->num_sharks, sizeof (fishRec))) == NULL) { /* free everything up to now */ (void) free((void *) atlantis); atlantis = NULL; return; } } ap->sharkspeed = MI_CYCLES(mi); /* has influence on the "width" of the movement */ ap->sharksize = MI_SIZE(mi); /* has influence on the "distance" of the sharks */ ap->whalespeed = whalespeed; ap->wire = MI_IS_WIREFRAME(mi); if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tnum_sharks=%d\n\tsharkspeed=%.1f\n\tsharksize=%d\n\twhalespeed=%.1f\n\twireframe=%s\n", MI_NAME(mi), ap->num_sharks, ap->sharkspeed, ap->sharksize, ap->whalespeed, ap->wire ? "yes" : "no" ); } if ((ap->glx_context = init_GL(mi)) != NULL) { reshape_atlantis(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glDrawBuffer(GL_BACK); Init(mi); AllDisplay(ap); glXSwapBuffers(display, window); } else { MI_CLEARWINDOW(mi); } }
void make_uniform_colormap(ModeInfo * mi, Colormap cmap, XColor * colors, int *ncolorsP, Bool allocate_p, Bool * writable_pP) { int ncolors = *ncolorsP; Bool wanted_writable = (allocate_p && writable_pP && *writable_pP); double S = ((double) (LRAND() % 34) + 66) / 100.0; /* range 66%-100% */ double V = ((double) (LRAND() % 34) + 66) / 100.0; /* range 66%-100% */ if (*ncolorsP <= 0) return; /* If this visual doesn't support writable cells, don't bother trying. */ if (wanted_writable && !has_writable_cells(mi)) *writable_pP = False; RETRY_NON_WRITABLE: make_color_ramp(MI_DISPLAY(mi), cmap, 0, S, V, 359, S, V, colors, &ncolors, False, True, wanted_writable); /* If we tried for writable cells and got none, try for non-writable. */ if (allocate_p && *ncolorsP == 0 && writable_pP && *writable_pP) { ncolors = *ncolorsP; *writable_pP = False; goto RETRY_NON_WRITABLE; } if (MI_IS_VERBOSE(mi) || MI_IS_DEBUG(mi)) complain(*ncolorsP, ncolors, wanted_writable, wanted_writable && *writable_pP); *ncolorsP = ncolors; }
ENTRYPOINT void change_sballs(ModeInfo * mi) { sballsstruct *sb; if (sballs == NULL) return; sb = &sballs[MI_SCREEN(mi)]; if (!sb->glx_context) return; /* initialise object number */ if ((object == 0) || (object > MAX_OBJ)) object = NRAND(MAX_OBJ-1)+1; object--; /* correct sphere number */ spheres = MI_COUNT(mi); if (MI_COUNT(mi) > polygons[object].numverts) spheres = polygons[object].numverts; if (MI_COUNT(mi) < 1) spheres = polygons[object].numverts; if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tobject=%s\n\tspheres=%d\n\tspeed=%d\n\ttexture=%s\n", MI_NAME(mi), polygons[object].shortname, spheres, (int) MI_CYCLES(mi), do_texture ? "on" : "off" ); } glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(sb->glx_context)); }
static void Init(ModeInfo * mi) { sballsstruct *sb = &sballs[MI_SCREEN(mi)]; int i; /* Default settings */ if (MI_IS_WIREFRAME(mi)) do_texture = False; if (do_texture) inittextures(mi); else { sb->btexture = (XImage*) NULL; sb->ftexture = (XImage*) NULL; } vinit(sb->eye ,0.0f, 0.0f, 6.0f); vinit(sb->rotm ,0.0f, 0.0f, 0.0f); sb->speed = MI_CYCLES(mi); /* initialise object number */ if ((object == 0) || (object > MAX_OBJ)) object = NRAND(MAX_OBJ-1)+1; object--; /* initialise sphere number */ spheres = MI_COUNT(mi); if (MI_COUNT(mi) > polygons[object].numverts) spheres = polygons[object].numverts; if (MI_COUNT(mi) < 1) spheres = polygons[object].numverts; /* initialise sphere radius */ for(i=0; i < spheres;i++) { #if RANDOM_RADIUS sb->radius[i] = ((float) LRAND() / (float) MAXRAND); if (sb->radius[i] < 0.3) sb->radius[i] = 0.3; if (sb->radius[i] > 0.7) sb->radius[i] = 0.7; #else sb->radius[i] = polygons[object].radius; #endif } if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tobject=%s\n\tspheres=%d\n\tspeed=%d\n\ttexture=%s\n", MI_NAME(mi), polygons[object].shortname, spheres, (int) MI_CYCLES(mi), do_texture ? "on" : "off" ); } glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); glEnable(GL_LIGHT1); }
static Bool Init(ModeInfo * mi) { int i; firestruct *fs = &fire[MI_SCREEN(mi)]; /* default settings */ fs->eject_r = 0.1 + NRAND(10) * 0.03; fs->dt = 0.015; fs->eject_vy = 4; fs->eject_vl = 1; fs->ridtri = 0.1 + NRAND(10) * 0.005; fs->maxage = 1.0 / fs->dt; vinit(fs->obs, DEF_OBS[0], DEF_OBS[1], DEF_OBS[2]); fs->v = 0.0; fs->alpha = DEF_ALPHA; fs->beta = DEF_BETA; /* initialise texture stuff */ if (do_texture) inittextures(mi); else { fs->ttexture = (XImage*) NULL; fs->gtexture = (XImage*) NULL; } if (MI_IS_DEBUG(mi)) { (void) fprintf(stderr, "%s:\n\tnum_part=%d\n\ttrees=%d\n\tfog=%s\n\tshadows=%s\n\teject_r=%.3f\n\tridtri=%.3f\n", MI_NAME(mi), fs->np, fs->num_trees, fs->fog ? "on" : "off", fs->shadows ? "on" : "off", fs->eject_r, fs->ridtri); } glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); /* makes particles blend with background */ if (!MI_IS_WIREFRAME(mi)||(!fs->np)) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } /* fog stuff */ glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_EXP); glFogfv(GL_FOG_COLOR, fogcolor); glFogf(GL_FOG_DENSITY, 0.03); glHint(GL_FOG_HINT, GL_NICEST); /* initialise particles and trees */ for (i = 0; i < fs->np; i++) { setnewpart(fs, &(fs->p[i])); } if (fs->num_trees) if (!inittree(mi)) { return False; } /* if no fire particles then initialise rain particles */ if (!fs->np) { vinit(fs->min,-7.0f,-0.2f,-7.0f); vinit(fs->max,7.0f,8.0f,7.0f); for (i = 0; i < NUMPART; i++) { setnewrain(fs, &(fs->r[i])); } } return True; }
void make_random_colormap(ModeInfo * mi, Colormap cmap, XColor * colors, int *ncolorsP, Bool bright_p, Bool allocate_p, Bool * writable_pP) { Bool wanted_writable = (allocate_p && writable_pP && *writable_pP); int ncolors = *ncolorsP; int i; if (*ncolorsP <= 0) return; /* If this visual doesn't support writable cells, don't bother trying. */ if (wanted_writable && !has_writable_cells(mi)) *writable_pP = False; for (i = 0; i < ncolors; i++) { colors[i].flags = DoRed | DoGreen | DoBlue; if (bright_p) { int H = (int) LRAND() % 360; /* range 0-360 */ double S = ((double) (LRAND() % 70) + 30) / 100.0; /* range 30%-100% */ double V = ((double) (LRAND() % 34) + 66) / 100.0; /* range 66%-100% */ hsv_to_rgb(H, S, V, &colors[i].red, &colors[i].green, &colors[i].blue); } else { colors[i].red = (unsigned short) (LRAND() % 0xFFFF); colors[i].green = (unsigned short) (LRAND() % 0xFFFF); colors[i].blue = (unsigned short) (LRAND() % 0xFFFF); } } if (!allocate_p) return; RETRY_NON_WRITABLE: if (writable_pP && *writable_pP) { unsigned long *pixels = (unsigned long *) malloc(sizeof (unsigned long) * (ncolors + 1)); allocate_writable_colors(MI_DISPLAY(mi), cmap, pixels, &ncolors); if (ncolors > 0) for (i = 0; i < ncolors; i++) colors[i].pixel = pixels[i]; free(pixels); if (ncolors > 0) XStoreColors(MI_DISPLAY(mi), cmap, colors, ncolors); } else { for (i = 0; i < ncolors; i++) { XColor color; color = colors[i]; if (!XAllocColor(MI_DISPLAY(mi), cmap, &color)) break; colors[i].pixel = color.pixel; } ncolors = i; } /* If we tried for writable cells and got none, try for non-writable. */ if (allocate_p && ncolors == 0 && writable_pP && *writable_pP) { ncolors = *ncolorsP; *writable_pP = False; goto RETRY_NON_WRITABLE; } if (MI_IS_VERBOSE(mi) || MI_IS_DEBUG(mi)) complain(*ncolorsP, ncolors, wanted_writable, wanted_writable && *writable_pP); *ncolorsP = ncolors; }
void make_smooth_colormap(ModeInfo * mi, Colormap cmap, XColor * colors, int *ncolorsP, Bool allocate_p, Bool * writable_pP) { int npoints; int ncolors = *ncolorsP; Bool wanted_writable = (allocate_p && writable_pP && *writable_pP); int i; int h[MAXPOINTS]; double s[MAXPOINTS]; double v[MAXPOINTS]; double total_s = 0; double total_v = 0; if (*ncolorsP <= 0) return; { int n = (int) (LRAND() % 20); if (n <= 5) npoints = 2; /* 30% of the time */ else if (n <= 15) npoints = 3; /* 50% of the time */ else if (n <= 18) npoints = 4; /* 15% of the time */ else npoints = 5; /* 5% of the time */ } REPICK_ALL_COLORS: for (i = 0; i < npoints; i++) { REPICK_THIS_COLOR: h[i] = (int) (LRAND() % 360); s[i] = LRAND() / MAXRAND; v[i] = 0.8 * LRAND() / MAXRAND + 0.2; /* Make sure that no two adjascent colors are *too* close together. If they are, try again. */ if (i > 0) { int j = (i + 1 == npoints) ? 0 : (i - 1); double hi = ((double) h[i]) / 360; double hj = ((double) h[j]) / 360; double dh = hj - hi; double distance; if (dh < 0) dh = -dh; if (dh > 0.5) dh = 0.5 - (dh - 0.5); distance = sqrt((dh * dh) + ((s[j] - s[i]) * (s[j] - s[i])) + ((v[j] - v[i]) * (v[j] - v[i]))); if (distance < 0.2) goto REPICK_THIS_COLOR; } total_s += s[i]; total_v += v[i]; } /* If the average saturation or intensity are too low, repick the colors, so that we don't end up with a black-and-white or too-dark map. */ if (total_s / npoints < 0.2) goto REPICK_ALL_COLORS; if (total_v / npoints < 0.3) goto REPICK_ALL_COLORS; /* If this visual doesn't support writable cells, don't bother trying. */ if (wanted_writable && !has_writable_cells(mi)) *writable_pP = False; RETRY_NON_WRITABLE: make_color_path(MI_DISPLAY(mi), cmap, npoints, h, s, v, colors, &ncolors, allocate_p, (writable_pP && *writable_pP)); /* If we tried for writable cells and got none, try for non-writable. */ if (allocate_p && *ncolorsP == 0 && *writable_pP) { *writable_pP = False; goto RETRY_NON_WRITABLE; } if (MI_IS_VERBOSE(mi) || MI_IS_DEBUG(mi)) complain(*ncolorsP, ncolors, wanted_writable, wanted_writable && *writable_pP); *ncolorsP = ncolors; }