From http://www.jwz.org/xscreensaver/xscreensaver-5.18.tar.gz
[xscreensaver] / hacks / squiral.c
index dbde586f7d922f24b352f2428e0ca56bcd86302c..2a0b0fd29bb61016afe8abe1ed8dddb8925c8f38 100644 (file)
@@ -107,6 +107,28 @@ do_worm(struct state *st, struct worm *w)
     w->v = w->v % st->height;
 }
 
+static void
+squiral_init_1 (struct state *st)
+{
+    int i;
+    if (st->worms) free (st->worms);
+    if (st->fill) free (st->fill);
+
+    st->worms=calloc(st->count, sizeof(struct worm));
+    st->fill=calloc(st->width*st->height, sizeof(int));
+
+    st->dirh[0]=0; st->dirh[1]=1; st->dirh[2]=0; st->dirh[3]=st->width-1;
+    st->dirv[0]=st->height-1; st->dirv[1]=0; st->dirv[2]=1; st->dirv[3]=0;
+    for(i=0;i<st->count;i++) {
+       st->worms[i].h=R(st->width);
+       st->worms[i].v=R(st->height);
+       st->worms[i].s=R(4)+4*PROB(st->handedness);
+       st->worms[i].c=R(st->ncolors);
+       if(st->cycle) { st->worms[i].cc=R(3)+st->ncolors; }
+       else st->worms[i].cc=0;
+    }
+}
+
 static void *
 squiral_init (Display *dpy, Window window)
 {
@@ -115,7 +137,6 @@ squiral_init (Display *dpy, Window window)
     Colormap cmap;
     XWindowAttributes xgwa;
     Bool writeable = False;
-    int i;
 
     st->dpy = dpy;
     st->window = window;
@@ -167,19 +188,7 @@ squiral_init (Display *dpy, Window window)
     if(st->worms) free(st->worms);
     if(st->fill)  free(st->fill);
 
-    st->worms=calloc(st->count, sizeof(struct worm));
-    st->fill=calloc(st->width*st->height, sizeof(int));
-
-    st->dirh[0]=0; st->dirh[1]=1; st->dirh[2]=0; st->dirh[3]=st->width-1;
-    st->dirv[0]=st->height-1; st->dirv[1]=0; st->dirv[2]=1; st->dirv[3]=0;
-    for(i=0;i<st->count;i++) {
-       st->worms[i].h=R(st->width);
-       st->worms[i].v=R(st->height);
-       st->worms[i].s=R(4)+4*PROB(st->handedness);
-       st->worms[i].c=R(st->ncolors);
-       if(st->cycle) { st->worms[i].cc=R(3)+st->ncolors; }
-       else st->worms[i].cc=0;
-    }
+    squiral_init_1 (st);
 
     return st;
 }
@@ -198,10 +207,12 @@ squiral_draw (Display *dpy, Window window, void *closure)
     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);
-    memset(&st->fill[st->inclear*st->width], 0, sizeof(int)*st->width);
+    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);
-    memset(&st->fill[(st->height-st->inclear-1)*st->width], 0, sizeof(int)*st->width);
+    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;
   }
@@ -217,6 +228,11 @@ 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
@@ -236,13 +252,14 @@ squiral_free (Display *dpy, Window window, void *closure)
 static const char *squiral_defaults[] = {
   ".background: black",
   ".foreground: white",
+  "*fpsSolid:  true",
   "*fill:       75",
   "*count:      0",
   "*ncolors:    100",
-  "*delay:      1000",
+  "*delay:      10000",
   "*disorder:   0.005",
   "*cycle:      False",
-  "*handedness: .5",
+  "*handedness: 0.5",
   0
 };