1 /* xscreensaver, Copyright (c) 1992 Jamie Zawinski <jwz@lucid.com>
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
12 #include "screenhack.h"
14 static GC draw_gc, erase_gc;
15 static unsigned int default_fg_pixel;
16 static int iterations, offset;
17 static Bool xsym, ysym;
20 init_rorschach (dpy, window)
26 XWindowAttributes xgwa;
27 XGetWindowAttributes (dpy, window, &xgwa);
29 gcv.foreground = default_fg_pixel =
30 get_pixel_resource ("foreground", "Foreground", dpy, cmap);
31 draw_gc = XCreateGC (dpy, window, GCForeground, &gcv);
32 gcv.foreground = get_pixel_resource ("background", "Background", dpy, cmap);
33 erase_gc = XCreateGC (dpy, window, GCForeground, &gcv);
34 iterations = get_integer_resource ("iterations", "Integer");
35 offset = get_integer_resource ("offset", "Integer");
36 if (offset <= 0) offset = 3;
37 if (iterations < 10) iterations = 10;
38 xsym = get_boolean_resource ("xsymmetry", "Symmetry");
39 ysym = get_boolean_resource ("ysymmetry", "Symmetry");
48 XWindowAttributes xgwa;
49 int xlim, ylim, x, y, i, got_color = 0;
52 XClearWindow (dpy, window);
53 XGetWindowAttributes (dpy, window, &xgwa);
59 hsv_to_rgb (random()%360, 1.0, 1.0, &color.red, &color.green, &color.blue);
60 if ((!mono_p) && (got_color = XAllocColor (dpy, cmap, &color)))
61 XSetForeground (dpy, draw_gc, color.pixel);
63 XSetForeground (dpy, draw_gc, default_fg_pixel);
67 for (i = 0; i < iterations; i++)
70 x += ((random () % (1 + (offset << 1))) - offset);
71 y += ((random () % (1 + (offset << 1))) - offset);
77 points [j].x = xlim - x;
84 points [j].y = ylim - y;
89 points [j].x = xlim - x;
90 points [j].y = ylim - y;
93 XDrawPoints (dpy, window, draw_gc, points, j, CoordModeOrigin);
97 for (i = 0; i < (ylim >> 1); i++)
99 int y = (random () % ylim);
100 XDrawLine (dpy, window, erase_gc, 0, y, xlim, y);
105 XClearWindow (dpy, window);
106 if (got_color) XFreeColors (dpy, cmap, &color.pixel, 1, 0);
112 char *progclass = "Rorschach";
114 char *defaults [] = {
115 "*background: black",
116 "*foreground: white",
124 XrmOptionDescRec options [] = {
125 { "-iterations", ".iterations", XrmoptionSepArg, 0 },
126 { "-offset", ".offset", XrmoptionSepArg, 0 },
127 { "-xsymmetry", ".xsymmetry", XrmoptionNoArg, "true" },
128 { "-ysymmetry", ".ysymmetry", XrmoptionNoArg, "true" }
130 int options_size = (sizeof (options) / sizeof (options[0]));
133 screenhack (dpy, window)
137 init_rorschach (dpy, window);