X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fsubstrate.c;h=52d031cc032804d5beb46e98ceee641569fd4d2b;hb=d5186197bc394e10a4402f7f6d23fbb14103bc50;hp=6b0cb823bfe0c2ca9112fce1d34f04a1617991f7;hpb=c1b9b55ad8d59dc05ef55e316aebf5863e7dfa56;p=xscreensaver diff --git a/hacks/substrate.c b/hacks/substrate.c index 6b0cb823..52d031cc 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; @@ -198,6 +200,13 @@ static inline void start_crack(struct field *f, crack *cr) /* We timed out. Use our default values */ px = cr->x; py = cr->y; + + /* Sanity check needed */ + if (px < 0) px = 0; + if (px >= f->width) px = f->width - 1; + if (py < 0) py = 0; + if (py >= f->height) py = f->height - 1; + ref_cgrid(f, px, py) = cr->t; } @@ -311,7 +320,6 @@ static inline unsigned long rgb2point(int depth, int r, int g, int b) switch(depth) { case 32: - ret = 0xff000000; case 24: #ifdef HAVE_COCOA /* This program idiotically does not go through a color map, so @@ -392,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 */ @@ -425,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); @@ -487,26 +503,28 @@ movedrawcrack(struct state *st, GC fgc, struct field *f, int cracknum) cr->y += ((float) STEP * sin(cr->t * M_PI/180)); } else { - float oldx, oldy; - - oldx = cr->x; - oldy = cr->y; - cr->x += ((float) cr->ys * cos(cr->t * M_PI/180)); cr->y += ((float) cr->ys * sin(cr->t * M_PI/180)); cr->x += ((float) cr->xs * cos(cr->t * M_PI/180 - M_PI / 2)); - cr->x += ((float) cr->xs * sin(cr->t * M_PI/180 - M_PI / 2)); + 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); } + 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 */ @@ -579,6 +597,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); @@ -684,6 +703,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; } @@ -697,6 +717,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; } @@ -712,12 +738,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 USE_IPHONE + "*ignoreRotation: True", +#endif 0 }; @@ -725,6 +755,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},