- int left, top, width, height;
-
-#define nrnd(x) (random() % (x))
-
- switch (random() % 8) {
- case 0: /* move a block left */
- case 1:
- left = nrnd(sizex - 1) + 1;
- top = nrnd(sizey);
- width = nrnd(sizex - left);
- height = nrnd(sizey - top);
- XCopyArea (dpy, window, window, gc, left, top, width, height,
- left - 1, top);
- break;
- case 2: /* move a block right */
- case 3:
- left = nrnd(sizex - 1);
- top = nrnd(sizey);
- width = nrnd(sizex - 1 - left);
- height = nrnd(sizey - top);
- XCopyArea (dpy, window, window, gc, left, top, width, height,
- left + 1, top);
- break;
- case 4: /* move a block up */
- left = nrnd(sizex);
- top = nrnd(sizey - 1) + 1;
- width = nrnd(sizex - left);
- height = nrnd(sizey - top);
- XCopyArea (dpy, window, window, gc, left, top, width, height,
- left, top - 1);
- break;
- default: /* move block down (biased to this) */
- left = nrnd(sizex);
- top = nrnd(sizey - 1);
- width = nrnd(sizex - left);
- height = nrnd(sizey - 1 - top);
- XCopyArea (dpy, window, window, gc, left, top, width, height,
- left, top + 1);
- break;
+ struct state *st = (struct state *) closure;
+ int left, top, width, height, toleft, totop;
+
+#define L 101
+#define R 102
+#define U 103
+#define D 104
+ static const int no_bias[] = { L,L,L,L, R,R,R,R, U,U,U,U, D,D,D,D };
+ static const int up_bias[] = { L,L,L,L, R,R,R,R, U,U,U,U, U,U,D,D };
+ static const int down_bias[] = { L,L,L,L, R,R,R,R, U,U,D,D, D,D,D,D };
+ static const int left_bias[] = { L,L,L,L, L,L,R,R, U,U,U,U, D,D,D,D };
+ static const int right_bias[] = { L,L,R,R, R,R,R,R, U,U,U,U, D,D,D,D };
+
+ static const int upleft_bias[] = { L,L,L,L, L,R,R,R, U,U,U,U, U,D,D,D };
+ static const int downleft_bias[] = { L,L,L,L, L,R,R,R, U,U,U,D, D,D,D,D };
+ static const int upright_bias[] = { L,L,L,R, R,R,R,R, U,U,U,U, U,D,D,D };
+ static const int downright_bias[] = { L,L,L,R, R,R,R,R, U,U,U,D, D,D,D,D };
+
+ if (st->img_loader) /* still loading */
+ {
+ st->img_loader = load_image_async_simple (st->img_loader,
+ 0, 0, 0, 0, 0);
+ if (! st->img_loader) { /* just finished */
+
+ st->start_time = time ((time_t) 0);
+ if (st->random_p)
+ st->mode = random() % (FUZZ+1);
+
+ if (st->mode == MELT || st->mode == STRETCH)
+ /* make sure screen eventually turns background color */
+ XDrawLine (st->dpy, st->window, st->gc, 0, 0, st->sizex, 0);
+ }
+ return st->delay;
+ }
+
+ if (!st->img_loader &&
+ st->start_time + st->duration < time ((time_t) 0)) {
+ decayscreen_load_image (st);
+ }
+
+ switch (st->mode) {
+ case SHUFFLE: st->current_bias = no_bias; break;
+ case UP: st->current_bias = up_bias; break;
+ case LEFT: st->current_bias = left_bias; break;
+ case RIGHT: st->current_bias = right_bias; break;
+ case DOWN: st->current_bias = down_bias; break;
+ case UPLEFT: st->current_bias = upleft_bias; break;
+ case DOWNLEFT: st->current_bias = downleft_bias; break;
+ case UPRIGHT: st->current_bias = upright_bias; break;
+ case DOWNRIGHT: st->current_bias = downright_bias; break;
+ case IN: st->current_bias = no_bias; break;
+ case OUT: st->current_bias = no_bias; break;
+ case MELT: st->current_bias = no_bias; break;
+ case STRETCH: st->current_bias = no_bias; break;
+ case FUZZ: st->current_bias = no_bias; break;
+ default: abort();