1 /* xscreensaver, Copyright (c) 1992, 1996, 1998, 2001, 2006
2 * Jamie Zawinski <jwz@jwz.org>
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
12 * 19971004: Johannes Keukelaar <johannes@nada.kth.se>: Use helix screen
16 #include "screenhack.h"
21 unsigned int default_fg_pixel;
22 int iterations, offset;
27 int current_x, current_y, remaining_iterations;
33 rorschach_init (Display *dpy, Window window)
35 struct state *st = (struct state *) calloc (1, sizeof(*st));
38 XWindowAttributes xgwa;
39 XGetWindowAttributes (dpy, window, &xgwa);
41 gcv.foreground = st->default_fg_pixel =
42 get_pixel_resource (dpy, cmap, "foreground", "Foreground");
43 st->draw_gc = XCreateGC (dpy, window, GCForeground, &gcv);
44 gcv.foreground = get_pixel_resource (dpy, cmap, "background", "Background");
45 st->iterations = get_integer_resource (dpy, "iterations", "Integer");
46 st->offset = get_integer_resource (dpy, "offset", "Integer");
47 if (st->offset <= 0) st->offset = 3;
48 if (st->iterations < 10) st->iterations = 10;
49 st->sleep_time = get_integer_resource (dpy, "delay", "Delay");
50 st->xsym = get_boolean_resource (dpy, "xsymmetry", "Symmetry");
51 st->ysym = get_boolean_resource (dpy, "ysymmetry", "Symmetry");
52 st->remaining_iterations = -1;
58 rorschach_reshape (Display *dpy, Window window, void *closure,
59 unsigned int width, unsigned int height)
61 struct state *st = (struct state *) closure;
68 rorschach_draw_start (Display *dpy, Window window, struct state *st)
71 XWindowAttributes xgwa;
73 XGetWindowAttributes (dpy, window, &xgwa);
74 st->xlim = xgwa.width;
75 st->ylim = xgwa.height;
78 if (st->color.pixel) XFreeColors (dpy, cmap, &st->color.pixel, 1, 0);
81 hsv_to_rgb (random()%360, 1.0, 1.0, &st->color.red, &st->color.green, &st->color.blue);
82 if ((!mono_p) && XAllocColor (dpy, cmap, &st->color))
83 XSetForeground (dpy, st->draw_gc, st->color.pixel);
85 XSetForeground (dpy, st->draw_gc, st->default_fg_pixel);
87 st->current_x = st->xlim/2;
88 st->current_y = st->ylim/2;
89 st->remaining_iterations = st->iterations;
94 rorschach_draw_step (Display *dpy, Window window, struct state *st)
96 # define ITER_CHUNK 300
97 XPoint points [4 * ITER_CHUNK];
98 int x = st->current_x;
99 int y = st->current_y;
102 int this_iterations = ITER_CHUNK;
103 if (this_iterations > st->remaining_iterations)
104 this_iterations = st->remaining_iterations;
106 for (i = 0; i < this_iterations; i++)
108 x += ((random () % (1 + (st->offset << 1))) - st->offset);
109 y += ((random () % (1 + (st->offset << 1))) - st->offset);
115 points [j].x = st->xlim - x;
122 points [j].y = st->ylim - y;
125 if (st->xsym && st->ysym)
127 points [j].x = st->xlim - x;
128 points [j].y = st->ylim - y;
132 XDrawPoints (dpy, window, st->draw_gc, points, j, CoordModeOrigin);
133 st->remaining_iterations -= this_iterations;
134 if (st->remaining_iterations < 0) st->remaining_iterations = 0;
141 rorschach_draw (Display *dpy, Window window, void *closure)
143 struct state *st = (struct state *) closure;
144 unsigned long delay = 20000;
147 st->eraser = erase_window (dpy, window, st->eraser);
151 if (st->remaining_iterations > 0)
153 rorschach_draw_step (dpy, window, st);
154 if (st->remaining_iterations == 0)
155 delay = st->sleep_time * 1000000;
159 if (st->remaining_iterations == 0)
160 st->eraser = erase_window (dpy, window, st->eraser);
162 rorschach_draw_start (dpy, window, st);
170 rorschach_event (Display *dpy, Window window, void *closure, XEvent *event)
176 rorschach_free (Display *dpy, Window window, void *closure)
178 struct state *st = (struct state *) closure;
183 static const char *rorschach_defaults [] = {
184 ".background: black",
185 ".foreground: white",
194 static XrmOptionDescRec rorschach_options [] = {
195 { "-iterations", ".iterations", XrmoptionSepArg, 0 },
196 { "-offset", ".offset", XrmoptionSepArg, 0 },
197 { "-xsymmetry", ".xsymmetry", XrmoptionNoArg, "true" },
198 { "-ysymmetry", ".ysymmetry", XrmoptionNoArg, "true" },
199 { "-no-xsymmetry", ".xsymmetry", XrmoptionNoArg, "false" },
200 { "-no-ysymmetry", ".ysymmetry", XrmoptionNoArg, "false" },
201 { "-delay", ".delay", XrmoptionSepArg, 0 },
205 XSCREENSAVER_MODULE ("Rorschach", rorschach)