1 /* xscreensaver, Copyright (c) 1992-2014 Jamie Zawinski <jwz@jwz.org>
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
11 * 19971004: Johannes Keukelaar <johannes@nada.kth.se>: Use helix screen
15 #include "screenhack.h"
20 unsigned int default_fg_pixel;
21 int iterations, offset;
26 int current_x, current_y, remaining_iterations;
32 rorschach_init (Display *dpy, Window window)
34 struct state *st = (struct state *) calloc (1, sizeof(*st));
37 XWindowAttributes xgwa;
38 XGetWindowAttributes (dpy, window, &xgwa);
40 gcv.foreground = st->default_fg_pixel =
41 get_pixel_resource (dpy, cmap, "foreground", "Foreground");
42 st->draw_gc = XCreateGC (dpy, window, GCForeground, &gcv);
43 gcv.foreground = get_pixel_resource (dpy, cmap, "background", "Background");
44 st->iterations = get_integer_resource (dpy, "iterations", "Integer");
45 st->offset = get_integer_resource (dpy, "offset", "Integer");
46 if (st->offset <= 0) st->offset = 3;
47 if (st->iterations < 10) st->iterations = 10;
48 st->sleep_time = get_integer_resource (dpy, "delay", "Delay");
49 st->xsym = get_boolean_resource (dpy, "xsymmetry", "Symmetry");
50 st->ysym = get_boolean_resource (dpy, "ysymmetry", "Symmetry");
51 st->remaining_iterations = -1;
57 rorschach_reshape (Display *dpy, Window window, void *closure,
58 unsigned int width, unsigned int height)
60 struct state *st = (struct state *) closure;
67 rorschach_draw_start (Display *dpy, Window window, struct state *st)
70 XWindowAttributes xgwa;
72 XGetWindowAttributes (dpy, window, &xgwa);
73 st->xlim = xgwa.width;
74 st->ylim = xgwa.height;
77 if (st->color.pixel) XFreeColors (dpy, cmap, &st->color.pixel, 1, 0);
80 hsv_to_rgb (random()%360, 1.0, 1.0, &st->color.red, &st->color.green, &st->color.blue);
81 if ((!mono_p) && XAllocColor (dpy, cmap, &st->color))
82 XSetForeground (dpy, st->draw_gc, st->color.pixel);
84 XSetForeground (dpy, st->draw_gc, st->default_fg_pixel);
86 st->current_x = st->xlim/2;
87 st->current_y = st->ylim/2;
88 st->remaining_iterations = st->iterations;
93 rorschach_draw_step (Display *dpy, Window window, struct state *st)
95 # define ITER_CHUNK 300
96 XPoint points [4 * ITER_CHUNK];
97 int x = st->current_x;
98 int y = st->current_y;
101 int this_iterations = ITER_CHUNK;
102 if (this_iterations > st->remaining_iterations)
103 this_iterations = st->remaining_iterations;
105 for (i = 0; i < this_iterations; i++)
107 x += ((random () % (1 + (st->offset << 1))) - st->offset);
108 y += ((random () % (1 + (st->offset << 1))) - st->offset);
114 points [j].x = st->xlim - x;
121 points [j].y = st->ylim - y;
124 if (st->xsym && st->ysym)
126 points [j].x = st->xlim - x;
127 points [j].y = st->ylim - y;
131 XDrawPoints (dpy, window, st->draw_gc, points, j, CoordModeOrigin);
132 st->remaining_iterations -= this_iterations;
133 if (st->remaining_iterations < 0) st->remaining_iterations = 0;
140 rorschach_draw (Display *dpy, Window window, void *closure)
142 struct state *st = (struct state *) closure;
143 unsigned long delay = 20000;
146 st->eraser = erase_window (dpy, window, st->eraser);
150 if (st->remaining_iterations > 0)
152 rorschach_draw_step (dpy, window, st);
153 if (st->remaining_iterations == 0)
154 delay = st->sleep_time * 1000000;
158 if (st->remaining_iterations == 0)
159 st->eraser = erase_window (dpy, window, st->eraser);
161 rorschach_draw_start (dpy, window, st);
169 rorschach_event (Display *dpy, Window window, void *closure, XEvent *event)
171 struct state *st = (struct state *) closure;
172 if (screenhack_event_helper (dpy, window, event))
174 st->remaining_iterations = 0;
181 rorschach_free (Display *dpy, Window window, void *closure)
183 struct state *st = (struct state *) closure;
188 static const char *rorschach_defaults [] = {
189 ".background: black",
190 ".foreground: white",
198 "*ignoreRotation: True",
203 static XrmOptionDescRec rorschach_options [] = {
204 { "-iterations", ".iterations", XrmoptionSepArg, 0 },
205 { "-offset", ".offset", XrmoptionSepArg, 0 },
206 { "-xsymmetry", ".xsymmetry", XrmoptionNoArg, "true" },
207 { "-ysymmetry", ".ysymmetry", XrmoptionNoArg, "true" },
208 { "-no-xsymmetry", ".xsymmetry", XrmoptionNoArg, "false" },
209 { "-no-ysymmetry", ".ysymmetry", XrmoptionNoArg, "false" },
210 { "-delay", ".delay", XrmoptionSepArg, 0 },
214 XSCREENSAVER_MODULE ("Rorschach", rorschach)