X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fxlyap.c;h=683c21baa610b7aae8573b3af77bb9d9bddd669d;hb=bbd0773f2adde4927a6196361d4061e70bf48cd9;hp=350888d0c379a45f6e3fab3acb65c6bb7070f247;hpb=5b7bc6e70fb439cf4c4bf771ae9f94077fe4fe08;p=xscreensaver diff --git a/hacks/xlyap.c b/hacks/xlyap.c index 350888d0..683c21ba 100644 --- a/hacks/xlyap.c +++ b/hacks/xlyap.c @@ -39,7 +39,6 @@ #include "screenhack.h" #include "yarandom.h" #include "hsv.h" -#include "vroot.h" #include #include @@ -47,7 +46,8 @@ char *progclass = "XLyap"; char *defaults [] = { - "XLyap.background: black", /* to placate SGI */ + ".background: black", + ".foreground: white", "*randomize: false", "*builtin: -1", "*minColor: 1", @@ -109,14 +109,22 @@ XrmOptionDescRec options [] = { #ifdef SIXTEEN_COLORS #define MAXPOINTS 128 +#ifdef BIGMEM #define MAXFRAMES 4 +#else +#define MAXFRAMES 2 +#endif #define MAXCOLOR 16 static int maxcolor=16, startcolor=0, color_offset=0, mincolindex=1; static int dwell=50, settle=25; static int width=128, height=128, xposition=128, yposition=128; #else #define MAXPOINTS 256 +#ifdef BIGMEM #define MAXFRAMES 8 +#else +#define MAXFRAMES 2 +#endif #define MAXCOLOR 256 static int maxcolor=256, startcolor=17, color_offset=96, mincolindex=33; static int dwell=100, settle=50; @@ -525,17 +533,13 @@ screenhack (Display *d, Window window) canvas = window; init_canvas(); - if (window != DefaultRootWindow(dpy)) - XSelectInput(dpy,canvas,KeyPressMask|ButtonPressMask|ButtonMotionMask| - ButtonReleaseMask|ExposureMask|StructureNotifyMask); if (displayplanes > 1) { init_color(); } else { XQueryColors(dpy, DefaultColormap(dpy, DefaultScreen(dpy)), Colors, numcolors); } - pixmap = XCreatePixmap(dpy, DefaultRootWindow(dpy), - width, height, DefaultDepth(dpy, screen)); + pixmap = XCreatePixmap(dpy, window, width, height, xgwa.depth); rubber_data.band_cursor = XCreateFontCursor(dpy, XC_hand2); CreateXorGC(); Clear(); @@ -573,6 +577,9 @@ main_event(void) break; case ButtonRelease: EndRubberBand(canvas, &rubber_data, &event); + break; + default: + screenhack_handle_event (dpy, &event); break; } } @@ -587,13 +594,13 @@ main_event(void) static int complyap(void) { - register i, bindex; - double total, prod, x, r; + int i, bindex; + double total, prod, x, dx, r; if (!run) return TRUE; a += a_inc; - if (a >= max_a) + if (a >= max_a) { if (sendpoint(lyapunov) == TRUE) return FALSE; else { @@ -602,6 +609,7 @@ complyap(void) save_to_file(); return TRUE; } + } if (b >= max_b) { FlushBuffer(); if (savefile) @@ -637,7 +645,14 @@ complyap(void) if (useprod) { /* using log(a*b) */ for (i=0;i 1.0e12) || (prod < 1.0e-12)) { total += log(prod); @@ -657,12 +672,19 @@ complyap(void) #endif } total += log(prod); - lyapunov = (total * M_LOG2E) / (double)dwell; + lyapunov = (total * M_LOG2E) / (double)i; } else { /* use log(a) + log(b) */ for (i=0;i= maxindex) { bindex = 0; if (Rflag) @@ -676,8 +698,9 @@ complyap(void) deriv = Derivs[Forcing[findex]]; #endif } - lyapunov = (total * M_LOG2E) / (double)dwell; + lyapunov = (total * M_LOG2E) / (double)i; } + if (sendpoint(lyapunov) == TRUE) return FALSE; else { @@ -777,7 +800,6 @@ init_data(void) if (show) show_defaults(); InitBuffer(); - ya_rand_init(0); } static void @@ -789,7 +811,7 @@ init_canvas(void) * create default, writable, graphics contexts for the canvas. */ for (i=0; i maxexp) + expo = maxexp; +#endif + point.x++; tmpexpo = (negative) ? expo : -1.0 * expo; if (tmpexpo > 0) { @@ -1476,8 +1507,7 @@ resize(void) XClearWindow(dpy, canvas); if (pixmap) XFreePixmap(dpy, pixmap); - pixmap = XCreatePixmap(dpy, DefaultRootWindow(dpy), - width, height, DefaultDepth(dpy, screen)); + pixmap = XCreatePixmap(dpy, canvas, width, height, d); a_inc = a_range / (double)width; b_inc = b_range / (double)height; point.x = -1; @@ -1658,7 +1688,7 @@ CreateXorGC(void) values.foreground = foreground; values.line_style = LineSolid; values.function = GXxor; - RubberGC = XCreateGC(dpy, DefaultRootWindow(dpy), + RubberGC = XCreateGC(dpy, canvas, GCForeground | GCBackground | GCFunction | GCLineStyle, &values); } @@ -1846,6 +1876,14 @@ InitBuffer(void) static void BufferPoint(Display *display, Window window, int color, int x, int y) { + +/* Guard against bogus color values. Shouldn't be necessary but paranoia + is good. */ + if (color < 0) + color = 0; + else if (color >= maxcolor) + color = maxcolor - 1; + if (Points.npoints[color] == MAXPOINTS) { XDrawPoints(display, window, Data_GC[color], @@ -1961,5 +1999,5 @@ setforcing(void) { static int i; for (i=0;i prob) ? 0 : 1; + forcing[i] = (random() > prob) ? 0 : 1; }