+static void *
+cloudlife_init (Display *dpy, Window window)
+{
+ struct state *st = (struct state *) calloc (1, sizeof(*st));
+ Bool tmp = True;
+
+ st->dpy = dpy;
+ st->window = window;
+ st->field = init_field(st);
+
+#ifdef TIME_ME
+ st->start_time = time(NULL);
+#endif
+
+ st->cycle_delay = get_integer_resource(st->dpy, "cycleDelay", "Integer");
+ st->cycle_colors = get_integer_resource(st->dpy, "cycleColors", "Integer");
+ st->ncolors = get_integer_resource(st->dpy, "ncolors", "Integer");
+ st->density = (get_integer_resource(st->dpy, "initialDensity", "Integer")
+ % 100 * 256)/100;
+
+ XGetWindowAttributes(st->dpy, st->window, &st->xgwa);
+
+ if (st->cycle_colors) {
+ st->colors = (XColor *) xrealloc(st->colors, sizeof(XColor) * (st->ncolors+1));
+ make_smooth_colormap (st->dpy, st->xgwa.visual, st->xgwa.colormap, st->colors, &st->ncolors,
+ True, &tmp, True);
+ }
+
+ st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap,
+ "foreground", "Foreground");
+ st->fgc = XCreateGC(st->dpy, st->window, GCForeground, &st->gcv);
+
+ st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap,
+ "background", "Background");
+ st->bgc = XCreateGC(st->dpy, st->window, GCForeground, &st->gcv);
+
+ return st;
+}
+
+static unsigned long
+cloudlife_draw (Display *dpy, Window window, void *closure)
+{
+ struct state *st = (struct state *) closure;
+
+ if (st->cycle_colors) {
+ if (st->colortimer == 0) {
+ st->colortimer = st->cycle_colors;
+ if( st->colorindex == 0 )
+ st->colorindex = st->ncolors;
+ st->colorindex--;
+ XSetForeground(st->dpy, st->fgc, st->colors[st->colorindex].pixel);
+ }
+ st->colortimer--;
+ }
+
+ XGetWindowAttributes(st->dpy, st->window, &st->xgwa);
+ if (st->field->height != st->xgwa.height / (1 << st->field->cell_size) + 2 ||
+ st->field->width != st->xgwa.width / (1 << st->field->cell_size) + 2) {
+
+ resize_field(st->field, st->xgwa.width / (1 << st->field->cell_size) + 2,
+ st->xgwa.height / (1 << st->field->cell_size) + 2);
+ populate_field(st->field, st->density);
+ }
+
+ draw_field(st, st->field);
+
+ if (do_tick(st->field) < (st->field->height + st->field->width) / 4) {
+ populate_field(st->field, st->density);
+ }
+
+ if (st->cycles % (st->field->max_age /2) == 0) {
+ populate_edges(st->field, st->density);
+ do_tick(st->field);
+ populate_edges(st->field, 0);
+ }
+
+ st->cycles++;
+
+#ifdef TIME_ME
+ if (st->cycles % st->field->max_age == 0) {
+ printf("%g s.\n",
+ ((time(NULL) - st->start_time) * 1000.0) / st->cycles);
+ }
+#endif
+
+ return (st->cycle_delay);
+}
+
+
+static void
+cloudlife_reshape (Display *dpy, Window window, void *closure,
+ unsigned int w, unsigned int h)
+{
+}
+
+static Bool
+cloudlife_event (Display *dpy, Window window, void *closure, XEvent *event)
+{
+ return False;
+}