1 | /* xscreensaver, Copyright (c) 1992, 1996, 1998, 2001 |
---|
2 | * Jamie Zawinski <jwz@jwz.org> |
---|
3 | * |
---|
4 | * Permission to use, copy, modify, distribute, and sell this software and its |
---|
5 | * documentation for any purpose is hereby granted without fee, provided that |
---|
6 | * the above copyright notice appear in all copies and that both that |
---|
7 | * copyright notice and this permission notice appear in supporting |
---|
8 | * documentation. No representations are made about the suitability of this |
---|
9 | * software for any purpose. It is provided "as is" without express or |
---|
10 | * implied warranty. |
---|
11 | * |
---|
12 | * 19971004: Johannes Keukelaar <johannes@nada.kth.se>: Use helix screen |
---|
13 | * eraser. |
---|
14 | */ |
---|
15 | |
---|
16 | #include "screenhack.h" |
---|
17 | #include "erase.h" |
---|
18 | |
---|
19 | static GC draw_gc, erase_gc; |
---|
20 | static unsigned int default_fg_pixel; |
---|
21 | static int iterations, offset; |
---|
22 | static Bool xsym, ysym; |
---|
23 | static int sleep_time; |
---|
24 | |
---|
25 | static void |
---|
26 | init_rorschach (Display *dpy, Window window) |
---|
27 | { |
---|
28 | XGCValues gcv; |
---|
29 | Colormap cmap; |
---|
30 | XWindowAttributes xgwa; |
---|
31 | XGetWindowAttributes (dpy, window, &xgwa); |
---|
32 | cmap = xgwa.colormap; |
---|
33 | gcv.foreground = default_fg_pixel = |
---|
34 | get_pixel_resource ("foreground", "Foreground", dpy, cmap); |
---|
35 | draw_gc = XCreateGC (dpy, window, GCForeground, &gcv); |
---|
36 | gcv.foreground = get_pixel_resource ("background", "Background", dpy, cmap); |
---|
37 | erase_gc = XCreateGC (dpy, window, GCForeground, &gcv); |
---|
38 | iterations = get_integer_resource ("iterations", "Integer"); |
---|
39 | offset = get_integer_resource ("offset", "Integer"); |
---|
40 | if (offset <= 0) offset = 3; |
---|
41 | if (iterations < 10) iterations = 10; |
---|
42 | xsym = get_boolean_resource ("xsymmetry", "Symmetry"); |
---|
43 | ysym = get_boolean_resource ("ysymmetry", "Symmetry"); |
---|
44 | } |
---|
45 | |
---|
46 | static void |
---|
47 | hurm (Display *dpy, Window window) |
---|
48 | { |
---|
49 | Colormap cmap; |
---|
50 | XWindowAttributes xgwa; |
---|
51 | int xlim, ylim, x, y, i, got_color = 0; |
---|
52 | XPoint points [4]; |
---|
53 | XColor color; |
---|
54 | XClearWindow (dpy, window); |
---|
55 | XGetWindowAttributes (dpy, window, &xgwa); |
---|
56 | xlim = xgwa.width; |
---|
57 | ylim = xgwa.height; |
---|
58 | cmap = xgwa.colormap; |
---|
59 | |
---|
60 | if (! mono_p) |
---|
61 | hsv_to_rgb (random()%360, 1.0, 1.0, &color.red, &color.green, &color.blue); |
---|
62 | if ((!mono_p) && (got_color = XAllocColor (dpy, cmap, &color))) |
---|
63 | XSetForeground (dpy, draw_gc, color.pixel); |
---|
64 | else |
---|
65 | XSetForeground (dpy, draw_gc, default_fg_pixel); |
---|
66 | |
---|
67 | x = xlim/2; |
---|
68 | y = ylim/2; |
---|
69 | for (i = 0; i < iterations; i++) |
---|
70 | { |
---|
71 | int j = 0; |
---|
72 | x += ((random () % (1 + (offset << 1))) - offset); |
---|
73 | y += ((random () % (1 + (offset << 1))) - offset); |
---|
74 | points [j].x = x; |
---|
75 | points [j].y = y; |
---|
76 | j++; |
---|
77 | if (xsym) |
---|
78 | { |
---|
79 | points [j].x = xlim - x; |
---|
80 | points [j].y = y; |
---|
81 | j++; |
---|
82 | } |
---|
83 | if (ysym) |
---|
84 | { |
---|
85 | points [j].x = x; |
---|
86 | points [j].y = ylim - y; |
---|
87 | j++; |
---|
88 | } |
---|
89 | if (xsym && ysym) |
---|
90 | { |
---|
91 | points [j].x = xlim - x; |
---|
92 | points [j].y = ylim - y; |
---|
93 | j++; |
---|
94 | } |
---|
95 | XDrawPoints (dpy, window, draw_gc, points, j, CoordModeOrigin); |
---|
96 | XSync (dpy, False); |
---|
97 | screenhack_handle_events (dpy); |
---|
98 | } |
---|
99 | sleep ( sleep_time ); |
---|
100 | |
---|
101 | erase_full_window(dpy, window); |
---|
102 | |
---|
103 | XClearWindow (dpy, window); |
---|
104 | if (got_color) XFreeColors (dpy, cmap, &color.pixel, 1, 0); |
---|
105 | XSync (dpy, False); |
---|
106 | screenhack_handle_events (dpy); |
---|
107 | sleep (1); |
---|
108 | } |
---|
109 | |
---|
110 | |
---|
111 | char *progclass = "Rorschach"; |
---|
112 | |
---|
113 | char *defaults [] = { |
---|
114 | ".background: black", |
---|
115 | ".foreground: white", |
---|
116 | "*xsymmetry: true", |
---|
117 | "*ysymmetry: false", |
---|
118 | "*iterations: 4000", |
---|
119 | "*offset: 4", |
---|
120 | "*delay: 5", |
---|
121 | 0 |
---|
122 | }; |
---|
123 | |
---|
124 | XrmOptionDescRec options [] = { |
---|
125 | { "-iterations", ".iterations", XrmoptionSepArg, 0 }, |
---|
126 | { "-offset", ".offset", XrmoptionSepArg, 0 }, |
---|
127 | { "-xsymmetry", ".xsymmetry", XrmoptionNoArg, "true" }, |
---|
128 | { "-ysymmetry", ".ysymmetry", XrmoptionNoArg, "true" }, |
---|
129 | { "-no-xsymmetry", ".xsymmetry", XrmoptionNoArg, "false" }, |
---|
130 | { "-no-ysymmetry", ".ysymmetry", XrmoptionNoArg, "false" }, |
---|
131 | { "-erase-speed", ".eraseSpeed", XrmoptionSepArg, 0 }, |
---|
132 | { "-delay", ".delay", XrmoptionSepArg, 0 }, |
---|
133 | { 0, 0, 0, 0 } |
---|
134 | }; |
---|
135 | |
---|
136 | void |
---|
137 | screenhack (Display *dpy, Window window) |
---|
138 | { |
---|
139 | sleep_time = get_integer_resource("delay", "Integer"); |
---|
140 | init_rorschach (dpy, window); |
---|
141 | while (1) |
---|
142 | hurm (dpy, window); |
---|
143 | } |
---|