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 Institute
26 * for its creation. Additional information and ideas were gleaned from the
27 * discussion on alt.fractals involving Stephen Hall, Ed Kubaitis, Dave Platt
28 * and Baback Moghaddam. Assistance with colormaps and spinning color wheels
29 * and X was gleaned from Hiram Clawson. Rubber banding code was adapted from
30 * 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"
43 #include <X11/cursorfont.h>
44 #include <X11/Xutil.h>
46 char *progclass = "XLyap";
57 "*colorExponent: 1.0",
59 "*randomForce: ", /* 0.5 */
64 "*function: 10101010",
65 "*forcingFunction: abbabaab",
66 "*bRange: ", /* 2.0 */
68 "*mapIndex: ", /* 0 */
74 "*aRange: ", /* 2.0 */
78 XrmOptionDescRec options [] = {
79 { "-randomize", ".randomize", XrmoptionNoArg, "true" },
80 { "-builtin", ".builtin", XrmoptionSepArg, 0 },
81 { "-C", ".minColor", XrmoptionSepArg, 0 }, /* n */
82 { "-D", ".dwell", XrmoptionSepArg, 0 }, /* n */
83 { "-L", ".useLog", XrmoptionNoArg, "true" },
84 { "-M", ".colorExponent", XrmoptionSepArg, 0 }, /* r */
85 { "-O", ".colorOffset", XrmoptionSepArg, 0 }, /* n */
86 { "-R", ".randomForce", XrmoptionSepArg, 0 }, /* p */
87 { "-S", ".settle", XrmoptionSepArg, 0 }, /* n */
88 { "-a", ".minA", XrmoptionSepArg, 0 }, /* r */
89 { "-b", ".minB", XrmoptionSepArg, 0 }, /* n */
90 { "-c", ".wheels", XrmoptionSepArg, 0 }, /* n */
91 { "-F", ".function", XrmoptionSepArg, 0 }, /* 10101010 */
92 { "-f", ".forcingFunction", XrmoptionSepArg, 0 }, /* abbabaab */
93 { "-h", ".bRange", XrmoptionSepArg, 0 }, /* r */
94 { "-i", ".startX", XrmoptionSepArg, 0 }, /* r */
95 { "-m", ".mapIndex", XrmoptionSepArg, 0 }, /* n */
96 { "-o", ".outputFile", XrmoptionSepArg, 0 }, /* filename */
97 { "-p", ".beNegative", XrmoptionNoArg, "true" },
98 { "-r", ".rgbMax", XrmoptionSepArg, 0 }, /* n */
99 { "-s", ".spinLength", XrmoptionSepArg, 0 }, /* n */
100 { "-v", ".show", XrmoptionNoArg, "true" },
101 { "-w", ".aRange", XrmoptionSepArg, 0 }, /* r */
106 #define ABS(a) (((a)<0) ? (0-(a)) : (a) )
107 #define Min(x,y) ((x < y)?x:y)
108 #define Max(x,y) ((x > y)?x:y)
110 #ifdef SIXTEEN_COLORS
111 #define MAXPOINTS 128
118 static int maxcolor=16, startcolor=0, color_offset=0, mincolindex=1;
119 static int dwell=50, settle=25;
120 static int width=128, height=128, xposition=128, yposition=128;
122 #define MAXPOINTS 256
129 static int maxcolor=256, startcolor=17, color_offset=96, mincolindex=33;
130 static int dwell=100, settle=50;
131 static int width=256, height=256;
141 static Visual *visual;
143 static unsigned long foreground, background;
145 static Window canvas;
152 int start_x, start_y;
154 } rubber_band_data_t;
158 double p_min, p_max, q_min, q_max;
159 rubber_band_data_t rubber_band;
162 typedef struct points_t {
163 XPoint data[MAXCOLOR][MAXPOINTS];
164 int npoints[MAXCOLOR];
167 static points_t Points;
168 static image_data_t rubber_data;
175 static GC Data_GC[MAXCOLOR], RubberGC;
178 #define FUNCMAXINDEX 16
182 typedef double (*PFD)(double,double);
184 static double logistic(double,double), circle(double,double), leftlog(double,double), rightlog(double,double), doublelog(double,double);
185 static double dlogistic(double,double), dcircle(double,double), dleftlog(double,double), drightlog(double,double), ddoublelog(double,double);
186 static PFD map, deriv;
187 static PFD Maps[NUMMAPS] = { logistic, circle, leftlog, rightlog, doublelog };
188 static PFD Derivs[NUMMAPS] = { dlogistic, dcircle, dleftlog, drightlog, ddoublelog };
190 static int aflag=0, bflag=0, wflag=0, hflag=0, Rflag=0;
191 static double pmins[NUMMAPS] = { 2.0, 0.0, 0.0, 0.0, 0.0 };
192 static double pmaxs[NUMMAPS] = { 4.0, 1.0, 6.75, 6.75, 16.0 };
193 static double amins[NUMMAPS] = { 2.0, 0.0, 0.0, 0.0, 0.0 };
194 static double aranges[NUMMAPS] = { 2.0, 1.0, 6.75, 6.75, 16.0 };
195 static double bmins[NUMMAPS] = { 2.0, 0.0, 0.0, 0.0, 0.0 };
196 static double branges[NUMMAPS] = { 2.0, 1.0, 6.75, 6.75, 16.0 };
198 static int forcing[MAXINDEX] = { 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
199 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,
200 0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1 };
201 static int Forcing[FUNCMAXINDEX] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
203 static int maxindex = MAXINDEX;
204 static int funcmaxindex = FUNCMAXINDEX;
205 static double min_a=2.0, min_b=2.0, a_range=2.0, b_range=2.0, minlyap=1.0;
206 static double max_a=4.0, max_b=4.0;
207 static double start_x=0.65, lyapunov, a_inc, b_inc, a, b;
208 static int numcolors=16, numfreecols, displayplanes, lowrange;
210 static Pixmap pixmap;
211 static Colormap cmap;
212 static XColor Colors[MAXCOLOR];
213 static double *exponents[MAXFRAMES];
214 static double a_minimums[MAXFRAMES], b_minimums[MAXFRAMES];
215 static double a_maximums[MAXFRAMES], b_maximums[MAXFRAMES];
216 static double minexp, maxexp, prob=0.5;
217 static int expind[MAXFRAMES]={0}, resized[MAXFRAMES]={0};
218 static int numwheels=MAXWHEELS, force=0, Force=0, negative=1;
219 static int rgb_max=65000, nostart=1, stripe_interval=7;
220 static int save=1, show=0, useprod=1, spinlength=256, savefile=0;
221 static int maxframe=0, frame=0, dorecalc=0, mapindex=0, run=1;
222 static char *outname="lyap.out";
225 const char * const version = LYAP_VERSION;
227 static void resize(void);
228 static void redisplay(Window w, XExposeEvent *event);
229 static void Spin(Window w);
230 static void show_defaults(void);
231 static void StartRubberBand(Window w, image_data_t *data, XEvent *event);
232 static void TrackRubberBand(Window w, image_data_t *data, XEvent *event);
233 static void EndRubberBand(Window w, image_data_t *data, XEvent *event);
234 static void CreateXorGC(void);
235 static void InitBuffer(void);
236 static void BufferPoint(Display *display, Window window, int color,
238 static void FlushBuffer(void);
239 static void init_canvas(void);
240 static void init_data(void);
241 static void init_color(void);
242 static void parseargs(void);
243 static void Clear(void);
244 static void setupmem(void);
245 static void main_event(void);
246 static int complyap(void);
247 static void Getkey(XKeyEvent *event);
248 static int sendpoint(double expo);
249 static void save_to_file(void);
250 static void setforcing(void);
251 static void check_params(int mapnum, int parnum);
252 static void usage(void);
253 static void Destroy_frame(void);
254 static void freemem(void);
255 static void Redraw(void);
256 static void redraw(double *exparray, int index, int cont);
257 static void recalc(void);
258 static void SetupCorners(XPoint *corners, image_data_t *data);
259 static void set_new_params(Window w, image_data_t *data);
260 static void go_down(void);
261 static void go_back(void);
262 static void go_init(void);
263 static void jumpwin(void);
264 static void print_help(void);
265 static void print_values(void);
269 screenhack (Display *d, Window window)
271 XWindowAttributes xgwa;
274 XGetWindowAttributes (dpy, window, &xgwa);
276 height = xgwa.height;
277 visual = xgwa.visual;
278 cmap = xgwa.colormap;
282 if (get_boolean_resource("randomize", "Boolean"))
283 builtin = random() % 22;
285 char *s = get_string_resource("builtin", "Integer");
296 min_a = 3.75; aflag++;
297 min_b = 3.299999; bflag++;
298 a_range = 0.05; wflag++;
299 b_range = 0.05; hflag++;
306 min_a = 3.8; aflag++;
307 min_b = 3.2; bflag++;
308 b_range = .05; hflag++;
309 a_range = .05; wflag++;
314 min_a = 3.4; aflag++;
315 min_b = 3.04; bflag++;
316 a_range = .5; wflag++;
317 b_range = .5; hflag++;
324 min_a = 3.5; aflag++;
325 min_b = 3.0; bflag++;
326 a_range = 0.2; wflag++;
327 b_range = 0.2; hflag++;
334 min_a = 3.55667; aflag++;
335 min_b = 3.2; bflag++;
336 b_range = .05; hflag++;
337 a_range = .05; wflag++;
342 min_a = 3.79; aflag++;
343 min_b = 3.22; bflag++;
344 b_range = .02999; hflag++;
345 a_range = .02999; wflag++;
350 min_a = 3.7999; aflag++;
351 min_b = 3.299999; bflag++;
352 a_range = 0.2; wflag++;
353 b_range = 0.2; hflag++;
360 min_a = 3.89; aflag++;
361 min_b = 3.22; bflag++;
362 b_range = .028; hflag++;
363 a_range = .02999; wflag++;
370 min_a = 3.2; aflag++;
371 min_b = 3.7; bflag++;
372 a_range = 0.05; wflag++;
373 b_range = .005; hflag++;
382 minlyap = maxexp = ABS(-0.85);
383 minexp = -1.0 * minlyap;
391 minlyap = maxexp = ABS(-0.85);
392 minexp = -1.0 * minlyap;
399 minlyap = maxexp = ABS(-0.85);
400 minexp = -1.0 * minlyap;
408 minlyap = maxexp = ABS(-0.85);
409 minexp = -1.0 * minlyap;
417 minlyap = maxexp = ABS(-0.85);
418 minexp = -1.0 * minlyap;
425 minlyap = maxexp = ABS(-0.85);
426 minexp = -1.0 * minlyap;
428 min_a = 3.91; aflag++;
429 a_range = 0.0899999999; wflag++;
430 min_b = 3.28; bflag++;
431 b_range = 0.35; hflag++;
438 minlyap = maxexp = ABS(-0.85);
439 minexp = -1.0 * minlyap;
445 minlyap = maxexp = ABS(-0.85);
446 minexp = -1.0 * minlyap;
453 minlyap = maxexp = ABS(-0.85);
454 minexp = -1.0 * minlyap;
461 minlyap = maxexp = ABS(-0.85);
462 minexp = -1.0 * minlyap;
470 minlyap = maxexp = ABS(-0.85);
471 minexp = -1.0 * minlyap;
478 minlyap = maxexp = ABS(-0.85);
479 minexp = -1.0 * minlyap;
487 minlyap = maxexp = ABS(-0.85);
488 minexp = -1.0 * minlyap;
496 minlyap = maxexp = ABS(-0.85);
497 minexp = -1.0 * minlyap;
504 maxindex = strlen(ff);
505 if (maxindex > MAXINDEX)
509 while (bindex < maxindex) {
511 forcing[bindex++] = 0;
513 forcing[bindex++] = 1;
521 screen = DefaultScreen(dpy);
522 background = BlackPixel(dpy, screen);
525 if (displayplanes > 1)
526 foreground = startcolor;
528 foreground = WhitePixel(dpy, screen);
531 * Create the window to display the Lyapunov exponents
536 if (displayplanes > 1) {
539 XQueryColors(dpy, DefaultColormap(dpy, DefaultScreen(dpy)),
542 pixmap = XCreatePixmap(dpy, window, width, height, xgwa.depth);
543 rubber_data.band_cursor = XCreateFontCursor(dpy, XC_hand2);
556 if (complyap() == TRUE)
558 n = XEventsQueued(dpy, QueuedAfterFlush);
560 XNextEvent(dpy, &event);
567 redisplay(canvas, &event.xexpose);
569 case ConfigureNotify:
573 StartRubberBand(canvas, &rubber_data, &event);
576 TrackRubberBand(canvas, &rubber_data, &event);
579 EndRubberBand(canvas, &rubber_data, &event);
582 screenhack_handle_event (dpy, &event);
588 /* complyap() is the guts of the program. This is where the Lyapunov exponent
589 * is calculated. For each iteration (past some large number of iterations)
590 * calculate the logarithm of the absolute value of the derivative at that
591 * point. Then average them over some large number of iterations. Some small
592 * speed up is achieved by utilizing the fact that log(a*b) = log(a) + log(b).
598 double total, prod, x, dx, r;
604 if (sendpoint(lyapunov) == TRUE)
623 r = (forcing[bindex]) ? b : a;
626 map = Maps[Forcing[findex]];
628 for (i=0;i<settle;i++) { /* Here's where we let the thing */
629 x = (*map)(x, r); /* "settle down". There is usually */
630 if (++bindex >= maxindex) { /* some initial "noise" in the */
631 bindex = 0; /* iterations. How can we optimize */
632 if (Rflag) /* the value of settle ??? */
635 r = (forcing[bindex]) ? b : a;
637 if (++findex >= funcmaxindex)
639 map = Maps[Forcing[findex]];
643 deriv = Derivs[Forcing[findex]];
645 if (useprod) { /* using log(a*b) */
646 for (i=0;i<dwell;i++) {
648 dx = (*deriv)(x, r); /* ABS is a macro, so don't be fancy */
650 if (dx == 0.0) /* log(0) is nasty so break out. */
656 /* we need to prevent overflow and underflow */
657 if ((prod > 1.0e12) || (prod < 1.0e-12)) {
661 if (++bindex >= maxindex) {
666 r = (forcing[bindex]) ? b : a;
668 if (++findex >= funcmaxindex)
670 map = Maps[Forcing[findex]];
671 deriv = Derivs[Forcing[findex]];
675 lyapunov = (total * M_LOG2E) / (double)i;
677 else { /* use log(a) + log(b) */
678 for (i=0;i<dwell;i++) {
680 dx = (*deriv)(x, r); /* ABS is a macro, so don't be fancy */
682 if (x == 0.0) /* log(0) check */
688 if (++bindex >= maxindex) {
693 r = (forcing[bindex]) ? b : a;
695 if (++findex >= funcmaxindex)
697 map = Maps[Forcing[findex]];
698 deriv = Derivs[Forcing[findex]];
701 lyapunov = (total * M_LOG2E) / (double)i;
704 if (sendpoint(lyapunov) == TRUE)
715 logistic(double x, double r) /* the familiar logistic map */
717 return(r * x * (1.0 - x));
721 dlogistic(double x, double r) /* the derivative of logistic map */
723 return(r - (2.0 * r * x));
727 circle(double x, double r) /* sin() hump or sorta like the circle map */
729 return(r * sin(M_PI * x));
733 dcircle(double x, double r) /* derivative of the "sin() hump" */
735 return(r * M_PI * cos(M_PI * x));
739 leftlog(double x, double r) /* left skewed logistic */
744 return(r * x * d * d);
748 dleftlog(double x, double r) /* derivative of the left skewed logistic */
750 return(r * (1.0 - (4.0 * x) + (3.0 * x * x)));
754 rightlog(double x, double r) /* right skewed logistic */
756 return(r * x * x * (1.0 - x));
760 drightlog(double x, double r) /* derivative of the right skewed logistic */
762 return(r * ((2.0 * x) - (3.0 * x * x)));
766 doublelog(double x, double r) /* double logistic */
771 return(r * x * x * d * d);
775 ddoublelog(double x, double r) /* derivative of the double logistic */
780 return(r * ((2.0 * x) - (6.0 * d) + (4.0 * x * d)));
786 numcolors = XDisplayCells(dpy, XDefaultScreen(dpy));
787 displayplanes = DisplayPlanes(dpy, XDefaultScreen(dpy));
788 if (numcolors > maxcolor)
789 numcolors = maxcolor;
790 numfreecols = numcolors - mincolindex;
791 lowrange = mincolindex - startcolor;
792 a_inc = a_range / (double)width;
793 b_inc = b_range / (double)height;
796 a = rubber_data.p_min = min_a;
797 b = rubber_data.q_min = min_b;
798 rubber_data.p_max = max_a;
799 rubber_data.q_max = max_b;
811 * create default, writable, graphics contexts for the canvas.
813 for (i=0; i<maxcolor; i++) {
814 Data_GC[i] = XCreateGC(dpy, canvas,
815 (unsigned long) NULL, (XGCValues *) NULL);
816 /* set the background to black */
817 XSetBackground(dpy,Data_GC[i],BlackPixel(dpy,XDefaultScreen(dpy)));
818 /* set the foreground of the ith context to i */
819 XSetForeground(dpy, Data_GC[i], i);
821 if (displayplanes == 1) {
822 XSetForeground(dpy,Data_GC[0],BlackPixel(dpy,XDefaultScreen(dpy)));
823 XSetForeground(dpy,Data_GC[1],WhitePixel(dpy,XDefaultScreen(dpy)));
829 hls2rgb(int hue_light_sat[3],
830 int rgb[3]) /* Each in range [0..65535] */
832 unsigned short r, g, b;
833 hsv_to_rgb((int) (hue_light_sat[0] / 10), /* 0-3600 -> 0-360 */
834 (int) ((hue_light_sat[2]/1000.0) * 64435), /* 0-1000 -> 0-65535 */
835 (int) ((hue_light_sat[1]/1000.0) * 64435), /* 0-1000 -> 0-65535 */
851 int ncolors = maxcolor;
852 Bool writable = False;
853 make_smooth_colormap(dpy, visual, cmap,
854 colors, &ncolors, True, &writable, True);
856 for (i = 0; i < maxcolor; i++)
857 XSetForeground(dpy, Data_GC[i],
858 colors[((int) ((i / ((float)maxcolor)) * ncolors))].pixel);
861 static int i, j, colgap, leg, step;
862 static Visual *visual;
866 def_cmap = DefaultColormap(dpy, DefaultScreen(dpy));
867 for (i=0; i<numcolors; i++) {
869 Colors[i].flags = DoRed|DoGreen|DoBlue;
872 /* Try to write into a new color map */
873 visual = DefaultVisual(dpy, DefaultScreen(dpy));
874 cmap = XCreateColormap(dpy, canvas, visual, AllocAll);
875 XQueryColors(dpy, def_cmap, Colors, numcolors);
877 colgap = rgb_max / mincolindex;
880 hls[0] = 50; /* Hue in low range */
881 hls[2] = 1000; /* Fully saturated */
882 for (i=startcolor; i<lowrange + startcolor; i++) {
883 hls[1] = 1000L * (i-startcolor) / lowrange;
885 Colors[i].red = rgb[0];
886 Colors[i].green = rgb[1];
887 Colors[i].blue = rgb[2];
889 colgap = rgb_max / numcolors;
891 XQueryColors(dpy, def_cmap, Colors, numcolors);
892 else if (numwheels == 1) {
893 colgap = 2*rgb_max/(numcolors - color_offset);
894 for (i=mincolindex; i<(numcolors/2); i++) {
896 Colors[i].green=((i+color_offset)*colgap);
897 Colors[i].red=((i+color_offset)*colgap);
899 for (i=(numcolors/2); i<(numcolors); i++) {
901 Colors[i].green=(((numcolors-i)+color_offset)*colgap);
902 Colors[i].red=(((numcolors-i)+color_offset)*colgap);
905 else if (numwheels == 2) {
906 hls[0] = 800; /* Hue in mid range */
907 hls[2] = 1000; /* Fully saturated */
908 for (i=startcolor; i<lowrange + startcolor; i++) {
909 hls[1] = 1000L * (i-startcolor) / lowrange;
911 Colors[i].red = rgb[0];
912 Colors[i].green = rgb[1];
913 Colors[i].blue = rgb[2];
915 for (i=mincolindex; i<(numcolors/2); i++) {
916 Colors[i].blue = rgb_max;
918 Colors[i].red=(i*2*rgb_max/numcolors);
920 for (i=(numcolors/2); i<numcolors; i++) {
921 Colors[i].blue = rgb_max;
923 Colors[i].red=((numcolors - i)*2*rgb_max/numcolors);
926 else if (numwheels == 3) {
927 hls[0] = 800; /* Hue in mid range */
928 hls[2] = 1000; /* Fully saturated */
929 for (i=startcolor; i<lowrange + startcolor; i++) {
930 hls[1] = 1000L * (i-startcolor) / lowrange;
932 Colors[i].red = rgb[0];
933 Colors[i].green = rgb[1];
934 Colors[i].blue = rgb[2];
936 colgap = 4*rgb_max/numcolors;
937 for (i=mincolindex; i<(numcolors/4); i++) {
938 Colors[i].blue = rgb_max;
940 Colors[i].red=(i*colgap);
942 for (i=(numcolors/4); i<(numcolors/2); i++) {
943 Colors[i].red = rgb_max;
945 Colors[i].blue=((numcolors/2) - i) * colgap;
947 for (i=(numcolors/2); i<(0.75*numcolors); i++) {
948 Colors[i].red = rgb_max;
949 Colors[i].blue=(i * colgap);
952 for (i=(0.75*numcolors); i<numcolors; i++) {
953 Colors[i].blue = rgb_max;
955 Colors[i].red=(numcolors-i)*colgap;
958 else if (numwheels == 4) {
959 hls[0] = 800; /* Hue in mid range */
960 hls[2] = 1000; /* Fully saturated */
961 for (i=startcolor; i<lowrange + startcolor; i++) {
962 hls[1] = 1000L * (i-startcolor) / lowrange;
964 Colors[i].red = rgb[0];
965 Colors[i].green = rgb[1];
966 Colors[i].blue = rgb[2];
968 colgap = numwheels * rgb_max / numcolors;
969 for (i=mincolindex; i<(numcolors/numwheels); i++) {
970 Colors[i].blue = rgb_max;
972 Colors[i].red=(i*colgap);
974 for (i=(numcolors/numwheels); i<(2*numcolors/numwheels); i++) {
975 Colors[i].red = rgb_max;
977 Colors[i].blue=((2*numcolors/numwheels) - i) * colgap;
979 for (i=(2*numcolors/numwheels); i<numcolors; i++) {
980 Colors[i].red = rgb_max;
981 Colors[i].green=(i - (2*numcolors/numwheels)) * colgap;
985 else if (numwheels == 5) {
986 hls[1] = 700; /* Lightness in midrange */
987 hls[2] = 1000; /* Fully saturated */
988 for (i=mincolindex; i<numcolors; i++) {
989 hls[0] = 3600L * i / numcolors;
991 Colors[i].red = rgb[0];
992 Colors[i].green = rgb[1];
993 Colors[i].blue = rgb[2];
995 for (i=mincolindex; i<numcolors; i+=stripe_interval) {
996 hls[0] = 3600L * i / numcolors;
998 Colors[i].red = rgb[0] / 2;
999 Colors[i].green = rgb[1] / 2;
1000 Colors[i].blue = rgb[2] / 2;
1003 else if (numwheels == 6) {
1004 hls[0] = 800; /* Hue in mid range */
1005 hls[2] = 1000; /* Fully saturated */
1006 for (i=startcolor; i<lowrange + startcolor; i++) {
1007 hls[1] = 1000L * (i-startcolor) / lowrange;
1009 Colors[i].red = rgb[0];
1010 Colors[i].green = rgb[1];
1011 Colors[i].blue = rgb[2];
1013 step = numfreecols / 3;
1014 leg = step+mincolindex;
1015 for (i = mincolindex; i < leg; ++i)
1017 Colors[i].pixel = i;
1018 Colors[i].red = fabs(65535 - (double)i / step * 65535.0);
1019 Colors[i].blue = (double)i / step * 65535.0;
1020 Colors[i].green = 0;
1021 Colors[i].flags = DoRed | DoGreen | DoBlue;
1023 for (j = 0, i = leg, leg += step; i < leg; ++i, ++j)
1025 Colors[i].pixel = i;
1026 Colors[i].red = (double)j / step * 65535.0;
1027 Colors[i].blue = 65535;
1028 Colors[i].green = Colors[i].red;
1029 Colors[i].flags = DoRed | DoGreen | DoBlue;
1031 for (j = 0, i = leg, leg += step; i < leg; ++i, ++j)
1033 Colors[i].pixel = i;
1034 Colors[i].red = 65535;
1035 Colors[i].blue = fabs(65535 - (double)j / step * 65535.0);
1036 Colors[i].green = Colors[i].blue;
1037 Colors[i].flags = DoRed | DoGreen | DoBlue;
1040 else if (numwheels == MAXWHEELS) { /* rainbow palette */
1041 hls[1] = 500; /* Lightness in midrange */
1042 hls[2] = 1000; /* Fully saturated */
1043 for (i=mincolindex; i<numcolors; i++) {
1044 hls[0] = 3600L * i / numcolors;
1046 Colors[i].red = rgb[0];
1047 Colors[i].green = rgb[1];
1048 Colors[i].blue = rgb[2];
1051 XStoreColors(dpy, cmap, Colors, numcolors);
1053 XSetWindowColormap(dpy, canvas, cmap);
1061 int bindex=0, findex;
1066 maxexp=minlyap; minexp= -1.0 * minlyap;
1068 mincolindex = get_integer_resource("minColor", "Integer");
1069 dwell = get_integer_resource("dwell", "Integer");
1072 char *optarg = get_string_resource("function", "String");
1073 funcmaxindex = strlen(optarg);
1074 if (funcmaxindex > FUNCMAXINDEX)
1078 for (findex=0;findex<funcmaxindex;findex++) {
1079 Forcing[findex] = (int)(*ch++ - '0');;
1080 if (Forcing[findex] >= NUMMAPS)
1085 if (get_boolean_resource("useLog", "Boolean"))
1088 minlyap=ABS(get_float_resource("colorExponent", "Float"));
1090 minexp= -1.0 * minlyap;
1092 color_offset = get_integer_resource("colorOffset", "Integer");
1094 maxcolor=ABS(get_integer_resource("maxColor", "Integer"));
1095 if ((maxcolor - startcolor) <= 0)
1097 if ((maxcolor - mincolindex) <= 0) {
1102 s = get_string_resource("randomForce", "Float");
1104 prob=atof(s); Rflag++; setforcing();
1107 settle = get_integer_resource("settle", "Integer");
1109 s = get_string_resource("minA", "Float");
1115 s = get_string_resource("minB", "Float");
1117 min_b=atof(s); bflag++;
1120 numwheels = get_integer_resource("wheels", "Integer");
1122 s = get_string_resource("forcingFunction", "String");
1124 maxindex = strlen(s);
1125 if (maxindex > MAXINDEX)
1129 while (bindex < maxindex) {
1131 forcing[bindex++] = 0;
1132 else if (*ch == 'b')
1133 forcing[bindex++] = 1;
1140 s = get_string_resource("bRange", "Float");
1146 start_x = get_float_resource("startX", "Float");
1148 s = get_string_resource("mapIndex", "Integer");
1151 if ((mapindex >= NUMMAPS) || (mapindex < 0))
1153 map = Maps[mapindex];
1154 deriv = Derivs[mapindex];
1156 min_a = amins[mapindex];
1158 a_range = aranges[mapindex];
1160 min_b = bmins[mapindex];
1162 b_range = branges[mapindex];
1164 for (i=0;i<FUNCMAXINDEX;i++)
1165 Forcing[i] = mapindex;
1168 outname = get_string_resource("outputFile", "Integer");
1170 if (get_boolean_resource("beNegative", "Boolean"))
1173 rgb_max = get_integer_resource("rgbMax", "Integer");
1174 spinlength = get_integer_resource("spinLength", "Integer");
1175 show = get_boolean_resource("show", "Boolean");
1177 s = get_string_resource("aRange", "Float");
1179 a_range = atof(s); wflag++;
1182 max_a = min_a + a_range;
1183 max_b = min_b + b_range;
1185 a_minimums[0] = min_a; b_minimums[0] = min_b;
1186 a_maximums[0] = max_a; b_maximums[0] = max_b;
1189 if (maxindex == funcmaxindex)
1190 for (findex=0;findex<funcmaxindex;findex++)
1191 check_params(Forcing[findex],forcing[findex]);
1193 fprintf(stderr, "Warning! Unable to check parameters\n");
1195 check_params(mapindex,2);
1199 check_params(int mapnum, int parnum)
1203 if ((max_a > pmaxs[mapnum]) || (min_a < pmins[mapnum])) {
1204 fprintf(stderr, "Warning! Parameter 'a' out of range.\n");
1205 fprintf(stderr, "You have requested a range of (%f,%f).\n",
1207 fprintf(stderr, "Valid range is (%f,%f).\n",
1208 pmins[mapnum],pmaxs[mapnum]);
1212 if ((max_b > pmaxs[mapnum]) || (min_b < pmins[mapnum])) {
1213 fprintf(stderr, "Warning! Parameter 'b' out of range.\n");
1214 fprintf(stderr, "You have requested a range of (%f,%f).\n",
1216 fprintf(stderr, "Valid range is (%f,%f).\n",
1217 pmins[mapnum],pmaxs[mapnum]);
1225 fprintf(stderr,"lyap [-BLs][-W#][-H#][-a#][-b#][-w#][-h#][-x xstart]\n");
1226 fprintf(stderr,"\t[-M#][-S#][-D#][-f string][-r#][-O#][-C#][-c#][-m#]\n");
1228 fprintf(stderr,"\t[-F string]\n");
1230 fprintf(stderr,"\tWhere: -C# specifies the minimum color index\n");
1231 fprintf(stderr,"\t -r# specifies the maxzimum rgb value\n");
1232 fprintf(stderr,"\t -u displays this message\n");
1233 fprintf(stderr,"\t -a# specifies the minimum horizontal parameter\n");
1234 fprintf(stderr,"\t -b# specifies the minimum vertical parameter\n");
1235 fprintf(stderr,"\t -w# specifies the horizontal parameter range\n");
1236 fprintf(stderr,"\t -h# specifies the vertical parameter range\n");
1237 fprintf(stderr,"\t -D# specifies the dwell\n");
1238 fprintf(stderr,"\t -S# specifies the settle\n");
1239 fprintf(stderr,"\t -H# specifies the initial window height\n");
1240 fprintf(stderr,"\t -W# specifies the initial window width\n");
1241 fprintf(stderr,"\t -O# specifies the color offset\n");
1242 fprintf(stderr,"\t -c# specifies the desired color wheel\n");
1243 fprintf(stderr,"\t -m# specifies the desired map (0-4)\n");
1244 fprintf(stderr,"\t -f aabbb specifies a forcing function of 00111\n");
1246 fprintf(stderr,"\t -F 00111 specifies the function forcing function\n");
1248 fprintf(stderr,"\t -L indicates use log(x)+log(y) rather than log(xy)\n");
1249 fprintf(stderr,"\tDuring display :\n");
1250 fprintf(stderr,"\t Use the mouse to zoom in on an area\n");
1251 fprintf(stderr,"\t e or E recalculates color indices\n");
1252 fprintf(stderr,"\t f or F saves exponents to a file\n");
1253 fprintf(stderr,"\t KJmn increase/decrease minimum negative exponent\n");
1254 fprintf(stderr,"\t r or R redraws\n");
1255 fprintf(stderr,"\t s or S spins the colorwheel\n");
1256 fprintf(stderr,"\t w or W changes the color wheel\n");
1257 fprintf(stderr,"\t x or X clears the window\n");
1258 fprintf(stderr,"\t q or Q exits\n");
1266 for (i=0;i<=maxframe;i++)
1267 redraw(exponents[i], expind[i], 1);
1276 if (displayplanes > 1) {
1277 for (j=0;j<spinlength;j++) {
1278 tmpxcolor = Colors[mincolindex].pixel;
1279 for (i=mincolindex;i<numcolors-1;i++)
1280 Colors[i].pixel = Colors[i+1].pixel;
1281 Colors[numcolors-1].pixel = tmpxcolor;
1282 XStoreColors(dpy, cmap, Colors, numcolors);
1284 for (j=0;j<spinlength;j++) {
1285 tmpxcolor = Colors[numcolors-1].pixel;
1286 for (i=numcolors-1;i>mincolindex;i--)
1287 Colors[i].pixel = Colors[i-1].pixel;
1288 Colors[mincolindex].pixel = tmpxcolor;
1289 XStoreColors(dpy, cmap, Colors, numcolors);
1295 Getkey(XKeyEvent *event)
1299 if (XLookupString(event, (char *)&key, sizeof(key), (KeySym *)0,
1300 (XComposeStatus *) 0) > 0)
1302 case '<': dwell /= 2; if (dwell < 1) dwell = 1; break;
1303 case '>': dwell *= 2; break;
1304 case '[': settle /= 2; if (settle < 1) settle = 1; break;
1305 case ']': settle *= 2; break;
1306 case 'd': go_down(); break;
1307 case 'D': FlushBuffer(); break;
1309 case 'E': FlushBuffer();
1310 dorecalc = (!dorecalc);
1314 maxexp = minlyap; minexp = -1.0 * minlyap;
1316 redraw(exponents[frame], expind[frame], 1);
1319 case 'F': save_to_file(); break;
1320 case 'i': if (stripe_interval > 0) {
1322 if (displayplanes > 1) {
1327 case 'I': stripe_interval++;
1328 if (displayplanes > 1) {
1332 case 'K': if (minlyap > 0.05)
1335 case 'J': minlyap += 0.05;
1337 case 'm': mapindex++;
1338 if (mapindex >= NUMMAPS)
1340 map = Maps[mapindex];
1341 deriv = Derivs[mapindex];
1343 min_a = amins[mapindex];
1345 a_range = aranges[mapindex];
1347 min_b = bmins[mapindex];
1349 b_range = branges[mapindex];
1351 for (i=0;i<FUNCMAXINDEX;i++)
1352 Forcing[i] = mapindex;
1353 max_a = min_a + a_range;
1354 max_b = min_b + b_range;
1355 a_minimums[0] = min_a; b_minimums[0] = min_b;
1356 a_maximums[0] = max_a; b_maximums[0] = max_b;
1357 a_inc = a_range / (double)width;
1358 b_inc = b_range / (double)height;
1361 a = rubber_data.p_min = min_a;
1362 b = rubber_data.q_min = min_b;
1363 rubber_data.p_max = max_a;
1364 rubber_data.q_max = max_b;
1367 case 'M': if (minlyap > 0.005)
1370 case 'N': minlyap += 0.005;
1373 case 'P': negative = (!negative);
1374 FlushBuffer(); redraw(exponents[frame], expind[frame], 1);
1376 case 'r': FlushBuffer(); redraw(exponents[frame], expind[frame], 1);
1378 case 'R': FlushBuffer(); Redraw(); break;
1380 spinlength=spinlength/2;
1381 case 'S': if (displayplanes > 1)
1383 spinlength=spinlength*2; break;
1384 case 'u': go_back(); break;
1385 case 'U': go_init(); break;
1387 case 'V': print_values(); break;
1388 case 'W': if (numwheels < MAXWHEELS)
1392 if (displayplanes > 1) {
1396 case 'w': if (numwheels > 0)
1399 numwheels = MAXWHEELS;
1400 if (displayplanes > 1) {
1404 case 'x': Clear(); break;
1405 case 'X': Destroy_frame(); break;
1406 case 'z': Cycle_frames(); redraw(exponents[frame], expind[frame], 1);
1408 case 'Z': while (!XPending(dpy)) Cycle_frames();
1409 redraw(exponents[frame], expind[frame], 1); break;
1411 case 'Q': exit(0); break;
1414 case 'H': print_help(); break;
1419 /* Here's where we index into a color map. After the Lyapunov exponent is
1420 * calculated, it is used to determine what color to use for that point.
1421 * I suppose there are a lot of ways to do this. I used the following :
1422 * if it's non-negative then there's a reserved area at the lower range
1423 * of the color map that i index into. The ratio of some "minimum exponent
1424 * value" and the calculated value is used as a ratio of how high to index
1425 * into this reserved range. Usually these colors are dark red (see init_color).
1426 * If the exponent is negative, the same ratio (expo/minlyap) is used to index
1427 * into the remaining portion of the colormap (which is usually some light
1428 * shades of color or a rainbow wheel). The coloring scheme can actually make
1429 * a great deal of difference in the quality of the picture. Different colormaps
1430 * bring out different details of the dynamics while different indexing
1431 * algorithms also greatly effect what details are seen. Play around with this.
1434 sendpoint(double expo)
1437 static double tmpexpo;
1440 /* The relationship minexp <= expo <= maxexp should always be true. This test
1441 enforces that. But maybe not enforcing it makes better pictures. */
1444 else if (expo > maxexp)
1449 tmpexpo = (negative) ? expo : -1.0 * expo;
1451 if (displayplanes >1) {
1452 index = (int)(tmpexpo*lowrange/maxexp);
1453 index = (index % lowrange) + startcolor;
1459 if (displayplanes >1) {
1460 index = (int)(tmpexpo*numfreecols/minexp);
1461 index = (index % numfreecols) + mincolindex;
1466 BufferPoint(dpy, canvas, index, point.x, point.y);
1468 exponents[frame][expind[frame]++] = expo;
1469 if (point.x >= width) {
1476 if (point.y >= height)
1485 redisplay (Window w, XExposeEvent *event)
1488 * Extract the exposed area from the event and copy
1489 * from the saved pixmap to the window.
1491 XCopyArea(dpy, pixmap, canvas, Data_GC[0],
1492 event->x, event->y, event->width, event->height,
1493 event->x, event->y);
1501 unsigned int bw, d, new_w, new_h;
1503 XGetGeometry(dpy,canvas,&r,&x,&y,&new_w,&new_h,&bw,&d);
1504 if ((new_w == width) && (new_h == height))
1506 width = new_w; height = new_h;
1507 XClearWindow(dpy, canvas);
1509 XFreePixmap(dpy, pixmap);
1510 pixmap = XCreatePixmap(dpy, canvas, width, height, d);
1511 a_inc = a_range / (double)width;
1512 b_inc = b_range / (double)height;
1516 a = rubber_data.p_min = min_a;
1517 b = rubber_data.q_min = min_b;
1518 rubber_data.p_max = max_a;
1519 rubber_data.q_max = max_b;
1522 for (n=0;n<MAXFRAMES;n++)
1523 if ((n <= maxframe) && (n != frame))
1531 redraw(double *exparray, int index, int cont)
1534 static int x_sav, y_sav;
1543 for (i=0;i<index;i++)
1544 sendpoint(exparray[i]);
1552 a = point.x * a_inc + min_a;
1553 b = point.y * b_inc + min_b;
1571 /* Store color pics in PPM format and monochrome in PGM */
1581 unsigned char green;
1584 struct Colormap *colormap=NULL;
1589 (struct Colormap *)malloc(sizeof(struct Colormap)*maxcolor))
1591 fprintf(stderr,"Error malloc'ing colormap array\n");
1594 outfile = fopen(outname,"w");
1600 ximage=XGetImage(dpy, pixmap, 0, 0, width, height, AllPlanes, XYPixmap);
1602 if (displayplanes > 1) {
1603 for (i=0;i<maxcolor;i++) {
1604 colormap[i].red=(unsigned char)(Colors[i].red >> 8);
1605 colormap[i].green=(unsigned char)(Colors[i].green >> 8);
1606 colormap[i].blue =(unsigned char)(Colors[i].blue >> 8);
1608 fprintf(outfile,"P%d %d %d\n",6,width,height);
1611 fprintf(outfile,"P%d %d %d\n",5,width,height);
1612 fprintf(outfile,"# settle=%d dwell=%d start_x=%f\n",settle,dwell,
1614 fprintf(outfile,"# min_a=%f a_rng=%f max_a=%f\n",min_a,a_range,max_a);
1615 fprintf(outfile,"# min_b=%f b_rng=%f max_b=%f\n",min_b,b_range,max_b);
1617 fprintf(outfile,"# pseudo-random forcing\n");
1619 fprintf(outfile,"# periodic forcing=");
1620 for (i=0;i<maxindex;i++) {
1621 fprintf(outfile,"%d",forcing[i]);
1623 fprintf(outfile,"\n");
1626 fprintf(outfile,"# periodic forcing=01\n");
1628 fprintf(outfile,"# function forcing=");
1629 for (i=0;i<funcmaxindex;i++) {
1630 fprintf(outfile,"%d",Forcing[i]);
1632 fprintf(outfile,"\n");
1634 fprintf(outfile,"%d\n",numcolors-1);
1636 for (j=0;j<height;j++)
1637 for (i=0;i<width;i++) {
1638 c = (unsigned char)XGetPixel(ximage,i,j);
1639 if (displayplanes > 1)
1640 fwrite((char *)&colormap[c],sizeof colormap[0],1,outfile);
1642 fwrite((char *)&c,sizeof c,1,outfile);
1652 minexp = maxexp = 0.0;
1654 for (i=0;i<expind[frame];i++) {
1655 if (exponents[frame][i] < minexp)
1656 minexp = exponents[frame][i];
1657 if (exponents[frame][i] > maxexp)
1658 maxexp = exponents[frame][i];
1665 XClearWindow(dpy, canvas);
1666 XCopyArea(dpy, canvas, pixmap, Data_GC[0],
1667 0, 0, width, height, 0, 0);
1675 printf("Width=%d Height=%d numcolors=%d settle=%d dwell=%d\n",
1676 width,height,numcolors,settle,dwell);
1677 printf("min_a=%f a_range=%f max_a=%f\n", min_a,a_range,max_a);
1678 printf("min_b=%f b_range=%f max_b=%f\n", min_b,b_range,max_b);
1679 printf("minlyap=%f minexp=%f maxexp=%f\n", minlyap,minexp,maxexp);
1688 values.foreground = foreground;
1689 values.line_style = LineSolid;
1690 values.function = GXxor;
1691 RubberGC = XCreateGC(dpy, canvas,
1692 GCForeground | GCBackground | GCFunction | GCLineStyle, &values);
1696 StartRubberBand(Window w, image_data_t *data, XEvent *event)
1701 data->rubber_band.last_x = data->rubber_band.start_x = event->xbutton.x;
1702 data->rubber_band.last_y = data->rubber_band.start_y = event->xbutton.y;
1703 SetupCorners(corners, data);
1704 XDrawLines(dpy, canvas, RubberGC,
1705 corners, sizeof(corners) / sizeof(corners[0]), CoordModeOrigin);
1709 SetupCorners(XPoint *corners, image_data_t *data)
1711 corners[0].x = data->rubber_band.start_x;
1712 corners[0].y = data->rubber_band.start_y;
1713 corners[1].x = data->rubber_band.start_x;
1714 corners[1].y = data->rubber_band.last_y;
1715 corners[2].x = data->rubber_band.last_x;
1716 corners[2].y = data->rubber_band.last_y;
1717 corners[3].x = data->rubber_band.last_x;
1718 corners[3].y = data->rubber_band.start_y;
1719 corners[4] = corners[0];
1723 TrackRubberBand(Window w, image_data_t *data, XEvent *event)
1730 SetupCorners(corners, data);
1731 XDrawLines(dpy, canvas, RubberGC,
1732 corners, sizeof(corners) / sizeof(corners[0]), CoordModeOrigin);
1733 ydiff = event->xbutton.y - data->rubber_band.start_y;
1734 xdiff = event->xbutton.x - data->rubber_band.start_x;
1735 data->rubber_band.last_x = data->rubber_band.start_x + xdiff;
1736 data->rubber_band.last_y = data->rubber_band.start_y + ydiff;
1737 if (data->rubber_band.last_y < data->rubber_band.start_y ||
1738 data->rubber_band.last_x < data->rubber_band.start_x)
1740 data->rubber_band.last_y = data->rubber_band.start_y;
1741 data->rubber_band.last_x = data->rubber_band.start_x;
1743 SetupCorners(corners, data);
1744 XDrawLines(dpy, canvas, RubberGC,
1745 corners, sizeof(corners) / sizeof(corners[0]), CoordModeOrigin);
1749 EndRubberBand(Window w, image_data_t *data, XEvent *event)
1756 SetupCorners(corners, data);
1757 XDrawLines(dpy, canvas, RubberGC,
1758 corners, sizeof(corners) / sizeof(corners[0]), CoordModeOrigin);
1759 if (data->rubber_band.start_x >= data->rubber_band.last_x ||
1760 data->rubber_band.start_y >= data->rubber_band.last_y)
1762 top.x = data->rubber_band.start_x;
1763 bot.x = data->rubber_band.last_x;
1764 top.y = data->rubber_band.start_y;
1765 bot.y = data->rubber_band.last_y;
1766 diff = data->q_max - data->q_min;
1767 delta = (double)top.y / (double)height;
1768 data->q_min += diff * delta;
1769 delta = (double)(height - bot.y) / (double)height;
1770 data->q_max -= diff * delta;
1771 diff = data->p_max - data->p_min;
1772 delta = (double)top.x / (double)width;
1773 data->p_min += diff * delta;
1774 delta = (double)(width - bot.x) / (double)width;
1775 data->p_max -= diff * delta;
1777 set_new_params(w, data);
1781 set_new_params(Window w, image_data_t *data)
1783 frame = (maxframe + 1) % MAXFRAMES;
1784 if (frame > maxframe)
1786 a_range = data->p_max - data->p_min;
1787 b_range = data->q_max - data->q_min;
1788 a_minimums[frame] = min_a = data->p_min;
1789 b_minimums[frame] = min_b = data->q_min;
1790 a_inc = a_range / (double)width;
1791 b_inc = b_range / (double)height;
1797 a_maximums[frame] = max_a = data->p_max;
1798 b_maximums[frame] = max_b = data->q_max;
1807 if (frame > maxframe)
1824 rubber_data.p_min = min_a = a_minimums[frame];
1825 rubber_data.q_min = min_b = b_minimums[frame];
1826 rubber_data.p_max = max_a = a_maximums[frame];
1827 rubber_data.q_max = max_b = b_maximums[frame];
1828 a_range = max_a - min_a;
1829 b_range = max_b - min_b;
1830 a_inc = a_range / (double)width;
1831 b_inc = b_range / (double)height;
1840 redraw(exponents[frame], expind[frame], 0);
1855 for (i=frame; i<maxframe; i++) {
1856 exponents[frame] = exponents[frame+1];
1857 expind[frame] = expind[frame+1];
1858 a_minimums[frame] = a_minimums[frame+1];
1859 b_minimums[frame] = b_minimums[frame+1];
1860 a_maximums[frame] = a_maximums[frame+1];
1861 b_maximums[frame] = b_maximums[frame+1];
1872 for (i = 0 ; i < maxcolor; ++i)
1873 Points.npoints[i] = 0;
1877 BufferPoint(Display *display, Window window, int color, int x, int y)
1880 /* Guard against bogus color values. Shouldn't be necessary but paranoia
1884 else if (color >= maxcolor)
1885 color = maxcolor - 1;
1887 if (Points.npoints[color] == MAXPOINTS)
1889 XDrawPoints(display, window, Data_GC[color],
1890 Points.data[color], Points.npoints[color], CoordModeOrigin);
1891 XDrawPoints(display, pixmap, Data_GC[color],
1892 Points.data[color], Points.npoints[color], CoordModeOrigin);
1893 Points.npoints[color] = 0;
1895 Points.data[color][Points.npoints[color]].x = x;
1896 Points.data[color][Points.npoints[color]].y = y;
1897 ++Points.npoints[color];
1905 for (color = 0; color < maxcolor; ++color)
1906 if (Points.npoints[color])
1908 XDrawPoints(dpy, canvas, Data_GC[color],
1909 Points.data[color], Points.npoints[color],
1911 XDrawPoints(dpy, pixmap, Data_GC[color],
1912 Points.data[color], Points.npoints[color],
1914 Points.npoints[color] = 0;
1921 printf("During run-time, interactive control can be exerted via : \n");
1922 printf("Mouse buttons allow rubber-banding of a zoom box\n");
1923 printf("< halves the 'dwell', > doubles the 'dwell'\n");
1924 printf("[ halves the 'settle', ] doubles the 'settle'\n");
1925 printf("D flushes the drawing buffer\n");
1926 printf("e or E recalculates color indices\n");
1927 printf("f or F saves exponents to a file\n");
1928 printf("h or H or ? displays this message\n");
1929 printf("i decrements, I increments the stripe interval\n");
1930 printf("KJMN increase/decrease minimum negative exponent\n");
1931 printf("m increments the map index, changing maps\n");
1932 printf("p or P reverses the colormap for negative/positive exponents\n");
1933 printf("r redraws without recalculating\n");
1934 printf("R redraws, recalculating with new dwell and settle values\n");
1935 printf("s or S spins the colorwheel\n");
1936 printf("u pops back up to the last zoom\n");
1937 printf("U pops back up to the first picture\n");
1938 printf("v or V displays the values of various settings\n");
1939 printf("w decrements, W increments the color wheel index\n");
1940 printf("x or X clears the window\n");
1941 printf("q or Q exits\n");
1949 printf("\nminlyap=%f minexp=%f maxexp=%f\n",minlyap,minexp,maxexp);
1950 printf("width=%d height=%d\n",width,height);
1951 printf("settle=%d dwell=%d start_x=%f\n",settle,dwell, start_x);
1952 printf("min_a=%f a_rng=%f max_a=%f\n",min_a,a_range,max_a);
1953 printf("min_b=%f b_rng=%f max_b=%f\n",min_b,b_range,max_b);
1955 printf("pseudo-random forcing\n");
1957 printf("periodic forcing=");
1958 for (i=0;i<maxindex;i++)
1959 printf("%d",forcing[i]);
1963 printf("periodic forcing=01\n");
1965 printf("function forcing=");
1966 for (i=0;i<funcmaxindex;i++) {
1967 printf("%d",Forcing[i]);
1971 printf("numcolors=%d\n",numcolors-1);
1979 for (i=0;i<MAXFRAMES;i++)
1988 for (i=0;i<MAXFRAMES;i++) {
1990 (double *)malloc(sizeof(double)*width*height))==NULL){
1991 fprintf(stderr,"Error malloc'ing exponent array.\n");
2001 for (i=0;i<MAXINDEX;i++)
2002 forcing[i] = (random() > prob) ? 0 : 1;