- count= get_integer_resource("count", "Integer");
- frac = get_integer_resource("fill", "Integer")*0.01;
- cycle= get_boolean_resource("cycle", "Cycle");
- disorder=get_float_resource("disorder", "Float");
- handedness=get_float_resource("handedness", "Float");
-
- if(frac<0.01) frac=0.01;
- if(frac>0.99) frac=0.99;
- if(count==0) count=width/32;
- if(count<1) count=1;
- if(count>1000) count=1000;
-
- if(worms) free(worms);
- if(fill) free(fill);
-
- worms=calloc(count, sizeof(struct worm));
- fill=calloc(width*height, sizeof(int));
-
- dirh[0]=0; dirh[1]=1; dirh[2]=0; dirh[3]=width-1;
- dirv[0]=height-1; dirv[1]=0; dirv[2]=1; dirv[3]=0;
- for(i=0;i<count;i++) {
- worms[i].h=R(width);
- worms[i].v=R(height);
- worms[i].s=R(4)+4*PROB(handedness);
- worms[i].c=R(ncolors);
- if(cycle) { worms[i].cc=R(3)+ncolors; }
- else worms[i].cc=0;
+ st->count= get_integer_resource(st->dpy, "count", "Integer");
+ st->frac = get_integer_resource(st->dpy, "fill", "Integer")*0.01;
+ st->cycle= get_boolean_resource(st->dpy, "cycle", "Cycle");
+ st->disorder=get_float_resource(st->dpy, "disorder", "Float");
+ st->handedness=get_float_resource(st->dpy, "handedness", "Float");
+
+ if(st->frac<0.01) st->frac=0.01;
+ if(st->frac>0.99) st->frac=0.99;
+ if(st->count==0) st->count=st->width/32;
+ if(st->count<1) st->count=1;
+ if(st->count>1000) st->count=1000;
+
+ if(st->worms) free(st->worms);
+ if(st->fill) free(st->fill);
+
+ squiral_init_1 (st);
+
+ return st;
+}
+
+static unsigned long
+squiral_draw (Display *dpy, Window window, void *closure)
+{
+ struct state *st = (struct state *) closure;
+ int i;
+
+ if(st->inclear<st->height) {
+ XDrawLine(st->dpy, st->window, st->erase_gc, 0, st->inclear, st->width-1, st->inclear);
+ memset(&st->fill[st->inclear*st->width], 0, sizeof(int)*st->width);
+ XDrawLine(st->dpy, st->window, st->erase_gc, 0, st->height-st->inclear-1, st->width-1,
+ st->height-st->inclear-1);
+ memset(&st->fill[(st->height-st->inclear-1)*st->width], 0, sizeof(int)*st->width);
+ st->inclear++;
+ XDrawLine(st->dpy, st->window, st->erase_gc, 0, st->inclear, st->width-1, st->inclear);
+ if (st->inclear < st->height)
+ memset(&st->fill[st->inclear*st->width], 0, sizeof(int)*st->width);
+ XDrawLine(st->dpy, st->window, st->erase_gc, 0, st->height-st->inclear-1, st->width-1,
+ st->height-st->inclear-1);
+ if (st->height - st->inclear >= 1)
+ memset(&st->fill[(st->height-st->inclear-1)*st->width], 0, sizeof(int)*st->width);
+ st->inclear++;
+ if(st->inclear>st->height/2) st->inclear=st->height;
+ }
+ else if(st->cov>(st->frac*st->width*st->height)) {
+ st->inclear=0;
+ st->cov=0;
+ }
+ for(i=0;i<st->count;i++) do_worm(st, &st->worms[i]);
+ return st->delay;
+}
+
+static void
+squiral_reshape (Display *dpy, Window window, void *closure,
+ unsigned int w, unsigned int h)
+{
+ struct state *st = (struct state *) closure;
+ st->width = w;
+ st->height = h;
+ squiral_init_1 (st);
+ XClearWindow (dpy, window);
+}
+
+static Bool
+squiral_event (Display *dpy, Window window, void *closure, XEvent *event)
+{
+ struct state *st = (struct state *) closure;
+ if (screenhack_event_helper (dpy, window, event))
+ {
+ squiral_init_1 (st);
+ XClearWindow (dpy, window);
+ return True;