-/* 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
This version by Chris Le Sueur <thefishface@gmail.com>, Feb 2005
Many improvements by Robby Griffin <rmg@terc.edu>, Mar 2006
+Multi-coloured mode added by Jack Grahl <j.grahl@ucl.ac.uk>, Jan 2007
*/
#include <assert.h>
int length;
int mode;
Bool recurse;
+ Bool multi;
Bool translate, scale, rotate;
};
}
static const char *ifs_defaults [] = {
+ ".lowrez: true",
".background: Black",
"*lensnum: 3",
+ "*fpsSolid: true",
"*length: 9",
"*mode: 0",
"*colors: 200",
"*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
};
{ "-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 }
else newlens->s = 0.5;
newlens->tx = nx;
- newlens->tx = ny;
+ newlens->ty = ny;
lensmatrix(st, newlens);
}
/* Calls itself <lensnum> times - with results from each lens/function. *
* After <length> 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);
}
}
}
* 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;
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
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) {
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
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);
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);
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;
}