1 /* wander, by Rick Campbell <rick@campbellcentral.org>, 19 December 1998.
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
14 #include "screenhack.h"
18 #define MAXIMUM_COLOR_COUNT (256)
20 static unsigned int advance = 0;
21 static Bool circles = 0;
22 static Colormap color_map = (Colormap)NULL;
23 static int color_count = 0;
24 static int color_index = 0;
25 static XColor colors [MAXIMUM_COLOR_COUNT];
26 static GC context = (GC)NULL;
27 static unsigned int density = 0;
29 static int height = 0;
30 static unsigned int length = 0;
31 static unsigned int reset = 0;
32 static unsigned int size = 0;
36 init_wander (Display *display, Window window)
39 XWindowAttributes attributes;
41 XClearWindow (display, window);
42 XGetWindowAttributes (display, window, &attributes);
43 width = attributes.width;
44 height = attributes.height;
45 depth = attributes.depth;
46 color_map = attributes.colormap;
49 free_colors (display, color_map, colors, color_count);
52 context = XCreateGC (display, window, GCForeground, &values);
53 color_count = MAXIMUM_COLOR_COUNT;
54 make_color_loop (display, color_map,
58 colors, &color_count, True, False);
62 colors [0].red = colors [0].green = colors [0].blue = 0;
63 colors [1].red = colors [1].green = colors [1].blue = 0xFFFF;
64 XAllocColor (display, color_map, &colors [0]);
65 XAllocColor (display, color_map, &colors [1]);
67 color_index = random () % color_count;
69 advance = get_integer_resource ("advance", "Integer");
70 density = get_integer_resource ("density", "Integer");
71 if (density < 1) density = 1;
72 reset = get_integer_resource ("reset", "Integer");
73 if (reset < 100) reset = 100;
74 circles = get_boolean_resource ("circles", "Boolean");
75 size = get_integer_resource ("size", "Integer");
76 if (size < 1) size = 1;
78 height = height / size;
79 length = get_integer_resource ("length", "Integer");
80 if (length < 1) length = 1;
81 XSetForeground (display, context, colors [color_index].pixel);
86 wander (Display *display, Window window)
88 int x = random () % width;
89 int y = random () % height;
92 int width_1 = width - 1;
93 int height_1 = height - 1;
94 int length_limit = length;
95 int reset_limit = reset;
96 int color_index = random () % color_count;
97 unsigned long color = colors [random () % color_count].pixel;
98 Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display), size,
100 XSetForeground (display, context,
101 BlackPixel (display, DefaultScreen (display)));
102 XFillRectangle (display, pixmap, context, 0, 0,
103 width * size, height * size);
104 XSetForeground (display, context, color);
105 XFillArc (display, pixmap, context, 0, 0, size, size, 0, 360*64);
109 if (random () % density)
118 x = (x + width_1 + (random () % 3)) % width;
119 y = (y + height_1 + (random () % 3)) % height;
121 if ((random () % length_limit) == 0)
125 color_index = random () % color_count;
129 color_index = (color_index + advance) % color_count;
131 color = colors [color_index].pixel;
132 XSetForeground (display, context, color);
135 XFillArc (display, pixmap, context,
136 0, 0, size, size, 0, 360 * 64);
139 if ((random () % reset_limit) == 0)
141 erase_full_window (display, window);
142 color = colors [random () % color_count].pixel;
143 x = random () % width;
144 y = random () % height;
149 XFillArc (display, pixmap, context, 0, 0, size, size, 0, 360*64);
154 XDrawPoint (display, window, context, x, y);
160 XCopyArea (display, pixmap, window, context, 0, 0, size, size,
165 XFillRectangle (display, window, context, x * size, y * size,
169 screenhack_handle_events (display);
173 char *progclass = "Wander";
187 XrmOptionDescRec options [] =
189 { "-advance", ".advance", XrmoptionSepArg, 0 },
190 { "-circles", ".circles", XrmoptionNoArg, "True" },
191 { "-no-circles",".circles", XrmoptionNoArg, "False" },
192 { "-density", ".density", XrmoptionSepArg, 0 },
193 { "-length", ".length", XrmoptionSepArg, 0 },
194 { "-delay", ".delay", XrmoptionSepArg, 0 },
195 { "-reset", ".reset", XrmoptionSepArg, 0 },
196 { "-size", ".size", XrmoptionSepArg, 0 },
201 screenhack (display, window)
205 int delay = get_integer_resource ("delay", "Integer");
208 init_wander (display, window);
209 wander (display, window);
210 screenhack_handle_events (display);
211 if (delay) sleep (delay);
212 erase_full_window (display, window);