X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fsubstrate.c;h=278a3bd6a4fb18151c52f0f466977b335604c1ba;hb=aa75c7476aeaa84cf3abc192b376a8b03c325213;hp=ce9c696b466835212fcfb9fd715b0c1b8948d07b;hpb=50be9bb40dc60130c99ffa568e6677779904ff70;p=xscreensaver diff --git a/hacks/substrate.c b/hacks/substrate.c index ce9c696b..278a3bd6 100644 --- a/hacks/substrate.c +++ b/hacks/substrate.c @@ -122,6 +122,7 @@ struct field { unsigned int cycles; unsigned int wireframe; + unsigned int seamless; }; struct state { @@ -164,6 +165,7 @@ static struct field f->parsedcolors = NULL; f->cycles = 0; f->wireframe = 0; + f->seamless = 0; f->fgcolor = 0; f->bgcolor = 0; f->visdepth = 0; @@ -285,7 +287,7 @@ static inline void point2rgb(int depth, unsigned long c, int *r, int *g, int *b) switch(depth) { case 32: case 24: -#ifdef HAVE_COCOA +#ifdef HAVE_JWXYZ /* This program idiotically does not go through a color map, so we have to hardcode in knowledge of how jwxyz.a packs pixels! Fix it to go through st->colors[st->ncolors] instead! @@ -319,7 +321,7 @@ static inline unsigned long rgb2point(int depth, int r, int g, int b) switch(depth) { case 32: case 24: -#ifdef HAVE_COCOA +#ifdef HAVE_JWXYZ /* This program idiotically does not go through a color map, so we have to hardcode in knowledge of how jwxyz.a packs pixels! Fix it to go through st->colors[st->ncolors] instead! @@ -398,6 +400,10 @@ region_color(struct state *st, GC fgc, struct field *f, crack *cr) cx = (int) rx; cy = (int) ry; + if (f->seamless) { + cx %= f->width; + cy %= f->height; + } if ((cx >= 0) && (cx < f->width) && (cy >= 0) && (cy < f->height)) { /* safe to check */ @@ -431,6 +437,10 @@ region_color(struct state *st, GC fgc, struct field *f, crack *cr) for (i = 0; i < grains; i++) { drawx = (cr->x + (rx - cr->x) * sin(cr->sandp + sin((float) i * w))); drawy = (cr->y + (ry - cr->y) * sin(cr->sandp + sin((float) i * w))); + if (f->seamless) { + drawx = fmod(drawx + f->width, f->width); + drawy = fmod(drawy + f->height, f->height); + } /* Draw sand bit */ c = trans_point(st, drawx, drawy, cr->sandcolor, (0.1 - i / (grains * 10.0)), f); @@ -462,7 +472,12 @@ static void build_substrate(struct field *f) /* erase the crack grid */ f->cgrid = (int *) xrealloc(f->cgrid, sizeof(int) * f->height * f->width); - memset(f->cgrid, 10001, f->height * f->width * sizeof(int)); + { + int j; + int *p = f->cgrid; + for (j = 0; j < f->height * f->width; j++) + *p++ = 10001; + } /* Not necessary now that make_crack ensures we have usable default * values in start_crack's timeout case @@ -500,14 +515,21 @@ movedrawcrack(struct state *st, GC fgc, struct field *f, int cracknum) cr->y += ((float) cr->xs * sin(cr->t * M_PI/180 - M_PI / 2)); cr->t += cr->t_inc; - cr->degrees_drawn += abs(cr->t_inc); + cr->degrees_drawn += fabsf(cr->t_inc); + } + if (f->seamless) { + cr->x = fmod(cr->x + f->width, f->width); + cr->y = fmod(cr->y + f->height, f->height); } /* bounds check */ /* modification of random(-0.33,0.33) */ cx = (int) (cr->x + (frand(0.66) - 0.33)); cy = (int) (cr->y + (frand(0.66) - 0.33)); - + if (f->seamless) { + cx %= f->width; + cy %= f->height; + } if ((cx >= 0) && (cx < f->width) && (cy >= 0) && (cy < f->height)) { /* draw sand painter if we're not wireframe */ @@ -525,10 +547,10 @@ movedrawcrack(struct state *st, GC fgc, struct field *f, int cracknum) } /* safe to check */ else if ((f->cgrid[cy * f->width + cx] > 10000) || - (abs(f->cgrid[cy * f->width + cx] - cr->t) < 5)) { + (fabsf(f->cgrid[cy * f->width + cx] - cr->t) < 5)) { /* continue cracking */ f->cgrid[cy * f->width + cx] = (int) cr->t; - } else if (abs(f->cgrid[cy * f->width + cx] - cr->t) > 2) { + } else if (fabsf(f->cgrid[cy * f->width + cx] - cr->t) > 2) { /* crack encountered (not self), stop cracking */ start_crack(f, cr); /* restart ourselves */ make_crack(f); /* generate a new crack */ @@ -580,6 +602,7 @@ substrate_init (Display *dpy, Window window) st->f->wireframe = (get_boolean_resource(st->dpy, "wireFrame", "Boolean")); st->f->grains = (get_integer_resource(st->dpy, "sandGrains", "Integer")); st->f->circle_percent = (get_integer_resource(st->dpy, "circlePercent", "Integer")); + st->f->seamless = (get_boolean_resource(st->dpy, "seamless", "Boolean")); if (st->f->initial_cracks <= 2) { fprintf(stderr, "%s: Initial cracks must be greater than 2\n", progname); @@ -685,6 +708,7 @@ substrate_draw (Display *dpy, Window window, void *closure) XSetForeground(st->dpy, st->fgc, st->gcv.foreground); } + /* #### mi->recursion_depth = st->f->cycles; */ return st->growth_delay; } @@ -698,6 +722,12 @@ substrate_reshape (Display *dpy, Window window, void *closure, static Bool substrate_event (Display *dpy, Window window, void *closure, XEvent *event) { + struct state *st = (struct state *) closure; + if (screenhack_event_helper (dpy, window, event)) + { + st->f->cycles = st->max_cycles; + return True; + } return False; } @@ -713,12 +743,16 @@ static const char *substrate_defaults[] = { ".foreground: black", "*fpsSolid: true", "*wireFrame: false", + "*seamless: false", "*maxCycles: 10000", "*growthDelay: 18000", "*initialCracks: 3", "*maxCracks: 100", "*sandGrains: 64", "*circlePercent: 33", +#ifdef HAVE_MOBILE + "*ignoreRotation: True", +#endif 0 }; @@ -726,6 +760,7 @@ static XrmOptionDescRec substrate_options[] = { {"-background", ".background", XrmoptionSepArg, 0}, {"-foreground", ".foreground", XrmoptionSepArg, 0}, {"-wireframe", ".wireFrame", XrmoptionNoArg, "true"}, + {"-seamless", ".seamless", XrmoptionNoArg, "true"}, {"-max-cycles", ".maxCycles", XrmoptionSepArg, 0}, {"-growth-delay", ".growthDelay", XrmoptionSepArg, 0}, {"-initial-cracks", ".initialCracks", XrmoptionSepArg, 0},