X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fifs.c;h=ad8af952139d2704a5ae5e3130ea9ad2df2c5a30;hb=39809ded547bdbb08207d3e514950425215b4410;hp=95058ae579b78f397d66ef785ce33ecebdf726e0;hpb=49f5b54f312fe4ac2e9bc47581a72451bd0e8439;p=xscreensaver diff --git a/hacks/ifs.c b/hacks/ifs.c index 95058ae5..ad8af952 100644 --- a/hacks/ifs.c +++ b/hacks/ifs.c @@ -1,4 +1,4 @@ -/* Copyright © Chris Le Sueur and Robby Griffin, 2005-2006 +/* Copyright © Chris Le Sueur and Robby Griffin, 2005-2006 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the @@ -26,6 +26,7 @@ a groovier colouring mode. This version by Chris Le Sueur , Feb 2005 Many improvements by Robby Griffin , Mar 2006 +Multi-coloured mode added by Jack Grahl , Jan 2007 */ #include @@ -75,6 +76,7 @@ struct state { int length; int mode; Bool recurse; + Bool multi; Bool translate, scale, rotate; }; @@ -88,8 +90,10 @@ myrandom(float up) } static const char *ifs_defaults [] = { + ".lowrez: true", ".background: Black", "*lensnum: 3", + "*fpsSolid: true", "*length: 9", "*mode: 0", "*colors: 200", @@ -98,10 +102,14 @@ static const char *ifs_defaults [] = { "*scale: True", "*rotate: True", "*recurse: False", -# ifdef HAVE_COCOA /* Don't second-guess Quartz's double-buffering */ + "*multi: True", +# ifdef HAVE_JWXYZ /* Don't second-guess Quartz's double-buffering */ "*doubleBuffer: False", #else "*doubleBuffer: True", +#endif +#ifdef HAVE_MOBILE + "*ignoreRotation: True", #endif 0 }; @@ -117,6 +125,8 @@ static XrmOptionDescRec ifs_options [] = { { "-no-rotate", ".rotate", XrmoptionNoArg, "False" }, { "-recurse", ".recurse", XrmoptionNoArg, "True" }, { "-iterate", ".recurse", XrmoptionNoArg, "False" }, + { "-multi", ".multi", XrmoptionNoArg, "True" }, + { "-no-multi", ".multi", XrmoptionNoArg, "False" }, { "-db", ".doubleBuffer",XrmoptionNoArg, "True" }, { "-no-db", ".doubleBuffer",XrmoptionNoArg, "False" }, { 0, 0, 0, 0 } @@ -205,7 +215,7 @@ CreateLens(struct state *st, else newlens->s = 0.5; newlens->tx = nx; - newlens->tx = ny; + newlens->ty = ny; lensmatrix(st, newlens); } @@ -264,17 +274,23 @@ mutate(struct state *st, Lens *l) /* Calls itself times - with results from each lens/function. * * After calls to itself, it stops iterating and draws a point. */ static void -recurse(struct state *st, int x, int y, int length) +recurse(struct state *st, int x, int y, int length, int p) { int i; Lens *l; if (length == 0) { - sp(st, x, y); - } else { + if (p == 0) + sp(st, x, y); + else { + l = &st->lenses[p]; + sp(st, STEPX(l, x, y), STEPY(l, x, y)); + } + } + else { for (i = 0; i < st->lensnum; i++) { l = &st->lenses[i]; - recurse(st, STEPX(l, x, y), STEPY(l, x, y), length - 1); + recurse(st, STEPX(l, x, y), STEPY(l, x, y), length - 1, p); } } } @@ -283,7 +299,7 @@ recurse(struct state *st, int x, int y, int length) * iteration after the first 10. */ static void -iterate(struct state *st, int count) +iterate(struct state *st, int count, int p) { int i; Lens *l; @@ -303,7 +319,13 @@ iterate(struct state *st, int count) for ( ; i < count; i++) { STEP(); - sp(st, x, y); + if (p == 0) + sp(st, x, y); + else + { + l = &st->lenses[p]; + sp(st, STEPX(l, x, y), STEPY(l, x, y)); + } } # undef STEP @@ -321,6 +343,8 @@ ifs_draw (Display *dpy, Window window, void *closure) struct state *st = (struct state *) closure; int i; int xmin = st->xmin, xmax = st->xmax, ymin = st->ymin, ymax = st->ymax; + int partcolor, x, y; + /* erase whatever was drawn in the previous frame */ if (xmin <= xmax && ymin <= ymax) { @@ -335,17 +359,37 @@ ifs_draw (Display *dpy, Window window, void *closure) st->ccolour++; st->ccolour %= st->ncolours; - XSetForeground(st->dpy, st->gc, st->colours[st->ccolour].pixel); /* calculate and draw points for this frame */ - memset(st->board, 0, st->widthb * st->height * sizeof(*st->board)); - if (st->recurse) - recurse(st, st->width << 7, st->height << 7, st->length); - else - iterate(st, pow(st->lensnum, st->length)); - if (st->npoints) - drawpoints(st); - + x = st->width << 7; + y = st->height << 7; + + if (st->multi) { + for (i = 0; i < st->lensnum; i++) { + partcolor = st->ccolour * (i+1); + partcolor %= st->ncolours; + XSetForeground(st->dpy, st->gc, st->colours[partcolor].pixel); + memset(st->board, 0, st->widthb * st->height * sizeof(*st->board)); + if (st->recurse) + recurse(st, x, y, st->length - 1, i); + else + iterate(st, pow(st->lensnum, st->length - 1), i); + if (st->npoints) + drawpoints(st); + } + } + else { + + XSetForeground(st->dpy, st->gc, st->colours[st->ccolour].pixel); + memset(st->board, 0, st->widthb * st->height * sizeof(*st->board)); + if (st->recurse) + recurse(st, x, y, st->length, 0); + else + iterate(st, pow(st->lensnum, st->length), 0); + if (st->npoints) + drawpoints(st); + } + /* if we just drew into a buffer, copy the changed area (including * erased area) to screen */ if (st->backbuffer != st->window @@ -393,9 +437,10 @@ ifs_init (Display *d_arg, Window w_arg) if (st->ncolours < st->lensnum) st->ncolours = st->lensnum; if (st->colours) free(st->colours); + if (st->ncolours < 1) st->ncolours = 1; st->colours = (XColor *)calloc(st->ncolours, sizeof(XColor)); if (!st->colours) exit(1); - make_smooth_colormap (st->dpy, xgwa.visual, xgwa.colormap, + make_smooth_colormap (xgwa.screen, xgwa.visual, xgwa.colormap, st->colours, &st->ncolours, True, 0, False); @@ -410,6 +455,7 @@ ifs_init (Display *d_arg, Window w_arg) st->scale = get_boolean_resource(st->dpy, "scale", "Boolean"); st->translate = get_boolean_resource(st->dpy, "translate", "Boolean"); st->recurse = get_boolean_resource(st->dpy, "recurse", "Boolean"); + st->multi = get_boolean_resource(st->dpy, "multi", "Boolean"); st->lensnum = get_integer_resource(st->dpy, "lensnum", "Functions"); if (st->lenses) free (st->lenses); @@ -472,6 +518,20 @@ ifs_reshape (Display *dpy, Window window, void *closure, static Bool ifs_event (Display *dpy, Window window, void *closure, XEvent *event) { + struct state *st = (struct state *)closure; + if (screenhack_event_helper (dpy, window, event)) + { + int i; + for (i = 0; i < st->lensnum; i++) { + CreateLens(st, + myrandom(1)-0.5, + myrandom(1), + myrandom(4)-2, + myrandom(4)+2, + &st->lenses[i]); + } + return True; + } return False; }