X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fdecayscreen.c;h=fa6561c1dae1a2e160ab87edc466193a9b972e27;hp=7b91f63bbd52b0cc06a25f6fcf68e39b724b96f6;hb=96a411663168b0ba5432b407a83be55f3df0c802;hpb=ce3185de9d9705e259f2b60dd4b5509007fa17d4 diff --git a/hacks/decayscreen.c b/hacks/decayscreen.c index 7b91f63b..fa6561c1 100644 --- a/hacks/decayscreen.c +++ b/hacks/decayscreen.c @@ -30,6 +30,10 @@ * 5-AUG-1993 * * Hacked by jwz, 28-Nov-97 (sped up and added new motion directions) + + * R. Schultz + * Added "melt" & "stretch" modes 28-Mar-1999 + * */ #include "screenhack.h" @@ -38,6 +42,7 @@ static int sizex, sizey; static int delay; static GC gc; static int mode; +static int iterations=100; #define SHUFFLE 0 #define UP 1 @@ -50,7 +55,9 @@ static int mode; #define DOWNRIGHT 8 #define IN 9 #define OUT 10 - +#define MELT 11 +#define STRETCH 12 +#define FUZZ 13 static void init_decay (Display *dpy, Window window) @@ -58,6 +65,7 @@ init_decay (Display *dpy, Window window) XGCValues gcv; XWindowAttributes xgwa; long gcflags; + unsigned long bg; char *s = get_string_resource("mode", "Mode"); if (s && !strcmp(s, "shuffle")) mode = SHUFFLE; @@ -71,10 +79,13 @@ init_decay (Display *dpy, Window window) else if (s && !strcmp(s, "downright")) mode = DOWNRIGHT; else if (s && !strcmp(s, "in")) mode = IN; else if (s && !strcmp(s, "out")) mode = OUT; + else if (s && !strcmp(s, "melt")) mode = MELT; + else if (s && !strcmp(s, "stretch")) mode = STRETCH; + else if (s && !strcmp(s, "fuzz")) mode = FUZZ; else { if (s && *s && !!strcmp(s, "random")) fprintf(stderr, "%s: unknown mode %s\n", progname, s); - mode = random() % (OUT+1); + mode = random() % (FUZZ+1); } delay = get_integer_resource ("delay", "Integer"); @@ -85,6 +96,12 @@ init_decay (Display *dpy, Window window) gcv.function = GXcopy; gcv.subwindow_mode = IncludeInferiors; + + if (mode == MELT || mode == STRETCH) { + bg = get_pixel_resource ("background", "Background", dpy, xgwa.colormap); + gcv.foreground = bg; + } + gcflags = GCForeground |GCFunction; if (use_subwindow_mode_p(xgwa.screen, window)) /* see grabscreen.c */ gcflags |= GCSubwindowMode; @@ -93,7 +110,16 @@ init_decay (Display *dpy, Window window) sizex = xgwa.width; sizey = xgwa.height; - grab_screen_image (xgwa.screen, window); + load_random_image (xgwa.screen, window, window, NULL); + + if (mode == MELT || mode == STRETCH) { + /* make sure screen eventually turns background color */ + XDrawLine(dpy, window, gc, 0, 0, sizex, 0); + + /* slow down for smoother melting*/ + iterations = 1; + } + } @@ -133,47 +159,112 @@ decay1 (Display *dpy, Window window) case DOWNRIGHT: bias = downright_bias; break; case IN: bias = no_bias; break; case OUT: bias = no_bias; break; - default: abort(); + case MELT: bias = no_bias; break; + case STRETCH: bias = no_bias; break; + case FUZZ: bias = no_bias; break; + default: abort(); } #define nrnd(x) (random() % (x)) - left = nrnd(sizex - 1); - top = nrnd(sizey); - width = nrnd(sizex - left); - height = nrnd(sizey - top); - - toleft = left; - totop = top; - - if (mode == IN || mode == OUT) { - int x = left+(width/2); - int y = top+(height/2); - int cx = sizex/2; - int cy = sizey/2; - if (mode == IN) { - if (x > cx && y > cy) bias = upleft_bias; - else if (x < cx && y > cy) bias = upright_bias; - else if (x < cx && y < cy) bias = downright_bias; - else /* (x > cx && y < cy)*/ bias = downleft_bias; - } else { - if (x > cx && y > cy) bias = downright_bias; - else if (x < cx && y > cy) bias = downleft_bias; - else if (x < cx && y < cy) bias = upleft_bias; - else /* (x > cx && y < cy)*/ bias = upright_bias; + if (mode == MELT || mode == STRETCH) { + left = nrnd(sizex/2); + top = nrnd(sizey); + width = nrnd( sizex/2 ) + sizex/2 - left; + height = nrnd(sizey - top); + toleft = left; + totop = top+1; + + } else if (mode == FUZZ) { /* By Vince Levey ; + inspired by the "melt" mode of the + "scrhack" IrisGL program by Paul Haeberli + circa 1991. */ + static int toggle = 0; + + left = nrnd(sizex - 1); + top = nrnd(sizey - 1); + toggle = !toggle; + if (toggle) + { + totop = top; + height = 1; + toleft = nrnd(sizex - 1); + if (toleft > left) + { + width = toleft-left; + toleft = left; + left++; + } + else + { + width = left-toleft; + left = toleft; + toleft++; + } + } + else + { + toleft = left; + width = 1; + totop = nrnd(sizey - 1); + if (totop > top) + { + height = totop-top; + totop = top; + top++; + } + else + { + height = top-totop; + top = totop; + totop++; + } + } + + } else { + + left = nrnd(sizex - 1); + top = nrnd(sizey); + width = nrnd(sizex - left); + height = nrnd(sizey - top); + + toleft = left; + totop = top; + if (mode == IN || mode == OUT) { + int x = left+(width/2); + int y = top+(height/2); + int cx = sizex/2; + int cy = sizey/2; + if (mode == IN) { + if (x > cx && y > cy) bias = upleft_bias; + else if (x < cx && y > cy) bias = upright_bias; + else if (x < cx && y < cy) bias = downright_bias; + else /* (x > cx && y < cy)*/ bias = downleft_bias; + } else { + if (x > cx && y > cy) bias = downright_bias; + else if (x < cx && y > cy) bias = downleft_bias; + else if (x < cx && y < cy) bias = upleft_bias; + else /* (x > cx && y < cy)*/ bias = upright_bias; + } } - } - - switch (bias[random() % (sizeof(no_bias)/sizeof(*no_bias))]) { + + switch (bias[random() % (sizeof(no_bias)/sizeof(*no_bias))]) { case L: toleft = left-1; break; case R: toleft = left+1; break; case U: totop = top-1; break; case D: totop = top+1; break; default: abort(); break; + } + } + + if (mode == STRETCH) { + XCopyArea (dpy, window, window, gc, 0, sizey-top-2, sizex, top+1, + 0, sizey-top-1); + } else { + XCopyArea (dpy, window, window, gc, left, top, width, height, + toleft, totop); } - XCopyArea (dpy, window, window, gc, left, top, width, height, - toleft, totop); #undef nrnd } @@ -204,9 +295,10 @@ screenhack (Display *dpy, Window window) init_decay (dpy, window); while (1) { int i; - for (i = 0; i < 100; i++) + for (i = 0; i < iterations; i++) decay1 (dpy, window); XSync(dpy, False); + screenhack_handle_events (dpy); if (delay) usleep (delay); } }