+static void *
+moire2_init (Display *dpy, Window window)
+{
+ struct state *st = (struct state *) calloc (1, sizeof(*st));
+ st->dpy = dpy;
+ st->window = window;
+ st->reset = 1;
+
+ st->delay = get_integer_resource (st->dpy, "delay", "Integer");
+ st->color_shift = get_integer_resource (st->dpy, "colorShift", "Integer");
+
+ if (st->color_shift <= 0) st->color_shift = 1;
+ moire2_init_1 (st);
+ return st;
+}
+
+static unsigned long
+moire2_draw (Display *dpy, Window window, void *closure)
+{
+ struct state *st = (struct state *) closure;
+
+ if (st->reset)
+ {
+ st->reset = 0;
+
+ st->iteration = 0;
+ st->iterations = 30 + (random() % 70) + (random() % 70);
+ reset_moire2 (st);
+
+ st->flip_a = mono_p ? False : (random() & 1);
+ st->flip_b = mono_p ? False : (random() & 1);
+
+ if (st->flip_b)
+ {
+ XSetForeground(st->dpy, st->window_gc, st->bg_pixel);
+ XSetBackground(st->dpy, st->window_gc, st->fg_pixel);
+ }
+ else
+ {
+ XSetForeground(st->dpy, st->window_gc, st->fg_pixel);
+ XSetBackground(st->dpy, st->window_gc, st->bg_pixel);
+ }
+ }
+
+ if (!mono_p)
+ {
+ st->pix++;
+ st->pix = st->pix % st->ncolors;
+
+ if (st->flip_a)
+ XSetBackground(st->dpy, st->window_gc, st->colors[st->pix].pixel);
+ else
+ XSetForeground(st->dpy, st->window_gc, st->colors[st->pix].pixel);
+ }
+