1 /* Lyap - calculate and display Lyapunov exponents */
3 /* Written by Ron Record (rr@sco) 03 Sep 1991 */
5 /* The idea here is to calculate the Lyapunov exponent for a periodically
6 * forced logistic map (later i added several other nonlinear maps of the unit
7 * interval). In order to turn the 1-dimensional parameter space of the
8 * logistic map into a 2-dimensional parameter space, select two parameter
9 * values ('a' and 'b') then alternate the iterations of the logistic map using
10 * first 'a' then 'b' as the parameter. This program accepts an argument to
11 * specify a forcing function, so instead of just alternating 'a' and 'b', you
12 * can use 'a' as the parameter for say 6 iterations, then 'b' for 6 iterations
13 * and so on. An interesting forcing function to look at is abbabaab (the
14 * Morse-Thue sequence, an aperiodic self-similar, self-generating sequence).
15 * Anyway, step through all the values of 'a' and 'b' in the ranges you want,
16 * calculating the Lyapunov exponent for each pair of values. The exponent
17 * is calculated by iterating out a ways (specified by the variable "settle")
18 * then on subsequent iterations calculating an average of the logarithm of
19 * the absolute value of the derivative at that point. Points in parameter
20 * space with a negative Lyapunov exponent are colored one way (using the
21 * value of the exponent to index into a color map) while points with a
22 * non-negative exponent are colored differently.
24 * The algorithm was taken from the September 1991 Scientific American article
25 * by A. K. Dewdney who gives credit to Mario Markus of the Max Planck
26 * Institute for its creation. Additional information and ideas were gleaned
27 * from the discussion on alt.fractals involving Stephen Hall, Ed Kubaitis,
28 * Dave Platt and Baback Moghaddam. Assistance with colormaps and spinning
29 * color wheels and X was gleaned from Hiram Clawson. Rubber banding code was
30 * adapted from an existing Mandelbrot program written by Stacey Campbell.
33 #define LYAP_PATCHLEVEL 4
34 #define LYAP_VERSION "#(@) lyap 2.3 2/20/92"
39 #include "screenhack.h"
44 #define countof(x) (sizeof((x))/sizeof((*x)))
47 # include <X11/cursorfont.h>
50 static const char *xlyap_defaults [] = {
60 "*colorExponent: 1.0",
62 "*randomForce: ", /* 0.5 */
67 "*function: 10101010",
68 "*forcingFunction: abbabaab",
69 "*bRange: ", /* 2.0 */
71 "*mapIndex: ", /* 0 */
77 "*aRange: ", /* 2.0 */
84 static XrmOptionDescRec xlyap_options [] = {
85 { "-randomize", ".randomize", XrmoptionNoArg, "true" },
86 { "-builtin", ".builtin", XrmoptionSepArg, 0 },
87 { "-C", ".minColor", XrmoptionSepArg, 0 }, /* n */
88 { "-D", ".dwell", XrmoptionSepArg, 0 }, /* n */
89 { "-L", ".useLog", XrmoptionNoArg, "true" },
90 { "-M", ".colorExponent", XrmoptionSepArg, 0 }, /* r */
91 { "-O", ".colorOffset", XrmoptionSepArg, 0 }, /* n */
92 { "-R", ".randomForce", XrmoptionSepArg, 0 }, /* p */
93 { "-S", ".settle", XrmoptionSepArg, 0 }, /* n */
94 { "-a", ".minA", XrmoptionSepArg, 0 }, /* r */
95 { "-b", ".minB", XrmoptionSepArg, 0 }, /* n */
96 { "-c", ".wheels", XrmoptionSepArg, 0 }, /* n */
97 { "-F", ".function", XrmoptionSepArg, 0 }, /* 10101010 */
98 { "-f", ".forcingFunction", XrmoptionSepArg, 0 }, /* abbabaab */
99 { "-h", ".bRange", XrmoptionSepArg, 0 }, /* r */
100 { "-i", ".startX", XrmoptionSepArg, 0 }, /* r */
101 { "-m", ".mapIndex", XrmoptionSepArg, 0 }, /* n */
102 { "-o", ".outputFile", XrmoptionSepArg, 0 }, /* filename */
103 { "-p", ".beNegative", XrmoptionNoArg, "true" },
104 { "-r", ".rgbMax", XrmoptionSepArg, 0 }, /* n */
105 { "-s", ".spinLength", XrmoptionSepArg, 0 }, /* n */
106 { "-v", ".show", XrmoptionNoArg, "true" },
107 { "-w", ".aRange", XrmoptionSepArg, 0 }, /* r */
108 { "-delay", ".delay", XrmoptionSepArg, 0 }, /* delay */
109 { "-linger", ".linger", XrmoptionSepArg, 0 }, /* linger */
114 #define ABS(a) (((a)<0) ? (0-(a)) : (a) )
115 #define Min(x,y) ((x < y)?x:y)
116 #define Max(x,y) ((x > y)?x:y)
118 #ifdef SIXTEEN_COLORS
119 # define MAXPOINTS 128
124 # endif /* !BIGMEM */
126 #else /* !SIXTEEN_COLORS */
127 # define MAXPOINTS 256
132 # endif /* !BIGMEM */
133 # define MAXCOLOR 256
134 #endif /* !SIXTEEN_COLORS */
138 #define FUNCMAXINDEX 16
155 int start_x, start_y;
157 } rubber_band_data_t;
164 double p_min, p_max, q_min, q_max;
165 /* rubber_band_data_t rubber_band;*/
168 typedef struct points_t {
169 XPoint data[MAXCOLOR][MAXPOINTS];
170 int npoints[MAXCOLOR];
174 typedef double (*PFD)(double,double);
176 /* #### What was this for? Everything was drawn twice, to the window and
177 to this, and this was never displayed! */
178 /*#define BACKING_PIXMAP*/
186 unsigned long foreground, background;
191 unsigned int maxcolor, startcolor, mincolindex;
194 int width, height, xposition, yposition;
197 /* image_data_t rubber_data;*/
199 GC Data_GC[MAXCOLOR]/*, RubberGC*/;
202 int aflag, bflag, wflag, hflag, Rflag;
206 double min_a, min_b, a_range, b_range, minlyap;
208 double start_x, lyapunov, a_inc, b_inc, a, b;
209 int numcolors, numfreecols, lowrange;
211 #ifdef BACKING_PIXMAP
214 /* XColor Colors[MAXCOLOR];*/
215 double *exponents[MAXFRAMES];
216 double a_minimums[MAXFRAMES], b_minimums[MAXFRAMES];
217 double a_maximums[MAXFRAMES], b_maximums[MAXFRAMES];
218 double minexp, maxexp, prob;
219 int expind[MAXFRAMES], resized[MAXFRAMES];
220 int numwheels, force, Force, negative;
221 int rgb_max, nostart, stripe_interval;
222 int save, show, useprod, spinlength;
223 int maxframe, frame, dorecalc, mapindex, run;
228 int forcing[MAXINDEX];
229 int Forcing[FUNCMAXINDEX];
234 XColor colors[MAXCOLOR];
238 static const double pmins[NUMMAPS] = { 2.0, 0.0, 0.0, 0.0, 0.0 };
239 static const double pmaxs[NUMMAPS] = { 4.0, 1.0, 6.75, 6.75, 16.0 };
240 static const double amins[NUMMAPS] = { 2.0, 0.0, 0.0, 0.0, 0.0 };
241 static const double aranges[NUMMAPS] = { 2.0, 1.0, 6.75, 6.75, 16.0 };
242 static const double bmins[NUMMAPS] = { 2.0, 0.0, 0.0, 0.0, 0.0 };
243 static const double branges[NUMMAPS] = { 2.0, 1.0, 6.75, 6.75, 16.0 };
245 /****************************************************************************/
247 /* callback function declarations
250 static double logistic(double,double);
251 static double circle(double,double);
252 static double leftlog(double,double);
253 static double rightlog(double,double);
254 static double doublelog(double,double);
255 static double dlogistic(double,double);
256 static double dcircle(double,double);
257 static double dleftlog(double,double);
258 static double drightlog(double,double);
259 static double ddoublelog(double,double);
261 static const PFD Maps[NUMMAPS] = { logistic, circle, leftlog, rightlog,
263 static const PFD Derivs[NUMMAPS] = { dlogistic, dcircle, dleftlog,
264 drightlog, ddoublelog };
267 /****************************************************************************/
269 /* other function declarations
272 static void resize(struct state *);
273 /*static void Spin(struct state *);*/
274 static void show_defaults(struct state *);
275 /*static void StartRubberBand(struct state *, image_data_t *, XEvent *);
276 static void TrackRubberBand(struct state *, image_data_t *, XEvent *);
277 static void EndRubberBand(struct state *, image_data_t *, XEvent *);*/
278 /*static void CreateXorGC(struct state *);*/
279 static void InitBuffer(struct state *);
280 static void BufferPoint(struct state *, int color, int x, int y);
281 static void FlushBuffer(struct state *);
282 static void init_data(struct state *);
283 static void init_color(struct state *);
284 static void parseargs(struct state *);
285 static void Clear(struct state *);
286 static void setupmem(struct state *);
287 static int complyap(struct state *);
288 static Bool Getkey(struct state *, XKeyEvent *);
289 static int sendpoint(struct state *, double expo);
290 /*static void save_to_file(struct state *);*/
291 static void setforcing(struct state *);
292 static void check_params(struct state *, int mapnum, int parnum);
293 static void usage(struct state *);
294 static void Destroy_frame(struct state *);
295 static void freemem(struct state *);
296 static void Redraw(struct state *);
297 static void redraw(struct state *, double *exparray, int index, int cont);
298 static void recalc(struct state *);
299 /*static void SetupCorners(XPoint *, image_data_t *);
300 static void set_new_params(struct state *, image_data_t *);*/
301 static void go_down(struct state *);
302 static void go_back(struct state *);
303 static void go_init(struct state *);
304 static void jumpwin(struct state *);
305 static void print_help(struct state *);
306 static void print_values(struct state *);
309 /****************************************************************************/
312 /* complyap() is the guts of the program. This is where the Lyapunov exponent
313 * is calculated. For each iteration (past some large number of iterations)
314 * calculate the logarithm of the absolute value of the derivative at that
315 * point. Then average them over some large number of iterations. Some small
316 * speed up is achieved by utilizing the fact that log(a*b) = log(a) + log(b).
319 complyap(struct state *st)
322 double total, prod, x, dx, r;
324 if (st->maxcolor > MAXCOLOR)
330 if (st->a >= st->max_a) {
331 if (sendpoint(st, st->lyapunov) == TRUE)
340 if (st->b >= st->max_b) {
350 r = (st->forcing[bindex]) ? st->b : st->a;
353 map = Maps[st->Forcing[findex]];
355 for (i=0;i<st->settle;i++) { /* Here's where we let the thing */
356 x = st->map (x, r); /* "settle down". There is usually */
357 if (++bindex >= st->maxindex) { /* some initial "noise" in the */
358 bindex = 0; /* iterations. How can we optimize */
359 if (st->Rflag) /* the value of settle ??? */
362 r = (st->forcing[bindex]) ? st->b : st->a;
364 if (++findex >= funcmaxindex)
366 map = Maps[st->Forcing[findex]];
370 deriv = Derivs[st->Forcing[findex]];
372 if (st->useprod) { /* using log(a*b) */
373 for (i=0;i<st->dwell;i++) {
375 dx = st->deriv (x, r); /* ABS is a macro, so don't be fancy */
377 if (dx == 0.0) /* log(0) is nasty so break out. */
383 /* we need to prevent overflow and underflow */
384 if ((prod > 1.0e12) || (prod < 1.0e-12)) {
388 if (++bindex >= st->maxindex) {
393 r = (st->forcing[bindex]) ? st->b : st->a;
395 if (++findex >= funcmaxindex)
397 map = Maps[st->Forcing[findex]];
398 deriv = Derivs[st->Forcing[findex]];
402 st->lyapunov = (total * M_LOG2E) / (double)i;
404 else { /* use log(a) + log(b) */
405 for (i=0;i<st->dwell;i++) {
407 dx = st->deriv (x, r); /* ABS is a macro, so don't be fancy */
409 if (x == 0.0) /* log(0) check */
415 if (++bindex >= st->maxindex) {
420 r = (st->forcing[bindex]) ? st->b : st->a;
422 if (++findex >= funcmaxindex)
424 map = Maps[st->Forcing[findex]];
425 deriv = Derivs[st->Forcing[findex]];
428 st->lyapunov = (total * M_LOG2E) / (double)i;
431 if (sendpoint(st, st->lyapunov) == TRUE)
442 logistic(double x, double r) /* the familiar logistic map */
444 return(r * x * (1.0 - x));
448 dlogistic(double x, double r) /* the derivative of logistic map */
450 return(r - (2.0 * r * x));
454 circle(double x, double r) /* sin() hump or sorta like the circle map */
456 return(r * sin(M_PI * x));
460 dcircle(double x, double r) /* derivative of the "sin() hump" */
462 return(r * M_PI * cos(M_PI * x));
466 leftlog(double x, double r) /* left skewed logistic */
471 return(r * x * d * d);
475 dleftlog(double x, double r) /* derivative of the left skewed logistic */
477 return(r * (1.0 - (4.0 * x) + (3.0 * x * x)));
481 rightlog(double x, double r) /* right skewed logistic */
483 return(r * x * x * (1.0 - x));
487 drightlog(double x, double r) /* derivative of the right skewed logistic */
489 return(r * ((2.0 * x) - (3.0 * x * x)));
493 doublelog(double x, double r) /* double logistic */
498 return(r * x * x * d * d);
502 ddoublelog(double x, double r) /* derivative of the double logistic */
507 return(r * ((2.0 * x) - (6.0 * d) + (4.0 * x * d)));
511 init_data(struct state *st)
513 st->numcolors = get_integer_resource (st->dpy, "colors", "Integer");
514 if (st->numcolors < 2)
516 if (st->numcolors > st->maxcolor)
517 st->numcolors = st->maxcolor;
518 st->numfreecols = st->numcolors - st->mincolindex;
519 st->lowrange = st->mincolindex - st->startcolor;
520 st->a_inc = st->a_range / (double)st->width;
521 st->b_inc = st->b_range / (double)st->height;
524 st->a = /*st->rubber_data.p_min = */st->min_a;
525 st->b = /*st->rubber_data.q_min = */st->min_b;
526 /* st->rubber_data.p_max = st->max_a;
527 st->rubber_data.q_max = st->max_b;*/
535 hls2rgb(int hue_light_sat[3],
536 int rgb[3]) /* Each in range [0..65535] */
538 unsigned short r, g, b;
539 hsv_to_rgb((int) (hue_light_sat[0] / 10), /* 0-3600 -> 0-360 */
540 (int) ((hue_light_sat[2]/1000.0) * 64435), /* 0-1000 -> 0-65535 */
541 (int) ((hue_light_sat[1]/1000.0) * 64435), /* 0-1000 -> 0-65535 */
551 init_color(struct state *st)
555 free_colors (st->dpy, st->cmap, st->colors, st->ncolors);
556 st->ncolors = st->maxcolor;
557 make_smooth_colormap(st->dpy, st->visual, st->cmap,
558 st->colors, &st->ncolors, True, NULL, True);
560 for (i = 0; i < st->maxcolor; i++) {
561 if (! st->Data_GC[i]) {
563 gcv.background = BlackPixel(st->dpy, st->screen);
564 st->Data_GC[i] = XCreateGC(st->dpy, st->canvas, GCBackground, &gcv);
566 XSetForeground(st->dpy, st->Data_GC[i],
567 st->colors[((int) ((i / ((float)st->maxcolor)) *
568 st->ncolors))].pixel);
574 parseargs(struct state *st)
577 int bindex=0, findex;
581 st->deriv = Derivs[0];
582 st->maxexp=st->minlyap; st->minexp= -1.0 * st->minlyap;
584 st->mincolindex = get_integer_resource(st->dpy, "minColor", "Integer");
585 st->dwell = get_integer_resource(st->dpy, "dwell", "Integer");
588 char *optarg = get_string_resource(st->dpy, "function", "String");
589 funcmaxindex = strlen(optarg);
590 if (funcmaxindex > FUNCMAXINDEX)
594 for (findex=0;findex<funcmaxindex;findex++) {
595 st->Forcing[findex] = (int)(*ch++ - '0');;
596 if (st->Forcing[findex] >= NUMMAPS)
601 if (get_boolean_resource(st->dpy, "useLog", "Boolean"))
604 st->minlyap=ABS(get_float_resource(st->dpy, "colorExponent", "Float"));
605 st->maxexp=st->minlyap;
606 st->minexp= -1.0 * st->minlyap;
608 st->color_offset = get_integer_resource(st->dpy, "colorOffset", "Integer");
610 st->maxcolor=ABS(get_integer_resource(st->dpy, "maxColor", "Integer"));
611 if ((st->maxcolor - st->startcolor) <= 0)
612 st->startcolor = get_pixel_resource(st->dpy, st->cmap,
613 "background", "Background");
614 if ((st->maxcolor - st->mincolindex) <= 0) {
616 st->color_offset = 0;
619 s = get_string_resource(st->dpy, "randomForce", "Float");
621 st->prob=atof(s); st->Rflag++; setforcing(st);
624 st->settle = get_integer_resource(st->dpy, "settle", "Integer");
627 s = get_string_resource(st->dpy, "minA", "Float");
633 s = get_string_resource(st->dpy, "minB", "Float");
635 st->min_b=atof(s); st->bflag++;
638 st->min_a = get_float_resource (st->dpy, "minA", "Float");
640 st->min_b = get_float_resource (st->dpy, "minB", "Float");
645 st->numwheels = get_integer_resource(st->dpy, "wheels", "Integer");
647 s = get_string_resource(st->dpy, "forcingFunction", "String");
649 st->maxindex = strlen(s);
650 if (st->maxindex > MAXINDEX)
654 while (bindex < st->maxindex) {
656 st->forcing[bindex++] = 0;
658 st->forcing[bindex++] = 1;
665 s = get_string_resource(st->dpy, "bRange", "Float");
667 st->b_range = atof(s);
671 st->start_x = get_float_resource(st->dpy, "startX", "Float");
673 s = get_string_resource(st->dpy, "mapIndex", "Integer");
675 st->mapindex=atoi(s);
676 if ((st->mapindex >= NUMMAPS) || (st->mapindex < 0))
678 st->map = Maps[st->mapindex];
679 st->deriv = Derivs[st->mapindex];
681 st->min_a = amins[st->mapindex];
683 st->a_range = aranges[st->mapindex];
685 st->min_b = bmins[st->mapindex];
687 st->b_range = branges[st->mapindex];
689 for (i=0;i<FUNCMAXINDEX;i++)
690 st->Forcing[i] = st->mapindex;
693 st->outname = get_string_resource(st->dpy, "outputFile", "Integer");
695 if (get_boolean_resource(st->dpy, "beNegative", "Boolean"))
698 st->rgb_max = get_integer_resource(st->dpy, "rgbMax", "Integer");
699 st->spinlength = get_integer_resource(st->dpy, "spinLength", "Integer");
700 st->show = get_boolean_resource(st->dpy, "show", "Boolean");
702 s = get_string_resource(st->dpy, "aRange", "Float");
704 st->a_range = atof(s); st->wflag++;
707 st->max_a = st->min_a + st->a_range;
708 st->max_b = st->min_b + st->b_range;
710 st->a_minimums[0] = st->min_a; st->b_minimums[0] = st->min_b;
711 st->a_maximums[0] = st->max_a; st->b_maximums[0] = st->max_b;
714 if (st->maxindex == st->funcmaxindex)
715 for (findex=0;findex<st->funcmaxindex;findex++)
716 check_params(st, st->Forcing[findex],st->forcing[findex]);
718 fprintf(stderr, "Warning! Unable to check parameters\n");
720 check_params(st, st->mapindex,2);
724 check_params(struct state *st, int mapnum, int parnum)
728 if ((st->max_a > pmaxs[mapnum]) || (st->min_a < pmins[mapnum])) {
729 fprintf(stderr, "Warning! Parameter 'a' out of range.\n");
730 fprintf(stderr, "You have requested a range of (%f,%f).\n",
731 st->min_a,st->max_a);
732 fprintf(stderr, "Valid range is (%f,%f).\n",
733 pmins[mapnum],pmaxs[mapnum]);
737 if ((st->max_b > pmaxs[mapnum]) || (st->min_b < pmins[mapnum])) {
738 fprintf(stderr, "Warning! Parameter 'b' out of range.\n");
739 fprintf(stderr, "You have requested a range of (%f,%f).\n",
740 st->min_b,st->max_b);
741 fprintf(stderr, "Valid range is (%f,%f).\n",
742 pmins[mapnum],pmaxs[mapnum]);
748 usage(struct state *st)
750 fprintf(stderr,"lyap [-BLs][-W#][-H#][-a#][-b#][-w#][-h#][-x xstart]\n");
751 fprintf(stderr,"\t[-M#][-S#][-D#][-f string][-r#][-O#][-C#][-c#][-m#]\n");
753 fprintf(stderr,"\t[-F string]\n");
755 fprintf(stderr,"\tWhere: -C# specifies the minimum color index\n");
756 fprintf(stderr,"\t -r# specifies the maxzimum rgb value\n");
757 fprintf(stderr,"\t -u displays this message\n");
758 fprintf(stderr,"\t -a# specifies the minimum horizontal parameter\n");
759 fprintf(stderr,"\t -b# specifies the minimum vertical parameter\n");
760 fprintf(stderr,"\t -w# specifies the horizontal parameter range\n");
761 fprintf(stderr,"\t -h# specifies the vertical parameter range\n");
762 fprintf(stderr,"\t -D# specifies the dwell\n");
763 fprintf(stderr,"\t -S# specifies the settle\n");
764 fprintf(stderr,"\t -H# specifies the initial window height\n");
765 fprintf(stderr,"\t -W# specifies the initial window width\n");
766 fprintf(stderr,"\t -O# specifies the color offset\n");
767 fprintf(stderr,"\t -c# specifies the desired color wheel\n");
768 fprintf(stderr,"\t -m# specifies the desired map (0-4)\n");
769 fprintf(stderr,"\t -f aabbb specifies a forcing function of 00111\n");
771 fprintf(stderr,"\t -F 00111 specifies the function forcing function\n");
773 fprintf(stderr,"\t -L indicates use log(x)+log(y) rather than log(xy)\n");
774 fprintf(stderr,"\tDuring display :\n");
775 fprintf(stderr,"\t Use the mouse to zoom in on an area\n");
776 fprintf(stderr,"\t e or E recalculates color indices\n");
777 fprintf(stderr,"\t f or F saves exponents to a file\n");
778 fprintf(stderr,"\t KJmn increase/decrease minimum negative exponent\n");
779 fprintf(stderr,"\t r or R redraws\n");
780 fprintf(stderr,"\t s or S spins the colorwheel\n");
781 fprintf(stderr,"\t w or W changes the color wheel\n");
782 fprintf(stderr,"\t x or X clears the window\n");
783 fprintf(stderr,"\t q or Q exits\n");
788 Cycle_frames(struct state *st)
791 for (i=0;i<=st->maxframe;i++)
792 redraw(st, st->exponents[i], st->expind[i], 1);
797 Spin(struct state *st)
803 for (j=0;j<st->spinlength;j++) {
804 tmpxcolor = st->Colors[st->mincolindex].pixel;
805 for (i=st->mincolindex;i<st->numcolors-1;i++)
806 st->Colors[i].pixel = st->Colors[i+1].pixel;
807 st->Colors[st->numcolors-1].pixel = tmpxcolor;
808 XStoreColors(st->dpy, st->cmap, st->Colors, st->numcolors);
810 for (j=0;j<st->spinlength;j++) {
811 tmpxcolor = st->Colors[st->numcolors-1].pixel;
812 for (i=st->numcolors-1;i>st->mincolindex;i--)
813 st->Colors[i].pixel = st->Colors[i-1].pixel;
814 st->Colors[st->mincolindex].pixel = tmpxcolor;
815 XStoreColors(st->dpy, st->cmap, st->Colors, st->numcolors);
822 Getkey(struct state *st, XKeyEvent *event)
826 if (XLookupString(event, (char *)&key, sizeof(key), (KeySym *)0,
827 (XComposeStatus *) 0) > 0)
829 if (st->reset_countdown)
830 st->reset_countdown = st->linger;
833 case '<': st->dwell /= 2; if (st->dwell < 1) st->dwell = 1; return True;
834 case '>': st->dwell *= 2; return True;
835 case '[': st->settle /= 2; if (st->settle < 1) st->settle = 1; return True;
836 case ']': st->settle *= 2; return True;
837 case 'd': go_down(st); return True;
838 case 'D': FlushBuffer(st); return True;
840 case 'E': FlushBuffer(st);
841 st->dorecalc = (!st->dorecalc);
845 st->maxexp = st->minlyap; st->minexp = -1.0 * st->minlyap;
847 redraw(st, st->exponents[st->frame], st->expind[st->frame], 1);
850 /* case 'F': save_to_file(); return True;*/
851 case 'i': if (st->stripe_interval > 0) {
852 st->stripe_interval--;
858 case 'I': st->stripe_interval++;
863 case 'K': if (st->minlyap > 0.05)
866 case 'J': st->minlyap += 0.05;
868 case 'm': st->mapindex++;
869 if (st->mapindex >= NUMMAPS)
871 st->map = Maps[st->mapindex];
872 st->deriv = Derivs[st->mapindex];
874 st->min_a = amins[st->mapindex];
876 st->a_range = aranges[st->mapindex];
878 st->min_b = bmins[st->mapindex];
880 st->b_range = branges[st->mapindex];
882 for (i=0;i<FUNCMAXINDEX;i++)
883 st->Forcing[i] = st->mapindex;
884 st->max_a = st->min_a + st->a_range;
885 st->max_b = st->min_b + st->b_range;
886 st->a_minimums[0] = st->min_a; st->b_minimums[0] = st->min_b;
887 st->a_maximums[0] = st->max_a; st->b_maximums[0] = st->max_b;
888 st->a_inc = st->a_range / (double)st->width;
889 st->b_inc = st->b_range / (double)st->height;
892 st->a = /*st->rubber_data.p_min = */st->min_a;
893 st->b = /*st->rubber_data.q_min = */st->min_b;
894 /* st->rubber_data.p_max = st->max_a;
895 st->rubber_data.q_max = st->max_b;*/
898 case 'M': if (st->minlyap > 0.005)
899 st->minlyap -= 0.005;
901 case 'N': st->minlyap += 0.005;
904 case 'P': st->negative = (!st->negative);
905 FlushBuffer(st); redraw(st, st->exponents[st->frame],
906 st->expind[st->frame], 1);
908 case 'r': FlushBuffer(st); redraw(st, st->exponents[st->frame],
909 st->expind[st->frame], 1);
911 case 'R': FlushBuffer(st); Redraw(st); return True;
913 st->spinlength=st->spinlength/2;
915 case 'S': if (!mono_p)
917 st->spinlength=st->spinlength*2; return True;
919 case 'u': go_back(st); return True;
920 case 'U': go_init(st); return True;
922 case 'V': print_values(st); return True;
923 case 'W': if (st->numwheels < MAXWHEELS)
931 case 'w': if (st->numwheels > 0)
934 st->numwheels = MAXWHEELS;
939 case 'x': Clear(st); return True;
940 case 'X': Destroy_frame(st); return True;
941 case 'z': Cycle_frames(st); redraw(st, st->exponents[st->frame],
942 st->expind[st->frame], 1);
945 case 'Z': while (!XPending(st->dpy)) Cycle_frames(st);
946 redraw(st, st->exponents[st->frame], st->expind[st->frame], 1);
950 case 'Q': exit(0); return True;
953 case 'H': print_help(st); return True;
954 default: return False;
960 /* Here's where we index into a color map. After the Lyapunov exponent is
961 * calculated, it is used to determine what color to use for that point. I
962 * suppose there are a lot of ways to do this. I used the following : if it's
963 * non-negative then there's a reserved area at the lower range of the color
964 * map that i index into. The ratio of some "minimum exponent value" and the
965 * calculated value is used as a ratio of how high to index into this reserved
966 * range. Usually these colors are dark red (see init_color). If the exponent
967 * is negative, the same ratio (expo/minlyap) is used to index into the
968 * remaining portion of the colormap (which is usually some light shades of
969 * color or a rainbow wheel). The coloring scheme can actually make a great
970 * deal of difference in the quality of the picture. Different colormaps bring
971 * out different details of the dynamics while different indexing algorithms
972 * also greatly effect what details are seen. Play around with this.
975 sendpoint(struct state *st, double expo)
979 if (st->maxcolor > MAXCOLOR)
983 /* The relationship st->minexp <= expo <= maxexp should always be true. This
984 test enforces that. But maybe not enforcing it makes better pictures. */
985 if (expo < st->minexp)
987 else if (expo > maxexp)
992 tmpexpo = (st->negative) ? expo : -1.0 * expo;
995 st->sendpoint_index = (int)(tmpexpo*st->lowrange/st->maxexp);
996 st->sendpoint_index = ((st->sendpoint_index % st->lowrange) +
1000 st->sendpoint_index = 0;
1004 st->sendpoint_index = (int)(tmpexpo*st->numfreecols/st->minexp);
1005 st->sendpoint_index = ((st->sendpoint_index % st->numfreecols)
1009 st->sendpoint_index = 1;
1011 BufferPoint(st, st->sendpoint_index, st->point.x, st->point.y);
1013 if (st->frame > MAXFRAMES)
1015 st->exponents[st->frame][st->expind[st->frame]++] = expo;
1017 if (st->point.x >= st->width) {
1024 if (st->point.y >= st->height)
1034 resize(struct state *st)
1038 unsigned int bw, d, new_w, new_h;
1040 XGetGeometry(st->dpy,st->canvas,&r,&x,&y,&new_w,&new_h,&bw,&d);
1041 if ((new_w == st->width) && (new_h == st->height))
1043 st->width = new_w; st->height = new_h;
1044 XClearWindow(st->dpy, st->canvas);
1045 #ifdef BACKING_PIXMAP
1047 XFreePixmap(st->dpy, st->pixmap);
1048 st->pixmap = XCreatePixmap(st->dpy, st->canvas, st->width, st->height, d);
1050 st->a_inc = st->a_range / (double)st->width;
1051 st->b_inc = st->b_range / (double)st->height;
1055 st->a = /*st->rubber_data.p_min = */st->min_a;
1056 st->b = /*st->rubber_data.q_min = */st->min_b;
1057 /* st->rubber_data.p_max = st->max_a;
1058 st->rubber_data.q_max = st->max_b;*/
1061 for (n=0;n<MAXFRAMES;n++)
1062 if ((n <= st->maxframe) && (n != st->frame))
1070 redraw(struct state *st, double *exparray, int index, int cont)
1072 int i, x_sav, y_sav;
1074 x_sav = st->point.x;
1075 y_sav = st->point.y;
1081 for (i=0;i<index;i++)
1082 sendpoint(st, exparray[i]);
1086 st->point.x = x_sav;
1087 st->point.y = y_sav;
1090 st->a = st->point.x * st->a_inc + st->min_a;
1091 st->b = st->point.y * st->b_inc + st->min_b;
1097 Redraw(struct state *st)
1105 st->expind[st->frame] = 0;
1106 st->resized[st->frame] = 0;
1110 recalc(struct state *st)
1114 st->minexp = st->maxexp = 0.0;
1115 for (i=0;i<st->expind[st->frame];i++) {
1116 if (st->exponents[st->frame][i] < st->minexp)
1117 st->minexp = st->exponents[st->frame][i];
1118 if (st->exponents[st->frame][i] > st->maxexp)
1119 st->maxexp = st->exponents[st->frame][i];
1124 Clear(struct state *st)
1126 XClearWindow(st->dpy, st->canvas);
1127 #ifdef BACKING_PIXMAP
1128 XCopyArea(st->dpy, st->canvas, st->pixmap, st->Data_GC[0],
1129 0, 0, st->width, st->height, 0, 0);
1135 show_defaults(struct state *st)
1138 printf("Width=%d Height=%d numcolors=%d settle=%d dwell=%d\n",
1139 st->width,st->height,st->numcolors,st->settle,st->dwell);
1140 printf("min_a=%f a_range=%f max_a=%f\n", st->min_a,st->a_range,st->max_a);
1141 printf("min_b=%f b_range=%f max_b=%f\n", st->min_b,st->b_range,st->max_b);
1142 printf("minlyap=%f minexp=%f maxexp=%f\n", st->minlyap,st->minexp,
1149 CreateXorGC(struct state *st)
1153 values.foreground = st->foreground;
1154 values.function = GXxor;
1155 st->RubberGC = XCreateGC(st->dpy, st->canvas,
1156 GCForeground | GCFunction, &values);
1160 StartRubberBand(struct state *st, image_data_t *data, XEvent *event)
1165 data->rubber_band.last_x = data->rubber_band.start_x = event->xbutton.x;
1166 data->rubber_band.last_y = data->rubber_band.start_y = event->xbutton.y;
1167 SetupCorners(corners, data);
1168 XDrawLines(st->dpy, st->canvas, st->RubberGC,
1169 corners, sizeof(corners) / sizeof(corners[0]), CoordModeOrigin);
1173 SetupCorners(XPoint *corners, image_data_t *data)
1175 corners[0].x = data->rubber_band.start_x;
1176 corners[0].y = data->rubber_band.start_y;
1177 corners[1].x = data->rubber_band.start_x;
1178 corners[1].y = data->rubber_band.last_y;
1179 corners[2].x = data->rubber_band.last_x;
1180 corners[2].y = data->rubber_band.last_y;
1181 corners[3].x = data->rubber_band.last_x;
1182 corners[3].y = data->rubber_band.start_y;
1183 corners[4] = corners[0];
1187 TrackRubberBand(struct state *st, image_data_t *data, XEvent *event)
1194 SetupCorners(corners, data);
1195 XDrawLines(st->dpy, st->canvas, st->RubberGC,
1196 corners, sizeof(corners) / sizeof(corners[0]), CoordModeOrigin);
1197 ydiff = event->xbutton.y - data->rubber_band.start_y;
1198 xdiff = event->xbutton.x - data->rubber_band.start_x;
1199 data->rubber_band.last_x = data->rubber_band.start_x + xdiff;
1200 data->rubber_band.last_y = data->rubber_band.start_y + ydiff;
1201 if (data->rubber_band.last_y < data->rubber_band.start_y ||
1202 data->rubber_band.last_x < data->rubber_band.start_x)
1204 data->rubber_band.last_y = data->rubber_band.start_y;
1205 data->rubber_band.last_x = data->rubber_band.start_x;
1207 SetupCorners(corners, data);
1208 XDrawLines(st->dpy, st->canvas, st->RubberGC,
1209 corners, sizeof(corners) / sizeof(corners[0]), CoordModeOrigin);
1213 EndRubberBand(struct state *st, image_data_t *data, XEvent *event)
1220 SetupCorners(corners, data);
1221 XDrawLines(st->dpy, st->canvas, st->RubberGC,
1222 corners, sizeof(corners) / sizeof(corners[0]), CoordModeOrigin);
1223 if (data->rubber_band.start_x >= data->rubber_band.last_x ||
1224 data->rubber_band.start_y >= data->rubber_band.last_y)
1226 top.x = data->rubber_band.start_x;
1227 bot.x = data->rubber_band.last_x;
1228 top.y = data->rubber_band.start_y;
1229 bot.y = data->rubber_band.last_y;
1230 diff = data->q_max - data->q_min;
1231 delta = (double)top.y / (double)st->height;
1232 data->q_min += diff * delta;
1233 delta = (double)(st->height - bot.y) / (double)st->height;
1234 data->q_max -= diff * delta;
1235 diff = data->p_max - data->p_min;
1236 delta = (double)top.x / (double)st->width;
1237 data->p_min += diff * delta;
1238 delta = (double)(st->width - bot.x) / (double)st->width;
1239 data->p_max -= diff * delta;
1241 set_new_params(st, data);
1245 set_new_params(struct state *st, image_data_t *data)
1247 st->frame = (st->maxframe + 1) % MAXFRAMES;
1248 if (st->frame > st->maxframe)
1249 st->maxframe = st->frame;
1250 st->a_range = data->p_max - data->p_min;
1251 st->b_range = data->q_max - data->q_min;
1252 st->a_minimums[st->frame] = st->min_a = data->p_min;
1253 st->b_minimums[st->frame] = st->min_b = data->q_min;
1254 st->a_inc = st->a_range / (double)st->width;
1255 st->b_inc = st->b_range / (double)st->height;
1261 st->a_maximums[st->frame] = st->max_a = data->p_max;
1262 st->b_maximums[st->frame] = st->max_b = data->q_max;
1263 st->expind[st->frame] = 0;
1269 go_down(struct state *st)
1272 if (st->frame > st->maxframe)
1278 go_back(struct state *st)
1282 st->frame = st->maxframe;
1287 jumpwin(struct state *st)
1289 /*st->rubber_data.p_min =*/ st->min_a = st->a_minimums[st->frame];
1290 /*st->rubber_data.q_min =*/ st->min_b = st->b_minimums[st->frame];
1291 /*st->rubber_data.p_max =*/ st->max_a = st->a_maximums[st->frame];
1292 /*st->rubber_data.q_max =*/ st->max_b = st->b_maximums[st->frame];
1293 st->a_range = st->max_a - st->min_a;
1294 st->b_range = st->max_b - st->min_b;
1295 st->a_inc = st->a_range / (double)st->width;
1296 st->b_inc = st->b_range / (double)st->height;
1302 if (st->resized[st->frame])
1305 redraw(st, st->exponents[st->frame], st->expind[st->frame], 0);
1309 go_init(struct state *st)
1316 Destroy_frame(struct state *st)
1320 for (i=st->frame; i<st->maxframe; i++) {
1321 st->exponents[st->frame] = st->exponents[st->frame+1];
1322 st->expind[st->frame] = st->expind[st->frame+1];
1323 st->a_minimums[st->frame] = st->a_minimums[st->frame+1];
1324 st->b_minimums[st->frame] = st->b_minimums[st->frame+1];
1325 st->a_maximums[st->frame] = st->a_maximums[st->frame+1];
1326 st->b_maximums[st->frame] = st->b_maximums[st->frame+1];
1333 InitBuffer(struct state *st)
1337 for (i = 0 ; i < st->maxcolor; ++i)
1338 st->Points.npoints[i] = 0;
1342 BufferPoint(struct state *st, int color, int x, int y)
1344 if (st->maxcolor > MAXCOLOR)
1347 /* Guard against bogus color values. Shouldn't be necessary but paranoia
1351 else if (color >= st->maxcolor)
1352 color = st->maxcolor - 1;
1354 if (st->Points.npoints[color] == MAXPOINTS)
1356 XDrawPoints(st->dpy, st->canvas, st->Data_GC[color],
1357 st->Points.data[color], st->Points.npoints[color],
1359 #ifdef BACKING_PIXMAP
1360 XDrawPoints(st->dpy, st->pixmap, st->Data_GC[color],
1361 st->Points.data[color], st->Points.npoints[color],
1364 st->Points.npoints[color] = 0;
1366 st->Points.data[color][st->Points.npoints[color]].x = x;
1367 st->Points.data[color][st->Points.npoints[color]].y = y;
1368 ++st->Points.npoints[color];
1372 FlushBuffer(struct state *st)
1376 for (color = 0; color < st->maxcolor; ++color)
1377 if (st->Points.npoints[color])
1379 XDrawPoints(st->dpy, st->canvas, st->Data_GC[color],
1380 st->Points.data[color], st->Points.npoints[color],
1382 #ifdef BACKING_PIXMAP
1383 XDrawPoints(st->dpy, st->pixmap, st->Data_GC[color],
1384 st->Points.data[color], st->Points.npoints[color],
1387 st->Points.npoints[color] = 0;
1392 print_help(struct state *st)
1394 printf("During run-time, interactive control can be exerted via : \n");
1395 printf("Mouse buttons allow rubber-banding of a zoom box\n");
1396 printf("< halves the 'dwell', > doubles the 'dwell'\n");
1397 printf("[ halves the 'settle', ] doubles the 'settle'\n");
1398 printf("D flushes the drawing buffer\n");
1399 printf("e or E recalculates color indices\n");
1400 printf("f or F saves exponents to a file\n");
1401 printf("h or H or ? displays this message\n");
1402 printf("i decrements, I increments the stripe interval\n");
1403 printf("KJMN increase/decrease minimum negative exponent\n");
1404 printf("m increments the map index, changing maps\n");
1405 printf("p or P reverses the colormap for negative/positive exponents\n");
1406 printf("r redraws without recalculating\n");
1407 printf("R redraws, recalculating with new dwell and settle values\n");
1408 printf("s or S spins the colorwheel\n");
1409 printf("u pops back up to the last zoom\n");
1410 printf("U pops back up to the first picture\n");
1411 printf("v or V displays the values of various settings\n");
1412 printf("w decrements, W increments the color wheel index\n");
1413 printf("x or X clears the window\n");
1414 printf("q or Q exits\n");
1418 print_values(struct state *st)
1421 printf("\nminlyap=%f minexp=%f maxexp=%f\n",
1422 st->minlyap,st->minexp, st->maxexp);
1423 printf("width=%d height=%d\n",st->width,st->height);
1424 printf("settle=%d dwell=%d st->start_x=%f\n",
1425 st->settle,st->dwell, st->start_x);
1426 printf("min_a=%f a_rng=%f max_a=%f\n",
1427 st->min_a,st->a_range,st->max_a);
1428 printf("min_b=%f b_rng=%f max_b=%f\n",
1429 st->min_b,st->b_range,st->max_b);
1431 printf("pseudo-random forcing\n");
1432 else if (st->force) {
1433 printf("periodic forcing=");
1434 for (i=0;i<st->maxindex;i++)
1435 printf("%d",st->forcing[i]);
1439 printf("periodic forcing=01\n");
1441 printf("function forcing=");
1442 for (i=0;i<st->funcmaxindex;i++) {
1443 printf("%d",st->Forcing[i]);
1447 printf("numcolors=%d\n",st->numcolors-1);
1451 freemem(struct state *st)
1454 for (i=0;i<MAXFRAMES;i++)
1455 free(st->exponents[i]);
1459 setupmem(struct state *st)
1462 for (i=0;i<MAXFRAMES;i++) {
1463 if((st->exponents[i]=
1464 (double *)malloc(sizeof(double)*st->width*(st->height+1)))==NULL){
1465 fprintf(stderr,"Error malloc'ing exponent array.\n");
1472 setforcing(struct state *st)
1475 for (i=0;i<MAXINDEX;i++)
1476 st->forcing[i] = (random() > st->prob) ? 0 : 1;
1479 /****************************************************************************/
1482 do_defaults (struct state *st)
1486 memset (st->expind, 0, sizeof(st->expind));
1487 memset (st->resized, 0, sizeof(st->resized));
1496 # ifdef SIXTEEN_COLORS
1505 # else /* !SIXTEEN_COLORS */
1508 st->color_offset=96;
1512 # endif /* !SIXTEEN_COLORS */
1514 st->maxindex = MAXINDEX;
1515 st->funcmaxindex = FUNCMAXINDEX;
1525 st->numwheels=MAXWHEELS;
1529 st->stripe_interval=7;
1535 for (i = 0; i < countof(st->forcing); i++)
1536 st->forcing[i] = (i & 1) ? 1 : 0;
1540 do_preset (struct state *st, int builtin)
1545 st->min_a = 3.75; st->aflag++;
1546 st->min_b = 3.299999; st->bflag++;
1547 st->a_range = 0.05; st->wflag++;
1548 st->b_range = 0.05; st->hflag++;
1551 ff = "abaabbaaabbb";
1555 st->min_a = 3.8; st->aflag++;
1556 st->min_b = 3.2; st->bflag++;
1557 st->b_range = .05; st->hflag++;
1558 st->a_range = .05; st->wflag++;
1563 st->min_a = 3.4; st->aflag++;
1564 st->min_b = 3.04; st->bflag++;
1565 st->a_range = .5; st->wflag++;
1566 st->b_range = .5; st->hflag++;
1573 st->min_a = 3.5; st->aflag++;
1574 st->min_b = 3.0; st->bflag++;
1575 st->a_range = 0.2; st->wflag++;
1576 st->b_range = 0.2; st->hflag++;
1583 st->min_a = 3.55667; st->aflag++;
1584 st->min_b = 3.2; st->bflag++;
1585 st->b_range = .05; st->hflag++;
1586 st->a_range = .05; st->wflag++;
1591 st->min_a = 3.79; st->aflag++;
1592 st->min_b = 3.22; st->bflag++;
1593 st->b_range = .02999; st->hflag++;
1594 st->a_range = .02999; st->wflag++;
1599 st->min_a = 3.7999; st->aflag++;
1600 st->min_b = 3.299999; st->bflag++;
1601 st->a_range = 0.2; st->wflag++;
1602 st->b_range = 0.2; st->hflag++;
1605 ff = "abaabbaaabbb";
1609 st->min_a = 3.89; st->aflag++;
1610 st->min_b = 3.22; st->bflag++;
1611 st->b_range = .028; st->hflag++;
1612 st->a_range = .02999; st->wflag++;
1619 st->min_a = 3.2; st->aflag++;
1620 st->min_b = 3.7; st->bflag++;
1621 st->a_range = 0.05; st->wflag++;
1622 st->b_range = .005; st->hflag++;
1627 ff = "aaaaaabbbbbb";
1631 st->minlyap = st->maxexp = ABS(-0.85);
1632 st->minexp = -1.0 * st->minlyap;
1636 ff = "aaaaaabbbbbb";
1640 st->minlyap = st->maxexp = ABS(-0.85);
1641 st->minexp = -1.0 * st->minlyap;
1648 st->minlyap = st->maxexp = ABS(-0.85);
1649 st->minexp = -1.0 * st->minlyap;
1657 st->minlyap = st->maxexp = ABS(-0.85);
1658 st->minexp = -1.0 * st->minlyap;
1666 st->minlyap = st->maxexp = ABS(-0.85);
1667 st->minexp = -1.0 * st->minlyap;
1674 st->minlyap = st->maxexp = ABS(-0.85);
1675 st->minexp = -1.0 * st->minlyap;
1677 st->min_a = 3.91; st->aflag++;
1678 st->a_range = 0.0899999999; st->wflag++;
1679 st->min_b = 3.28; st->bflag++;
1680 st->b_range = 0.35; st->hflag++;
1684 ff = "aaaaaabbbbbb";
1687 st->minlyap = st->maxexp = ABS(-0.85);
1688 st->minexp = -1.0 * st->minlyap;
1694 st->minlyap = st->maxexp = ABS(-0.85);
1695 st->minexp = -1.0 * st->minlyap;
1702 st->minlyap = st->maxexp = ABS(-0.85);
1703 st->minexp = -1.0 * st->minlyap;
1710 st->minlyap = st->maxexp = ABS(-0.85);
1711 st->minexp = -1.0 * st->minlyap;
1716 ff = "aaaaaabbbbbb";
1719 st->minlyap = st->maxexp = ABS(-0.85);
1720 st->minexp = -1.0 * st->minlyap;
1727 st->minlyap = st->maxexp = ABS(-0.85);
1728 st->minexp = -1.0 * st->minlyap;
1736 st->minlyap = st->maxexp = ABS(-0.85);
1737 st->minexp = -1.0 * st->minlyap;
1745 st->minlyap = st->maxexp = ABS(-0.85);
1746 st->minexp = -1.0 * st->minlyap;
1757 st->maxindex = strlen(ff);
1758 if (st->maxindex > MAXINDEX)
1762 while (bindex < st->maxindex) {
1764 st->forcing[bindex++] = 0;
1765 else if (*ch == 'b')
1766 st->forcing[bindex++] = 1;
1776 xlyap_init (Display *d, Window window)
1778 struct state *st = (struct state *) calloc (1, sizeof(*st));
1779 XWindowAttributes xgwa;
1781 XGetWindowAttributes (d, window, &xgwa);
1783 st->width = xgwa.width;
1784 st->height = xgwa.height;
1785 st->visual = xgwa.visual;
1786 st->cmap = xgwa.colormap;
1791 if (get_boolean_resource(st->dpy, "randomize", "Boolean"))
1792 builtin = random() % NBUILTINS;
1794 char *s = get_string_resource(st->dpy, "builtin", "Integer");
1801 do_preset (st, builtin);
1803 st->screen = DefaultScreen(st->dpy);
1804 st->background = BlackPixel(st->dpy, st->screen);
1808 st->foreground = st->startcolor;
1810 st->foreground = WhitePixel(st->dpy, st->screen);
1813 * Create the window to display the Lyapunov exponents
1815 st->canvas = window;
1818 #ifdef BACKING_PIXMAP
1819 st->pixmap = XCreatePixmap(st->dpy, window, st->width, st->height,
1822 /* st->rubber_data.band_cursor = XCreateFontCursor(st->dpy, XC_hand2);*/
1823 /* CreateXorGC(st);*/
1826 st->delay = get_integer_resource(st->dpy, "delay", "Delay");
1827 st->linger = get_integer_resource(st->dpy, "linger", "Linger");
1828 if (st->linger < 1) st->linger = 1;
1834 static unsigned long
1835 xlyap_draw (Display *dpy, Window window, void *closure)
1837 struct state *st = (struct state *) closure;
1840 if (!st->run && st->reset_countdown) {
1841 st->reset_countdown--;
1842 if (st->reset_countdown)
1846 do_preset (st, (random() % NBUILTINS));
1856 for (i = 0; i < 1000; i++)
1857 if (complyap(st) == TRUE)
1860 st->reset_countdown = st->linger;
1867 xlyap_reshape (Display *dpy, Window window, void *closure,
1868 unsigned int w, unsigned int h)
1870 struct state *st = (struct state *) closure;
1875 xlyap_event (Display *dpy, Window window, void *closure, XEvent *event)
1877 struct state *st = (struct state *) closure;
1881 return Getkey(st, &event->xkey);
1885 StartRubberBand(st, &st->rubber_data, event);
1888 TrackRubberBand(st, &st->rubber_data, event);
1891 EndRubberBand(st, &st->rubber_data, event);
1901 xlyap_free (Display *dpy, Window window, void *closure)
1904 struct state *st = (struct state *) closure;
1908 #ifdef BACKING_PIXMAP
1909 XFreePixmap (st->dpy, st->pixmap);
1911 /* XFreeGC (st->dpy, st->RubberGC);*/
1912 for (i = 0; i < st->maxcolor; i++)
1913 XFreeGC (st->dpy, st->Data_GC[i]);
1919 XSCREENSAVER_MODULE ("XLyap", xlyap)