static void * ccurve_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); unsigned long int black = 0; int depth = 0; XWindowAttributes hack_attributes; XGCValues values; unsigned long int white = 0; st->dpy = dpy; st->window = window; st->delay = get_float_resource (st->dpy, "delay", "Integer"); st->delay2 = get_float_resource (st->dpy, "pause", "Integer"); st->maximum_lines = get_integer_resource (st->dpy, "limit", "Integer"); black = BlackPixel (st->dpy, DefaultScreen (st->dpy)); white = WhitePixel (st->dpy, DefaultScreen (st->dpy)); st->background = black; XGetWindowAttributes (st->dpy, st->window, &hack_attributes); st->width = hack_attributes.width; st->height = hack_attributes.height; depth = hack_attributes.depth; st->color_map = hack_attributes.colormap; st->pixmap = XCreatePixmap (st->dpy, st->window, st->width, st->height, depth); values.foreground = white; values.background = black; st->context = XCreateGC (st->dpy, st->window, GCForeground | GCBackground, &values); st->color_count = MAXIMUM_COLOR_COUNT; make_color_loop (hack_attributes.screen, hack_attributes.visual, st->color_map, 0, 1, 1, 120, 1, 1, 240, 1, 1, st->colors, &st->color_count, True, False); if (st->color_count <= 0) { st->color_count = 1; st->colors [0].red = st->colors [0].green = st->colors [0].blue = 0xFFFF; XAllocColor (st->dpy, st->color_map, &st->colors [0]); } st->draw_maximum_x = 1.20; st->draw_maximum_y = 0.525; st->draw_minimum_x = -0.20; st->draw_minimum_y = -0.525; st->draw_x2 = 1.0; return st; }
static eraser_state * eraser_init (Display *dpy, Window window) { eraser_state *st = (eraser_state *) calloc (1, sizeof(*st)); XWindowAttributes xgwa; XGCValues gcv; unsigned long fg, bg; double duration; int which; char *s; st->dpy = dpy; st->window = window; XGetWindowAttributes (dpy, window, &xgwa); st->width = xgwa.width; st->height = xgwa.height; bg = get_pixel_resource (dpy, xgwa.colormap, "background", "Background"); fg = get_pixel_resource (dpy, xgwa.colormap, "foreground", "Foreground"); gcv.foreground = fg; gcv.background = bg; st->fg_gc = XCreateGC (dpy, window, GCForeground|GCBackground, &gcv); gcv.foreground = bg; gcv.background = fg; st->bg_gc = XCreateGC (dpy, window, GCForeground|GCBackground, &gcv); # ifdef HAVE_COCOA /* Pretty much all of these leave turds if AA is on. */ jwxyz_XSetAntiAliasing (st->dpy, st->fg_gc, False); jwxyz_XSetAntiAliasing (st->dpy, st->bg_gc, False); # endif s = get_string_resource (dpy, "eraseMode", "Integer"); if (!s || !*s) which = -1; else which = get_integer_resource(dpy, "eraseMode", "Integer"); if (which < 0 || which >= countof(erasers)) which = random() % countof(erasers); st->fn = erasers[which]; duration = get_float_resource (dpy, "eraseSeconds", "Float"); if (duration < 0.1 || duration > 10) duration = 1; st->start_time = double_time(); st->stop_time = st->start_time + duration; XSync (st->dpy, False); return st; }
static void * rocks_init (Display *d, Window w) { struct state *st = (struct state *) calloc (1, sizeof(*st)); int i; XGCValues gcv; Colormap cmap; XWindowAttributes xgwa; unsigned int bg; st->dpy = d; st->window = w; XGetWindowAttributes (st->dpy, st->window, &xgwa); st->width = xgwa.width; st->height = xgwa.height; st->midx = st->width/2; st->midy = st->height/2; cmap = xgwa.colormap; st->delay = get_integer_resource (st->dpy, "delay", "Integer"); if (st->delay < 0) st->delay = 0; st->speed = get_integer_resource (st->dpy, "speed", "Integer"); if (st->speed < 1) st->speed = 1; if (st->speed > 100) st->speed = 100; st->rotate_p = get_boolean_resource (st->dpy, "rotate", "Boolean"); st->move_p = get_boolean_resource (st->dpy, "move", "Boolean"); if (mono_p) st->ncolors = 2; else st->ncolors = get_integer_resource (st->dpy, "colors", "Colors"); if (st->ncolors < 2) { st->ncolors = 2; mono_p = True; } st->colors = (XColor *) malloc(st->ncolors * sizeof(*st->colors)); st->draw_gcs = (GC *) malloc(st->ncolors * sizeof(*st->draw_gcs)); bg = get_pixel_resource (st->dpy, cmap, "background", "Background"); st->colors[0].pixel = bg; st->colors[0].flags = DoRed|DoGreen|DoBlue; XQueryColor(st->dpy, cmap, &st->colors[0]); st->ncolors--; make_random_colormap(xgwa.screen, xgwa.visual, cmap, st->colors+1, &st->ncolors, True, True, 0, True); st->ncolors++; if (st->ncolors < 2) { st->ncolors = 2; mono_p = True; } if (mono_p) { unsigned int fg = get_pixel_resource(st->dpy, cmap, "foreground", "Foreground"); st->colors[1].pixel = fg; st->colors[1].flags = DoRed|DoGreen|DoBlue; XQueryColor(st->dpy, cmap, &st->colors[1]); gcv.foreground = fg; gcv.background = bg; st->draw_gcs[0] = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcv); st->draw_gcs[1] = st->draw_gcs[0]; } else for( i = 0; i < st->ncolors; i++ ) { gcv.foreground = st->colors[i].pixel; gcv.background = bg; st->draw_gcs[i] = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcv); } gcv.foreground = bg; st->erase_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground, &gcv); st->max_dep = (st->move_p ? MAX_DEP : 0); for (i = 0; i < SIN_RESOLUTION; i++) { st->sins [i] = sin ((((double) i) / (SIN_RESOLUTION / 2)) * M_PI); st->coss [i] = cos ((((double) i) / (SIN_RESOLUTION / 2)) * M_PI); } /* we actually only need i/speed of these, but wtf */ for (i = 1; i < (sizeof (st->depths) / sizeof (st->depths[0])); i++) st->depths [i] = atan (((double) 0.5) / (((double) i) / DEPTH_SCALE)); st->depths [0] = M_PI/2; /* avoid division by 0 */ st->threed = get_boolean_resource(st->dpy, "use3d", "Boolean"); if (st->threed) { gcv.background = bg; gcv.foreground = get_pixel_resource (st->dpy, cmap, "left3d", "Foreground"); st->threed_left_gc = XCreateGC (st->dpy, st->window, GCForeground|GCBackground,&gcv); gcv.foreground = get_pixel_resource (st->dpy, cmap, "right3d", "Foreground"); st->threed_right_gc = XCreateGC (st->dpy, st->window,GCForeground|GCBackground,&gcv); st->threed_delta = get_float_resource(st->dpy, "delta3d", "Integer"); } /* don't want any exposure events from XCopyPlane */ for( i = 0; i < st->ncolors; i++) XSetGraphicsExposures (st->dpy, st->draw_gcs[i], False); XSetGraphicsExposures (st->dpy, st->erase_gc, False); st->nrocks = get_integer_resource (st->dpy, "count", "Count"); if (st->nrocks < 1) st->nrocks = 1; st->rocks = (struct rock *) calloc (st->nrocks, sizeof (struct rock)); init_pixmaps (st); XClearWindow (st->dpy, st->window); return st; }
static void hexadrop_init_1 (Display *dpy, Window window, state *st) { XGCValues gcv; char *s1, *s2; st->dpy = dpy; st->window = window; st->delay = get_integer_resource (st->dpy, "delay", "Integer"); st->ncolors = get_integer_resource (st->dpy, "ncolors", "Integer"); st->speed = get_float_resource (st->dpy, "speed", "Speed"); if (st->speed < 0) st->speed = 0; XGetWindowAttributes (st->dpy, st->window, &st->xgwa); if (st->ncolors < 2) st->ncolors = 2; st->colors = (XColor *) calloc (sizeof(*st->colors), st->ncolors); if (st->ncolors < 10) make_random_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, False, True, 0, True); else make_smooth_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, True, 0, True); XSetWindowBackground (dpy, window, st->colors[0].pixel); s1 = get_string_resource (st->dpy, "uniform", "Uniform"); s2 = get_string_resource (st->dpy, "lockstep", "Lockstep"); if ((!s1 || !*s1 || !strcasecmp(s1, "maybe")) && (!s2 || !*s2 || !strcasecmp(s2, "maybe"))) { /* When being random, don't do both. */ st->uniform_p = random() & 1; st->lockstep_p = st->uniform_p ? 0 : random() & 1; } else { if (!s1 || !*s1 || !strcasecmp(s1, "maybe")) st->uniform_p = random() & 1; else st->uniform_p = get_boolean_resource (st->dpy, "uniform", "Uniform"); if (!s2 || !*s2 || !strcasecmp(s2, "maybe")) st->lockstep_p = random() & 1; else st->lockstep_p = get_boolean_resource (st->dpy, "lockstep","Lockstep"); } st->sides = get_integer_resource (st->dpy, "sides", "Sides"); if (! (st->sides == 0 || st->sides == 3 || st->sides == 4 || st->sides == 6 || st->sides == 8)) { printf ("%s: invalid number of sides: %d\n", progname, st->sides); st->sides = 0; } if (! st->sides) { static int defs[] = { 3, 3, 3, 4, 6, 6, 6, 6, 8, 8, 8 }; st->sides = defs[random() % countof(defs)]; } make_cells (st); gcv.foreground = st->colors[0].pixel; st->gc = XCreateGC (dpy, window, GCForeground, &gcv); }
static Bool InitializeAll(struct state *st) { XGCValues xgcv; XWindowAttributes xgwa; /* XSetWindowAttributes xswa;*/ Colormap cmap; XColor color; int n,i; double rspeed; st->cosilines = True; XGetWindowAttributes(st->dpy,st->win[0],&xgwa); cmap=xgwa.colormap; /* xswa.backing_store=Always; XChangeWindowAttributes(st->dpy,st->win[0],CWBackingStore,&xswa);*/ xgcv.function=GXcopy; xgcv.foreground=get_pixel_resource (st->dpy, cmap, "background", "Background"); st->fgc[32]=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); n=0; if (mono_p) { st->fgc[0]=st->fgc[32]; xgcv.foreground=get_pixel_resource (st->dpy, cmap, "foreground", "Foreground"); st->fgc[1]=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); for (i=0;i<32;i+=2) st->fgc[i]=st->fgc[0]; for (i=1;i<32;i+=2) st->fgc[i]=st->fgc[1]; } else for (i=0;i<32;i++) { color.red=colors[n++]<<8; color.green=colors[n++]<<8; color.blue=colors[n++]<<8; color.flags=DoRed|DoGreen|DoBlue; XAllocColor(st->dpy,cmap,&color); xgcv.foreground=color.pixel; st->fgc[i]=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); } st->cgc=XCreateGC(st->dpy,st->win[0],GCForeground|GCFunction,&xgcv); XSetGraphicsExposures(st->dpy,st->cgc,False); st->cosilines = get_boolean_resource(st->dpy, "random","Boolean"); #ifdef HAVE_DOUBLE_BUFFER_EXTENSION if (get_boolean_resource (st->dpy, "useDBE", "Boolean")) st->usedouble = True; st->win[1] = xdbe_get_backbuffer (st->dpy, st->win[0], XdbeUndefined); if (!st->win[1]) { st->usedouble = False; st->win[1] = st->win[0]; } #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ st->delay=get_integer_resource(st->dpy, "delay","Integer"); rspeed=get_float_resource(st->dpy, "speed","Float"); if (rspeed<0.0001 || rspeed>0.2) { fprintf(stderr,"Speed not in valid range! (0.0001 - 0.2), using 0.1 \n"); rspeed=0.1; } st->sizx=xgwa.width; st->sizy=xgwa.height; st->midx=st->sizx>>1; st->midy=st->sizy>>1; st->stateX=0; st->stateY=0; if (!make_rots(st,rspeed,rspeed)) { fprintf(stderr,"Not enough memory for tables!\n"); return False; } return True; }
static struct starfish * make_starfish (struct state *st, int maxx, int maxy, int size) { struct starfish *s = (struct starfish *) calloc(1, sizeof(*s)); int i; s->blob_p = st->blob_p; s->elasticity = SCALE * get_float_resource (st->dpy, "thickness", "Thickness"); if (s->elasticity == 0) /* bell curve from 0-15, avg 7.5 */ s->elasticity = RAND(5*SCALE) + RAND(5*SCALE) + RAND(5*SCALE); s->rotv = get_float_resource (st->dpy, "rotation", "Rotation"); if (s->rotv == -1) /* bell curve from 0-12 degrees, avg 6 */ s->rotv = frand(4) + frand(4) + frand(4); s->rotv /= 360; /* convert degrees to ratio */ if (s->blob_p) { s->elasticity *= 3; s->rotv *= 3; } s->rot_max = s->rotv * 2; s->rota = 0.0004 + frand(0.0002); if (! (random() % 20)) size *= frand(0.35) + frand(0.35) + 0.3; { static const char skips[] = { 2, 2, 2, 2, 3, 3, 3, 6, 6, 12 }; s->skip = skips[random() % sizeof(skips)]; } if (! (random() % (s->skip == 2 ? 3 : 12))) s->mode = zoom; else s->mode = pulse; maxx *= SCALE; maxy *= SCALE; size *= SCALE; s->max_r = size; s->min_r = 0; if (s->min_r < (5*SCALE)) s->min_r = (5*SCALE); s->x = maxx/2; s->y = maxy/2; s->th = frand(M_PI+M_PI) * RANDSIGN(); { static const char sizes[] = { 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 8, 8, 8, 10, 35 }; int nsizes = sizeof(sizes); if (s->skip > 3) nsizes -= 4; s->npoints = s->skip * sizes[random() % nsizes]; } s->spline = make_spline (s->npoints); s->r = (long *) malloc (sizeof(*s->r) * s->npoints); for (i = 0; i < s->npoints; i++) s->r[i] = ((i % s->skip) == 0) ? 0 : size; return s; }
/* initialize the user-specifiable params */ static void initParams (struct state *st) { int problems = 0; st->delay = get_integer_resource (st->dpy, "delay", "Delay"); if (st->delay < 0) { fprintf (stderr, "error: delay must be at least 0\n"); problems = 1; } st->maxIters = get_integer_resource (st->dpy, "maxIters", "Integer"); if (st->maxIters < 0) { fprintf (stderr, "error: maxIters must be at least 0\n"); problems = 1; } st->doubleBuffer = get_boolean_resource (st->dpy, "doubleBuffer", "Boolean"); # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ st->doubleBuffer = False; # endif st->requestedBlotCount = get_integer_resource (st->dpy, "count", "Count"); if (st->requestedBlotCount <= 0) { fprintf (stderr, "error: count must be at least 0\n"); problems = 1; } st->colorCount = get_integer_resource (st->dpy, "colors", "Colors"); if (st->colorCount <= 0) { fprintf (stderr, "error: colors must be at least 1\n"); problems = 1; } st->lineWidth = get_integer_resource (st->dpy, "lineWidth", "LineWidth"); if (st->lineWidth < 0) { fprintf (stderr, "error: line width must be at least 0\n"); problems = 1; } st->nervousness = get_float_resource (st->dpy, "nervousness", "Float"); if ((st->nervousness < 0) || (st->nervousness > 1)) { fprintf (stderr, "error: nervousness must be in the range 0..1\n"); problems = 1; } st->maxNerveRadius = get_float_resource (st->dpy, "maxNerveRadius", "Float"); if ((st->maxNerveRadius < 0) || (st->maxNerveRadius > 1)) { fprintf (stderr, "error: maxNerveRadius must be in the range 0..1\n"); problems = 1; } st->eventChance = get_float_resource (st->dpy, "eventChance", "Float"); if ((st->eventChance < 0) || (st->eventChance > 1)) { fprintf (stderr, "error: eventChance must be in the range 0..1\n"); problems = 1; } st->iterAmt = get_float_resource (st->dpy, "iterAmt", "Float"); if ((st->iterAmt < 0) || (st->iterAmt > 1)) { fprintf (stderr, "error: iterAmt must be in the range 0..1\n"); problems = 1; } st->minScale = get_float_resource (st->dpy, "minScale", "Float"); if ((st->minScale < 0) || (st->minScale > 10)) { fprintf (stderr, "error: minScale must be in the range 0..10\n"); problems = 1; } st->maxScale = get_float_resource (st->dpy, "maxScale", "Float"); if ((st->maxScale < 0) || (st->maxScale > 10)) { fprintf (stderr, "error: maxScale must be in the range 0..10\n"); problems = 1; } if (st->maxScale < st->minScale) { fprintf (stderr, "error: maxScale must be >= minScale\n"); problems = 1; } st->minRadius = get_integer_resource (st->dpy, "minRadius", "Integer"); if ((st->minRadius < 1) || (st->minRadius > 100)) { fprintf (stderr, "error: minRadius must be in the range 1..100\n"); problems = 1; } st->maxRadius = get_integer_resource (st->dpy, "maxRadius", "Integer"); if ((st->maxRadius < 1) || (st->maxRadius > 100)) { fprintf (stderr, "error: maxRadius must be in the range 1..100\n"); problems = 1; } if (st->maxRadius < st->minRadius) { fprintf (stderr, "error: maxRadius must be >= minRadius\n"); problems = 1; } if (problems) { exit (1); } }
static void setup_display (struct state *st) { XWindowAttributes xgwa; int cell_size = get_integer_resource (st->dpy, "size", "Integer"); int osize, alloc_size, oalloc; int mem_throttle = 0; char *s; if (cell_size < 1) cell_size = 1; osize = cell_size; s = get_string_resource (st->dpy, "memThrottle", "MemThrottle"); if (s) { int n; char c; if (1 == sscanf (s, " %d M %c", &n, &c) || 1 == sscanf (s, " %d m %c", &n, &c)) mem_throttle = n * (1 << 20); else if (1 == sscanf (s, " %d K %c", &n, &c) || 1 == sscanf (s, " %d k %c", &n, &c)) mem_throttle = n * (1 << 10); else if (1 == sscanf (s, " %d %c", &n, &c)) mem_throttle = n; else { fprintf (stderr, "%s: invalid memThrottle \"%s\" (try \"10M\")\n", progname, s); exit (1); } free (s); } XGetWindowAttributes (st->dpy, st->window, &xgwa); st->originalcolors = get_boolean_resource (st->dpy, "originalcolors", "Boolean"); st->count = get_integer_resource (st->dpy, "count", "Integer"); if (st->count < 2) st->count = 2; /* number of colors can't be greater than the half depth of the screen. */ if (st->count > (unsigned int) (1L << (xgwa.depth-1))) st->count = (unsigned int) (1L << (xgwa.depth-1)); /* Actually, since cell->col is of type char, this has to be small. */ if (st->count >= (unsigned int) (1L << ((sizeof(st->arr[0].col) * 8) - 1))) st->count = (unsigned int) (1L << ((sizeof(st->arr[0].col) * 8) - 1)); if (st->originalcolors && (st->count > 8)) { st->count = 8; } st->coloredGCs = (GC *) calloc (sizeof(GC), st->count * 2); st->diaglim = get_float_resource (st->dpy, "diaglim", "Float"); if (st->diaglim < 1.0) { st->diaglim = 1.0; } else if (st->diaglim > 2.0) { st->diaglim = 2.0; } st->diaglim *= st->orthlim; st->anychan = get_float_resource (st->dpy, "anychan", "Float"); if (st->anychan < 0.0) { st->anychan = 0.0; } else if (st->anychan > 1.0) { st->anychan = 1.0; } st->minorchan = get_float_resource (st->dpy, "minorchan","Float"); if (st->minorchan < 0.0) { st->minorchan = 0.0; } else if (st->minorchan > 1.0) { st->minorchan = 1.0; } st->instantdeathchan = get_float_resource (st->dpy, "instantdeathchan","Float"); if (st->instantdeathchan < 0.0) { st->instantdeathchan = 0.0; } else if (st->instantdeathchan > 1.0) { st->instantdeathchan = 1.0; } st->minlifespan = get_integer_resource (st->dpy, "minlifespan", "Integer"); if (st->minlifespan < 1) { st->minlifespan = 1; } st->maxlifespan = get_integer_resource (st->dpy, "maxlifespan", "Integer"); if (st->maxlifespan < st->minlifespan) { st->maxlifespan = st->minlifespan; } st->minlifespeed = get_float_resource (st->dpy, "minlifespeed", "Float"); if (st->minlifespeed < 0.0) { st->minlifespeed = 0.0; } else if (st->minlifespeed > 1.0) { st->minlifespeed = 1.0; } st->maxlifespeed = get_float_resource (st->dpy, "maxlifespeed", "Float"); if (st->maxlifespeed < st->minlifespeed) { st->maxlifespeed = st->minlifespeed; } else if (st->maxlifespeed > 1.0) { st->maxlifespeed = 1.0; } st->mindeathspeed = get_float_resource (st->dpy, "mindeathspeed", "Float"); if (st->mindeathspeed < 0.0) { st->mindeathspeed = 0.0; } else if (st->mindeathspeed > 1.0) { st->mindeathspeed = 1.0; } st->maxdeathspeed = get_float_resource (st->dpy, "maxdeathspeed", "Float"); if (st->maxdeathspeed < st->mindeathspeed) { st->maxdeathspeed = st->mindeathspeed; } else if (st->maxdeathspeed > 1.0) { st->maxdeathspeed = 1.0; } st->minlifespeed *= st->diaglim; st->maxlifespeed *= st->diaglim; st->mindeathspeed *= st->diaglim; st->maxdeathspeed *= st->diaglim; st->windowWidth = xgwa.width; st->windowHeight = xgwa.height; st->arr_width = st->windowWidth / cell_size; st->arr_height = st->windowHeight / cell_size; alloc_size = sizeof(cell) * st->arr_width * st->arr_height; oalloc = alloc_size; if (mem_throttle > 0) while (cell_size < st->windowWidth/10 && cell_size < st->windowHeight/10 && alloc_size > mem_throttle) { cell_size++; st->arr_width = st->windowWidth / cell_size; st->arr_height = st->windowHeight / cell_size; alloc_size = sizeof(cell) * st->arr_width * st->arr_height; } if (osize != cell_size) { if (!st->warned) { fprintf (stderr, "%s: throttling cell size from %d to %d because of %dM limit.\n", progname, osize, cell_size, mem_throttle / (1 << 20)); fprintf (stderr, "%s: %dx%dx%d = %.1fM, %dx%dx%d = %.1fM.\n", progname, st->windowWidth, st->windowHeight, osize, ((float) oalloc) / (1 << 20), st->windowWidth, st->windowHeight, cell_size, ((float) alloc_size) / (1 << 20)); st->warned = 1; } } st->xSize = st->arr_width ? st->windowWidth / st->arr_width : 0; st->ySize = st->arr_height ? st->windowHeight / st->arr_height : 0; if (st->xSize > st->ySize) { st->xSize = st->ySize; } else { st->ySize = st->xSize; } st->xOffset = (st->windowWidth - (st->arr_width * st->xSize)) / 2; st->yOffset = (st->windowHeight - (st->arr_height * st->ySize)) / 2; if (st->originalcolors) { setup_original_colormap (st, &xgwa); } else { setup_random_colormap (st, &xgwa); } }
static void * anemone_init (Display *disp, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); XWindowAttributes wa; st->dpy = disp; st->turn = 0.; st->width = get_integer_resource(st->dpy, "width", "Integer"); st->arms = get_integer_resource(st->dpy, "arms", "Integer"); st->finpoints = get_integer_resource(st->dpy, "finpoints", "Integer"); st->delay = get_integer_resource(st->dpy, "delay", "Integer"); st->withdraw = get_integer_resource(st->dpy, "withdraw", "Integer"); st->turndelta = get_float_resource(st->dpy, "turnspeed", "float") / 100000; st->dbuf = TRUE; # ifdef HAVE_JWXYZ /* Don't second-guess Quartz's double-buffering */ st->dbuf = False; # endif st->b = st->ba = st->bb = 0; /* double-buffer to reduce flicker */ #ifdef HAVE_DOUBLE_BUFFER_EXTENSION st->b = st->backb = xdbe_get_backbuffer (st->dpy, window, XdbeUndefined); #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ XGetWindowAttributes(st->dpy, window, &wa); st->scrWidth = wa.width; st->scrHeight = wa.height; st->cmap = wa.colormap; st->ncolors = get_integer_resource (st->dpy, "colors", "Colors"); st->ncolors += 3; st->colors = (XColor *) malloc(sizeof(*st->colors) * (st->ncolors+1)); make_smooth_colormap (wa.screen, wa.visual, st->cmap, st->colors, &st->ncolors, True, 0, True); st->gcDraw = XCreateGC(st->dpy, window, 0, &st->gcv); st->gcv.foreground = get_pixel_resource(st->dpy, st->cmap, "background", "Background"); st->gcClear = XCreateGC(st->dpy, window, GCForeground, &st->gcv); if (st->dbuf) { if (!st->b) { st->ba = XCreatePixmap (st->dpy, window, st->scrWidth, st->scrHeight, wa.depth); st->bb = XCreatePixmap (st->dpy, window, st->scrWidth, st->scrHeight, wa.depth); st->b = st->ba; } } else { st->b = window; } if (st->ba) XFillRectangle (st->dpy, st->ba, st->gcClear, 0, 0, st->scrWidth, st->scrHeight); if (st->bb) XFillRectangle (st->dpy, st->bb, st->gcClear, 0, 0, st->scrWidth, st->scrHeight); XClearWindow(st->dpy, window); XSetLineAttributes(st->dpy, st->gcDraw, st->width, LineSolid, CapRound, JoinBevel); initAppendages(st); return st; }
static void * halftone_init (Display *dpy, Window window) { int x, y, i; int count; int spacing; double factor; double min_mass; double max_mass; double min_speed; double max_speed; XGCValues gc_values; XWindowAttributes attrs; halftone_screen *halftone; halftone = (halftone_screen *) calloc (1, sizeof(halftone_screen)); halftone->dpy = dpy; halftone->window = window; halftone->delay = get_integer_resource (dpy, "delay", "Integer"); halftone->delay = (halftone->delay < 0 ? DEFAULT_DELAY : halftone->delay); halftone->gc = XCreateGC (halftone->dpy, halftone->window, 0, &gc_values); halftone->buffer_width = -1; halftone->buffer_height = -1; halftone->dots = NULL; /* Read command line arguments and set all settings. */ count = get_integer_resource (dpy, "count", "Count"); halftone->gravity_point_count = count < 1 ? DEFAULT_COUNT : count; spacing = get_integer_resource (dpy, "spacing", "Integer"); halftone->spacing = spacing < 1 ? DEFAULT_SPACING : spacing; factor = get_float_resource (dpy, "sizeFactor", "Double"); halftone->max_dot_size = (factor < 0 ? DEFAULT_SIZE_FACTOR : factor) * halftone->spacing; min_mass = get_float_resource (dpy, "minMass", "Double"); min_mass = min_mass < 0 ? DEFAULT_MIN_MASS : min_mass; max_mass = get_float_resource (dpy, "maxMass", "Double"); max_mass = max_mass < 0 ? DEFAULT_MAX_MASS : max_mass; max_mass = max_mass < min_mass ? min_mass : max_mass; min_speed = get_float_resource (dpy, "minSpeed", "Double"); min_speed = min_speed < 0 ? DEFAULT_MIN_SPEED : min_speed; max_speed = get_float_resource (dpy, "maxSpeed", "Double"); max_speed = max_speed < 0 ? DEFAULT_MAX_SPEED : max_speed; max_speed = max_speed < min_speed ? min_speed : max_speed; /* Set up the moving gravity points. */ halftone->gravity_point_x = (double *) malloc(halftone->gravity_point_count * sizeof(double)); halftone->gravity_point_y = (double *) malloc(halftone->gravity_point_count * sizeof(double)); halftone->gravity_point_mass = (double *) malloc(halftone->gravity_point_count * sizeof(double)); halftone->gravity_point_x_inc = (double *) malloc(halftone->gravity_point_count * sizeof(double)); halftone->gravity_point_y_inc = (double *) malloc(halftone->gravity_point_count * sizeof(double)); for (i = 0; i < halftone->gravity_point_count; i++) { halftone->gravity_point_x[i] = frand(1); halftone->gravity_point_y[i] = frand(1); halftone->gravity_point_mass[i] = min_mass + (max_mass - min_mass) * frand(1); halftone->gravity_point_x_inc[i] = min_speed + (max_speed - min_speed) * frand(1); halftone->gravity_point_y_inc[i] = min_speed + (max_speed - min_speed) * frand(1); } /* Set up the dots. */ XGetWindowAttributes(halftone->dpy, halftone->window, &attrs); halftone->ncolors = get_integer_resource (dpy, "colors", "Colors"); if (halftone->ncolors < 4) halftone->ncolors = 4; halftone->colors = (XColor *) calloc(halftone->ncolors, sizeof(XColor)); make_smooth_colormap (attrs.screen, attrs.visual, attrs.colormap, halftone->colors, &halftone->ncolors, True, 0, False); halftone->color0 = 0; halftone->color1 = halftone->ncolors / 2; halftone->cycle_speed = get_integer_resource (dpy, "cycleSpeed", "CycleSpeed"); halftone->color_tick = 0; update_buffer(halftone, &attrs); update_dot_attributes(halftone, &attrs); for (x = 0; x < halftone->dots_width; x++) for (y = 0; y < halftone->dots_height; y++) { halftone->dots[x + y * halftone->dots_width] = 0; } return halftone; }
static void * fontglide_init (Display *dpy, Window window) { XGCValues gcv; state *s = (state *) calloc (1, sizeof(*s)); s->dpy = dpy; s->window = window; s->frame_delay = get_integer_resource (dpy, "delay", "Integer"); XGetWindowAttributes (s->dpy, s->window, &s->xgwa); s->font_override = get_string_resource (dpy, "font", "Font"); if (s->font_override && (!*s->font_override || *s->font_override == '(')) s->font_override = 0; s->charset = get_string_resource (dpy, "fontCharset", "FontCharset"); s->border_width = get_integer_resource (dpy, "fontBorderWidth", "Integer"); if (s->border_width < 0 || s->border_width > 20) s->border_width = 1; s->speed = get_float_resource (dpy, "speed", "Float"); if (s->speed <= 0 || s->speed > 200) s->speed = 1; s->linger = get_float_resource (dpy, "linger", "Float"); if (s->linger <= 0 || s->linger > 200) s->linger = 1; s->trails_p = get_boolean_resource (dpy, "trails", "Trails"); s->debug_p = get_boolean_resource (dpy, "debug", "Debug"); s->debug_metrics_p = (get_boolean_resource (dpy, "debugMetrics", "Debug") ? 'y' : 0); s->dbuf = get_boolean_resource (dpy, "doubleBuffer", "Boolean"); # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ s->dbuf = False; # endif if (s->trails_p) s->dbuf = False; /* don't need it in this case */ { char *ss = get_string_resource (dpy, "mode", "Mode"); if (!ss || !*ss || !strcasecmp (ss, "random")) s->mode = ((random() % 2) ? SCROLL : PAGE); else if (!strcasecmp (ss, "scroll")) s->mode = SCROLL; else if (!strcasecmp (ss, "page")) s->mode = PAGE; else { fprintf (stderr, "%s: `mode' must be `scroll', `page', or `random', not `%s'\n", progname, ss); } } if (s->dbuf) { #ifdef HAVE_DOUBLE_BUFFER_EXTENSION s->dbeclear_p = get_boolean_resource (dpy, "useDBEClear", "Boolean"); if (s->dbeclear_p) s->b = xdbe_get_backbuffer (dpy, window, XdbeBackground); else s->b = xdbe_get_backbuffer (dpy, window, XdbeUndefined); s->backb = s->b; #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ if (!s->b) { s->ba = XCreatePixmap (s->dpy, s->window, s->xgwa.width, s->xgwa.height, s->xgwa.depth); s->b = s->ba; } } else { s->b = s->window; } gcv.foreground = get_pixel_resource (s->dpy, s->xgwa.colormap, "background", "Background"); s->bg_gc = XCreateGC (s->dpy, s->b, GCForeground, &gcv); s->subproc_relaunch_delay = 2 * 1000; if (! s->debug_metrics_p) launch_text_generator (s); s->nsentences = 5; /* #### */ s->sentences = (sentence **) calloc (s->nsentences, sizeof (sentence *)); s->spawn_p = True; return s; }
static void inter_init(Display* dpy, Window win, struct inter_context* c) { XWindowAttributes xgwa; double H[3], S[3], V[3]; int i; int mono; int gray; XGCValues val; unsigned long valmask = 0; Bool dbuf = get_boolean_resource (dpy, "doubleBuffer", "Boolean"); # ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ dbuf = False; # endif memset (c, 0, sizeof(*c)); c->dpy = dpy; c->win = win; c->delay = get_integer_resource(dpy, "delay", "Integer"); XGetWindowAttributes(c->dpy, c->win, &xgwa); c->w = xgwa.width; c->h = xgwa.height; c->cmap = xgwa.colormap; #ifdef HAVE_XSHM_EXTENSION c->use_shm = get_boolean_resource(dpy, "useSHM", "Boolean"); #endif /* HAVE_XSHM_EXTENSION */ if (dbuf) { #ifdef HAVE_DOUBLE_BUFFER_EXTENSION c->back_buf = xdbe_get_backbuffer (c->dpy, c->win, XdbeUndefined); #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ #ifdef HAVE_DOUBLE_BUFFER_EXTENSION if (!c->back_buf) #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ c->pix_buf = XCreatePixmap (dpy, win, xgwa.width, xgwa.height, xgwa.depth); } val.function = GXcopy; c->copy_gc = XCreateGC(c->dpy, TARGET(c), GCFunction, &val); c->count = get_integer_resource(dpy, "count", "Integer"); if(c->count < 1) c->count = 1; c->grid_size = get_integer_resource(dpy, "gridsize", "Integer"); if(c->grid_size < 1) c->grid_size = 1; mono = get_boolean_resource(dpy, "mono", "Boolean"); if(!mono) { c->colors = get_integer_resource(dpy, "ncolors", "Integer"); if(c->colors < 2) c->colors = 2; } c->hue = get_integer_resource(dpy, "hue", "Float"); while (c->hue < 0 || c->hue >= 360) c->hue = frand(360.0); c->speed = get_integer_resource(dpy, "speed", "Integer"); c->shift = get_float_resource(dpy, "color-shift", "Float"); while(c->shift >= 360.0) c->shift -= 360.0; while(c->shift <= -360.0) c->shift += 360.0; c->radius = get_integer_resource(dpy, "radius", "Integer");; if(c->radius < 1) c->radius = 1; #ifdef USE_XIMAGE c->ximage = 0; # ifdef HAVE_XSHM_EXTENSION if (c->use_shm) { c->ximage = create_xshm_image(dpy, xgwa.visual, xgwa.depth, ZPixmap, 0, &c->shm_info, xgwa.width, c->grid_size); if (!c->ximage) c->use_shm = False; } # endif /* HAVE_XSHM_EXTENSION */ if (!c->ximage) { c->ximage = XCreateImage (dpy, xgwa.visual, xgwa.depth, ZPixmap, 0, 0, /* depth, fmt, offset, data */ xgwa.width, c->grid_size, /* width, height */ 8, 0); /* pad, bpl */ c->ximage->data = (unsigned char *) calloc(c->ximage->height, c->ximage->bytes_per_line); } #endif /* USE_XIMAGE */ if(!mono) { c->pal = calloc(c->colors, sizeof(XColor)); gray = get_boolean_resource(dpy, "gray", "Boolean"); if(!gray) { H[0] = c->hue; H[1] = H[0] + c->shift < 360.0 ? H[0]+c->shift : H[0] + c->shift-360.0; H[2] = H[1] + c->shift < 360.0 ? H[1]+c->shift : H[1] + c->shift-360.0; S[0] = S[1] = S[2] = 1.0; V[0] = V[1] = V[2] = 1.0; } else { H[0] = H[1] = H[2] = 0.0; S[0] = S[1] = S[2] = 0.0; V[0] = 1.0; V[1] = 0.5; V[2] = 0.0; } make_color_loop(c->dpy, c->cmap, H[0], S[0], V[0], H[1], S[1], V[1], H[2], S[2], V[2], c->pal, &(c->colors), True, False); if(c->colors < 2) { /* color allocation failure */ mono = 1; free(c->pal); } } if(mono) { /* DON'T else this with the previous if! */ c->colors = 2; c->pal = calloc(2, sizeof(XColor)); c->pal[0].pixel = BlackPixel(c->dpy, DefaultScreen(c->dpy)); c->pal[1].pixel = WhitePixel(c->dpy, DefaultScreen(c->dpy)); } valmask = GCForeground; c->gcs = calloc(c->colors, sizeof(GC)); for(i = 0; i < c->colors; i++) { val.foreground = c->pal[i].pixel; c->gcs[i] = XCreateGC(c->dpy, TARGET(c), valmask, &val); } c->wave_height = calloc(c->radius, sizeof(int)); for(i = 0; i < c->radius; i++) { float max = ((float)c->colors) * ((float)c->radius - (float)i) / ((float)c->radius); c->wave_height[i] = (int) ((max + max*cos((double)i/50.0)) / 2.0); } c->source = calloc(c->count, sizeof(struct inter_source)); for(i = 0; i < c->count; i++) { c->source[i].x_theta = frand(2.0)*3.14159; c->source[i].y_theta = frand(2.0)*3.14159; } }
/* initialize the user-specifiable params */ static void initParams (struct state *st) { int problems = 0; st->borderWidth = get_integer_resource (st->dpy, "borderWidth", "Integer"); if (st->borderWidth < 0) { fprintf (stderr, "error: border width must be at least 0\n"); problems = 1; } st->delay = get_integer_resource (st->dpy, "delay", "Delay"); if (st->delay < 0) { fprintf (stderr, "error: delay must be at least 0\n"); problems = 1; } st->duration = get_integer_resource (st->dpy, "duration", "Seconds"); if (st->duration < 1) st->duration = 1; st->eventChance = get_float_resource (st->dpy, "eventChance", "Double"); if ((st->eventChance < 0.0) || (st->eventChance > 1.0)) { fprintf (stderr, "error: eventChance must be in the range 0..1\n"); problems = 1; } st->friction = get_float_resource (st->dpy, "friction", "Double"); if ((st->friction < 0.0) || (st->friction > 1.0)) { fprintf (stderr, "error: friction must be in the range 0..1\n"); problems = 1; } st->maxColumns = get_integer_resource (st->dpy, "maxColumns", "Integer"); if (st->maxColumns < 0) { fprintf (stderr, "error: max columns must be at least 0\n"); problems = 1; } st->maxRows = get_integer_resource (st->dpy, "maxRows", "Integer"); if (st->maxRows < 0) { fprintf (stderr, "error: max rows must be at least 0\n"); problems = 1; } st->springiness = get_float_resource (st->dpy, "springiness", "Double"); if ((st->springiness < 0.0) || (st->springiness > 1.0)) { fprintf (stderr, "error: springiness must be in the range 0..1\n"); problems = 1; } st->tileSize = get_integer_resource (st->dpy, "tileSize", "Integer"); if (st->tileSize < 1) { fprintf (stderr, "error: tile size must be at least 1\n"); problems = 1; } st->transference = get_float_resource (st->dpy, "transference", "Double"); if ((st->transference < 0.0) || (st->transference > 1.0)) { fprintf (stderr, "error: transference must be in the range 0..1\n"); problems = 1; } if (problems) { exit (1); } }
ENTRYPOINT void init_logo (ModeInfo *mi) { logo_configuration *dc; int do_gasket = get_boolean_resource(mi->dpy, "doGasket", "Boolean"); int do_helix = get_boolean_resource(mi->dpy, "doHelix", "Boolean"); int do_ladder = do_helix && get_boolean_resource(mi->dpy, "doLadder", "Boolean"); if (!do_gasket && !do_helix) { fprintf (stderr, "%s: no helix or gasket?\n", progname); exit (1); } if (!dcs) { dcs = (logo_configuration *) calloc (MI_NUM_SCREENS(mi), sizeof (logo_configuration)); if (!dcs) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } } dc = &dcs[MI_SCREEN(mi)]; if ((dc->glx_context = init_GL(mi)) != NULL) { gl_init(mi); reshape_logo (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); } dc->wall_facets = get_integer_resource(mi->dpy, "wallFacets", "Integer"); dc->tube_facets = get_integer_resource(mi->dpy, "tubeFacets", "Integer"); dc->clockwise = get_boolean_resource(mi->dpy, "clockwise", "Boolean"); dc->turns = get_float_resource(mi->dpy, "turns", "Float"); dc->turn_spacing = get_float_resource(mi->dpy, "turnSpacing", "Float"); dc->bar_spacing = get_float_resource(mi->dpy, "barSpacing", "Float"); dc->wall_height = get_float_resource(mi->dpy, "wallHeight", "Float"); dc->wall_thickness = get_float_resource(mi->dpy, "wallThickness", "Float"); dc->tube_thickness = get_float_resource(mi->dpy, "tubeThickness", "Float"); dc->wall_taper = get_float_resource(mi->dpy, "wallTaper", "Float"); dc->gasket_size = get_float_resource(mi->dpy, "gasketSize", "Float"); dc->gasket_depth = get_float_resource(mi->dpy, "gasketDepth", "Float"); dc->gasket_thickness = get_float_resource(mi->dpy, "gasketThickness", "Float"); dc->speed = get_float_resource(mi->dpy, "speed", "Float"); { XColor xcolor; char *color_name = get_string_resource (mi->dpy, "foreground", "Foreground"); char *s2; for (s2 = color_name + strlen(color_name) - 1; s2 > color_name; s2--) if (*s2 == ' ' || *s2 == '\t') *s2 = 0; else break; if (! XParseColor (MI_DISPLAY(mi), mi->xgwa.colormap, color_name, &xcolor)) { fprintf (stderr, "%s: can't parse color %s\n", progname, color_name); exit (1); } dc->color[0] = xcolor.red / 65535.0; dc->color[1] = xcolor.green / 65535.0; dc->color[2] = xcolor.blue / 65535.0; dc->color[3] = 1.0; } dc->trackball = gltrackball_init (); dc->gasket_spinnery.probability = 0.1; dc->gasket_spinnerx.probability = 0.1; dc->gasket_spinnerz.probability = 1.0; dc->helix_spinnerz.probability = 0.6; dc->scene_spinnerx.probability = 0.1; dc->scene_spinnery.probability = 0.0; if (dc->speed > 0) /* start off with the gasket in motion */ { dc->gasket_spinnerz.spinning_p = True; dc->gasket_spinnerz.speed = (0.002 * ((random() & 1) ? 1 : -1) * dc->speed); } glPushMatrix(); dc->helix_list = glGenLists (1); glNewList (dc->helix_list, GL_COMPILE); glRotatef(126, 0, 0, 1); if (do_ladder) make_ladder (dc, 0, 0); if (do_helix) make_helix (dc, 0, 0); glRotatef(180, 0, 0, 1); if (do_helix) make_helix (dc, 0, 0); glEndList (); glPopMatrix(); glPushMatrix(); dc->helix_list_wire = glGenLists (1); glNewList (dc->helix_list_wire, GL_COMPILE); /* glRotatef(126, 0, 0, 1); wtf? */ if (do_ladder) make_ladder (dc, 1, 1); if (do_helix) make_helix (dc, 1, 1); glRotatef(180, 0, 0, 1); if (do_helix) make_helix (dc, 1, 1); glEndList (); glPopMatrix(); glPushMatrix(); dc->helix_list_facetted = glGenLists (1); glNewList (dc->helix_list_facetted, GL_COMPILE); glRotatef(126, 0, 0, 1); if (do_ladder) make_ladder (dc, 1, 0); if (do_helix) make_helix (dc, 1, 0); glRotatef(180, 0, 0, 1); if (do_helix) make_helix (dc, 1, 0); glEndList (); glPopMatrix(); dc->gasket_list = glGenLists (1); glNewList (dc->gasket_list, GL_COMPILE); if (do_gasket) make_gasket (dc, 0); glEndList (); dc->gasket_list_wire = glGenLists (1); glNewList (dc->gasket_list_wire, GL_COMPILE); if (do_gasket) make_gasket (dc, 1); glEndList (); /* When drawing both solid and wireframe objects, make sure the wireframe actually shows up! */ glEnable (GL_POLYGON_OFFSET_FILL); glPolygonOffset (1.0, 1.0); }
static void * squiral_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); XGCValues gcv; Colormap cmap; XWindowAttributes xgwa; Bool writeable = False; st->dpy = dpy; st->window = window; st->delay= get_integer_resource(st->dpy, "delay", "Integer"); XClearWindow(st->dpy, st->window); XGetWindowAttributes(st->dpy, st->window, &xgwa); st->width = xgwa.width; st->height = xgwa.height; cmap = xgwa.colormap; gcv.foreground = get_pixel_resource(st->dpy, cmap, "foreground", "Foreground"); st->draw_gc = XCreateGC(st->dpy, st->window, GCForeground, &gcv); gcv.foreground = get_pixel_resource (st->dpy, cmap, "background", "Background"); st->erase_gc = XCreateGC (st->dpy, st->window, GCForeground, &gcv); cmap = xgwa.colormap; if( st->ncolors ) { free_colors(xgwa.screen, cmap, st->colors, st->ncolors); st->ncolors = 0; } if( mono_p ) { st->ncolors=1; st->colors[0].pixel=get_pixel_resource(st->dpy, cmap, "foreground","Foreground"); } else { st->ncolors = get_integer_resource(st->dpy, "ncolors", "Integer"); if (st->ncolors < 0 || st->ncolors > NCOLORSMAX) st->ncolors = NCOLORSMAX; make_uniform_colormap(xgwa.screen, xgwa.visual, cmap, st->colors, &st->ncolors, True, &writeable, False); if (st->ncolors <= 0) { st->ncolors = 1; st->colors[0].pixel=get_pixel_resource(st->dpy, cmap, "foreground","Foreground"); } } st->count= get_integer_resource(st->dpy, "count", "Integer"); st->frac = get_integer_resource(st->dpy, "fill", "Integer")*0.01; st->cycle= get_boolean_resource(st->dpy, "cycle", "Cycle"); st->disorder=get_float_resource(st->dpy, "disorder", "Float"); st->handedness=get_float_resource(st->dpy, "handedness", "Float"); if(st->frac<0.01) st->frac=0.01; if(st->frac>0.99) st->frac=0.99; if(st->count==0) st->count=st->width/32; if(st->count<1) st->count=1; if(st->count>1000) st->count=1000; if(st->worms) free(st->worms); if(st->fill) free(st->fill); squiral_init_1 (st); return st; }
void init_molecule (ModeInfo *mi) { molecule_configuration *mc; int wire; #ifndef STANDALONE timeout = MI_CYCLES(mi); #endif if (!mcs) { mcs = (molecule_configuration *) calloc (MI_NUM_SCREENS(mi), sizeof (molecule_configuration)); if (!mcs) { return; } } mc = &mcs[MI_SCREEN(mi)]; if (mc->glx_context) { /* Free font stuff */ free_fonts (mi); } if ((mc->glx_context = init_GL(mi)) != NULL) { glDrawBuffer(GL_BACK); gl_init(); last = 0; reshape_molecule (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); } if (!load_fonts (mi)) { release_molecule(mi); return; } if (firstcall) startup_blurb (mi); cur_wire = MI_IS_WIREFRAME(mi); wire = cur_wire; mc->rotx = FLOATRAND(1.0) * RANDSIGN(); mc->roty = FLOATRAND(1.0) * RANDSIGN(); mc->rotz = FLOATRAND(1.0) * RANDSIGN(); /* bell curve from 0-6 degrees, avg 3 */ mc->dx = (FLOATRAND(0.1) + FLOATRAND(0.1) + FLOATRAND(0.1)) / (360/2); mc->dy = (FLOATRAND(0.1) + FLOATRAND(0.1) + FLOATRAND(0.1)) / (360/2); mc->dz = (FLOATRAND(0.1) + FLOATRAND(0.1) + FLOATRAND(0.1)) / (360/2); mc->d_max = mc->dx * 8; mc->ddx = 0.00006 + FLOATRAND(0.00003); mc->ddy = 0.00006 + FLOATRAND(0.00003); mc->ddz = 0.00006 + FLOATRAND(0.00003); { char *s = do_spin; while (*s) { if (*s == 'x' || *s == 'X') mc->spin_x = 1; else if (*s == 'y' || *s == 'Y') mc->spin_y = 1; else if (*s == 'z' || *s == 'Z') mc->spin_z = 1; else { (void) fprintf (stderr, "molecule: spin must contain only the characters X, Y, or Z (not \"%s\")\n", do_spin); /* exit (1); */ } s++; } } mc->molecule_dlist = glGenLists(1); load_molecules (mi); mc->which = NRAND(mc->nmolecules); #ifdef STANDALONE mc->no_label_threshold = get_float_resource ("noLabelThreshold", "NoLabelThreshold"); mc->wireframe_threshold = get_float_resource ("wireframeThreshold", "WireframeThreshold"); #else mc->no_label_threshold = 30; mc->wireframe_threshold = 150; #endif if (wire) do_bonds = 1; }
ENTRYPOINT void init_molecule (ModeInfo *mi) { molecule_configuration *mc; int wire; if (!mcs) { mcs = (molecule_configuration *) calloc (MI_NUM_SCREENS(mi), sizeof (molecule_configuration)); if (!mcs) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } } mc = &mcs[MI_SCREEN(mi)]; if ((mc->glx_context = init_GL(mi)) != NULL) { gl_init(mi); reshape_molecule (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); } load_fonts (mi); startup_blurb (mi); wire = MI_IS_WIREFRAME(mi); { Bool spinx=False, spiny=False, spinz=False; double spin_speed = 0.5; double spin_accel = 0.3; double wander_speed = 0.01; char *s = do_spin; while (*s) { if (*s == 'x' || *s == 'X') spinx = True; else if (*s == 'y' || *s == 'Y') spiny = True; else if (*s == 'z' || *s == 'Z') spinz = True; else if (*s == '0') ; else { fprintf (stderr, "%s: spin must contain only the characters X, Y, or Z (not \"%s\")\n", progname, do_spin); exit (1); } s++; } mc->rot = make_rotator (spinx ? spin_speed : 0, spiny ? spin_speed : 0, spinz ? spin_speed : 0, spin_accel, do_wander ? wander_speed : 0, (spinx && spiny && spinz)); mc->trackball = gltrackball_init (); } orig_do_labels = do_labels; orig_do_atoms = do_atoms; orig_do_bonds = do_bonds; orig_do_shells = do_shells; orig_wire = MI_IS_WIREFRAME(mi); mc->molecule_dlist = glGenLists(1); if (do_shells) mc->shell_dlist = glGenLists(1); load_molecules (mi); mc->which = random() % mc->nmolecules; mc->no_label_threshold = get_float_resource (mi->dpy, "noLabelThreshold", "NoLabelThreshold"); mc->wireframe_threshold = get_float_resource (mi->dpy, "wireframeThreshold", "WireframeThreshold"); mc->mode = 0; if (wire) do_bonds = 1; }
ENTRYPOINT void init_quasicrystal (ModeInfo *mi) { quasicrystal_configuration *bp; int wire = MI_IS_WIREFRAME(mi); unsigned char *tex_data = 0; int tex_width; int i; if (!bps) { bps = (quasicrystal_configuration *) calloc (MI_NUM_SCREENS(mi), sizeof (quasicrystal_configuration)); if (!bps) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } } bp = &bps[MI_SCREEN(mi)]; bp->glx_context = init_GL(mi); reshape_quasicrystal (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glDisable (GL_DEPTH_TEST); glEnable (GL_CULL_FACE); bp->count = MI_COUNT(mi); if (bp->count < 1) bp->count = 1; if (! wire) { unsigned char *o; tex_width = 4096; tex_data = (unsigned char *) calloc (4, tex_width); o = tex_data; for (i = 0; i < tex_width; i++) { unsigned char y = 255 * (1 + sin (i * M_PI * 2 / tex_width)) / 2; *o++ = y; *o++ = y; *o++ = y; *o++ = 255; } } bp->symmetric_p = get_boolean_resource (MI_DISPLAY (mi), "symmetry", "Symmetry"); bp->contrast = get_float_resource (MI_DISPLAY (mi), "contrast", "Contrast"); if (bp->contrast < 0 || bp->contrast > 100) { fprintf (stderr, "%s: contrast must be between 0 and 100%%.\n", progname); bp->contrast = 0; } { Bool spinp = get_boolean_resource (MI_DISPLAY (mi), "spin", "Spin"); Bool wanderp = get_boolean_resource (MI_DISPLAY (mi), "wander", "Wander"); double spin_speed = 0.01; double wander_speed = 0.0001; double spin_accel = 10.0; double scale_speed = 0.005; bp->planes = (plane *) calloc (sizeof (*bp->planes), bp->count); bp->ncolors = 256; /* ncolors affects color-cycling speed */ bp->colors = (XColor *) calloc (bp->ncolors, sizeof(XColor)); make_smooth_colormap (0, 0, 0, bp->colors, &bp->ncolors, False, 0, False); bp->ccolor = 0; for (i = 0; i < bp->count; i++) { plane *p = &bp->planes[i]; p->rot = make_rotator (0, 0, spinp ? spin_speed : 0, spin_accel, wanderp ? wander_speed : 0, True); p->rot2 = make_rotator (0, 0, 0, 0, scale_speed, True); if (! wire) { clear_gl_error(); glGenTextures (1, &p->texid); glBindTexture (GL_TEXTURE_1D, p->texid); glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glTexImage1D (GL_TEXTURE_1D, 0, GL_RGBA, tex_width, 0, GL_RGBA, /* GL_UNSIGNED_BYTE, */ GL_UNSIGNED_INT_8_8_8_8_REV, tex_data); check_gl_error("texture"); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } } } if (tex_data) free (tex_data); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); }
static void * whirlygig_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); st->dpy = dpy; st->window = window; st->ncolors = NCOLORS; st->dbuf = get_boolean_resource (st->dpy, "doubleBuffer", "Boolean"); # ifdef HAVE_JWXYZ /* Don't second-guess Quartz's double-buffering */ st->dbuf = False; # endif st->start_time = st->current_time; st->info = (struct info *)malloc(sizeof(struct info)); st->screen = DefaultScreen(st->dpy); XGetWindowAttributes (st->dpy, st->window, &st->xgwa); if (st->dbuf) { #ifdef HAVE_DOUBLE_BUFFER_EXTENSION if (get_boolean_resource(st->dpy,"useDBE","Boolean")) { st->dbeclear_p = get_boolean_resource (st->dpy, "useDBEClear", "Boolean"); if (st->dbeclear_p) st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeBackground); else st->b = xdbe_get_backbuffer (st->dpy, st->window, XdbeUndefined); st->backb = st->b; } #endif /* HAVE_DOUBLE_BUFFER_EXTENSION */ if (!st->b) { st->ba = XCreatePixmap (st->dpy, st->window, st->xgwa.width, st->xgwa.height,st->xgwa.depth); st->b = st->ba; } } else { st->b = st->window; } st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap, "foreground", "Foreground"); st->fgc = XCreateGC (st->dpy, st->b, GCForeground, &st->gcv); st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap, "background", "Background"); st->bgc = XCreateGC (st->dpy, st->b, GCForeground, &st->gcv); #ifdef HAVE_JWXYZ /* #### should turn off double-buffering instead */ jwxyz_XSetAntiAliasing (dpy, st->fgc, False); jwxyz_XSetAntiAliasing (dpy, st->bgc, False); #endif { Bool writable_p = False; make_uniform_colormap (st->xgwa.screen, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors, True, &writable_p, True); } if (st->ba) XFillRectangle (st->dpy, st->ba, st->bgc, 0, 0, st->xgwa.width, st->xgwa.height); /* info is a structure holding all the random pieces of information I may want to pass to my baby functions -- much of it I may never use, but it is nice to have around just in case I want it to make a funky function funkier */ /* info->writable = get_boolean_resource (dpy, "cycle", "Boolean"); */ st->info->xspeed = get_float_resource(st->dpy, "xspeed" , "Float"); st->info->yspeed = get_float_resource(st->dpy, "yspeed" , "Float"); st->info->xamplitude = get_float_resource(st->dpy, "xamplitude", "Float"); st->info->yamplitude = get_float_resource(st->dpy, "yamplitude", "Float"); st->info->offset_period = get_float_resource(st->dpy, "offset_period", "Float"); st->info->whirlies = get_integer_resource(st->dpy, "whirlies", "Integer"); st->info->nlines = get_integer_resource(st->dpy, "nlines", "Integer"); st->info->half_width = st->xgwa.width / 2; st->info->half_height = st->xgwa.height / 2; st->info->speed = get_integer_resource(st->dpy, "speed" , "Integer"); st->info->trail = get_boolean_resource(st->dpy, "trail", "Integer"); st->info->color_modifier = get_integer_resource(st->dpy, "color_modifier", "Integer"); st->info->xoffset = get_float_resource(st->dpy, "xoffset", "Float"); st->info->yoffset = get_float_resource(st->dpy, "yoffset", "Float"); st->xmode_str = get_string_resource(st->dpy, "xmode", "Mode"); st->ymode_str = get_string_resource(st->dpy, "ymode", "Mode"); st->wrap = get_boolean_resource(st->dpy, "wrap", "Boolean"); st->modifier = 3000.0 + frand(1500.0); if (! st->xmode_str) st->xmode = spin_mode; else if (! strcmp (st->xmode_str, "spin")) st->xmode = spin_mode; else if (! strcmp (st->xmode_str, "funky")) st->xmode = funky_mode; else if (! strcmp (st->xmode_str, "circle")) st->xmode = circle_mode; else if (! strcmp (st->xmode_str, "linear")) st->xmode = linear_mode; else if (! strcmp (st->xmode_str, "test")) st->xmode = test_mode; else if (! strcmp (st->xmode_str, "fun")) st->xmode = fun_mode; else if (! strcmp (st->xmode_str, "innie")) st->xmode = innie_mode; else if (! strcmp (st->xmode_str, "lissajous")) st->xmode = lissajous_mode; else { st->xmode = random() % (int) lissajous_mode; } if (! st->ymode_str) st->ymode = spin_mode; else if (! strcmp (st->ymode_str, "spin")) st->ymode = spin_mode; else if (! strcmp (st->ymode_str, "funky")) st->ymode = funky_mode; else if (! strcmp (st->ymode_str, "circle")) st->ymode = circle_mode; else if (! strcmp (st->ymode_str, "linear")) st->ymode = linear_mode; else if (! strcmp (st->ymode_str, "test")) st->ymode = test_mode; else if (! strcmp (st->ymode_str, "fun")) st->ymode = fun_mode; else if (! strcmp (st->ymode_str, "innie")) st->ymode = innie_mode; else if (! strcmp (st->ymode_str, "lissajous")) st->ymode = lissajous_mode; else { st->ymode = random() % (int) lissajous_mode; } if (get_integer_resource(st->dpy, "start_time", "Integer") == -1) st->current_time = (unsigned long int)(random()); else st->current_time = get_integer_resource(st->dpy, "start_time", "Integer"); if (st->info->whirlies == -1) st->info->whirlies = 1 + (random() % 15); if (st->info->nlines == -1) st->info->nlines = 1 + (random() % 5); if (st->info->color_modifier == -1) st->info->color_modifier = 1 + (random() % 25); if (get_boolean_resource(st->dpy, "explain", "Integer")) st->explaining = 1; st->current_color = 1 + (random() % NCOLORS); return st; }
static void initialize (struct state *st) { XGCValues *xgc; XGCValues *xorgc; XGCValues *xandgc; st->maxk=34; st->r = st->g = st->b = 1; st->hue = st->sat = 0; st->val = 1; st->mag = 10; st->movef = 0.5; st->wobber = 2; st->cycle = 6; st->scrnWidth = WIDTH; st->scrnHeight = HEIGHT; XGetWindowAttributes (st->dpy, st->window, &st->xgwa); st->scrnWidth = st->xgwa.width; st->scrnHeight = st->xgwa.height; { float f = get_float_resource (st->dpy, "cycle", "Float"); if (f <= 0 || f > 60) f = 6.0; st->cycle = 60.0 / f; } st->movef = get_float_resource (st->dpy, "move", "Float"); st->wobber = get_float_resource (st->dpy, "wobble", "Float"); { double magfac = get_float_resource (st->dpy, "mag", "Float"); st->mag *= magfac; st->fastch=(int)(st->fastch*magfac); } if (get_boolean_resource (st->dpy, "minutes", "Boolean")) { st->minutes=1; st->maxk+=60-24; } st->timewait = get_integer_resource (st->dpy, "delay", "Integer"); st->fastch = get_integer_resource (st->dpy, "fast", "Integer"); st->cycl = get_boolean_resource (st->dpy, "colcycle", "Integer"); st->hsvcycl = get_float_resource (st->dpy, "hsvcycle", "Integer"); { char *s = get_string_resource (st->dpy, "rgb", "RGB"); char dummy; if (s && *s) { double rr, gg, bb; if (3 == sscanf (s, "%lf %lf %lf %c", &rr, &gg, &bb, &dummy)) st->r = rr, st->g = gg, st->b = bb; } if (s) free (s); s = get_string_resource (st->dpy, "hsv", "HSV"); if (s && *s) { double hh, ss, vv; if (3 == sscanf (s, "%lf %lf %lf %c", &hh, &ss, &vv, &dummy)) { st->hue = hh, st->sat = ss, st->val = vv; hsv2rgb(st->hue,st->sat,st->val,&st->r,&st->g,&st->b); } } if (s) free (s); } if (st->fastch > maxfast) st->fastch=maxfast; xgc=( XGCValues *) malloc(sizeof(XGCValues) ); xorgc=( XGCValues *) malloc(sizeof(XGCValues) ); xandgc=( XGCValues *) malloc(sizeof(XGCValues) ); st->planes=st->xgwa.depth; #ifdef HAVE_JWXYZ # define GXandInverted GXcopy /* #### this can't be right, right? */ #endif st->gc = XCreateGC (st->dpy, st->window, 0, xgc); xorgc->function =GXor; st->orgc = XCreateGC (st->dpy, st->window, GCFunction, xorgc); xandgc->function =GXandInverted; st->andgc = XCreateGC (st->dpy, st->window, GCFunction, xandgc); st->buffer = XCreatePixmap (st->dpy, st->window, st->scrnWidth, st->scrnHeight, st->xgwa.depth); #ifdef DEBUG printf("Time 3D drawing "); #ifdef FASTDRAW # ifdef FASTCOPY puts("fast by Pixmap copy"); # else puts("fast by XImage copy"); # endif #else puts("slow"); #endif #endif /* DEBUG */ #ifdef FASTCOPY st->fastcircles = XCreatePixmap (st->dpy, st->window, fastcw, st->fastch+1, st->xgwa.depth); st->fastmask = XCreatePixmap (st->dpy, st->window, fastcw, st->fastch+1, st->xgwa.depth); #endif setink(BlackPixelOfScreen (st->xgwa.screen)); XFillRectangle (st->dpy, st->buffer , st->gc, 0, 0, st->scrnWidth, st->scrnHeight); #ifdef FASTCOPY setink(0); XFillRectangle (st->dpy, st->fastcircles, st->gc, 0, 0, fastcw, st->fastch+1); XFillRectangle (st->dpy, st->fastmask , st->gc, 0, 0, fastcw, st->fastch+1); #endif #ifdef PRTDBX printf("move\t%.2f\nwobber\t%.2f\nmag\t%.2f\ncycle\t%.4f\n", st->movef,st->wobber,st->mag/10,st->cycle); printf("fast\t%i\nmarks\t%i\nwait\t%i\n",st->fastch,st->maxk,st->timewait); #endif }