1 /* xscreensaver, Copyright (c) 1992, 1995, 1996, 1998
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 * This code derived from TI Explorer Lisp code by Joe Keane, Fritz Mueller,
17 #include "screenhack.h"
21 static GC color0, color1, color2, color3, color4, color5, color6, color7;
26 static int observer_z;
27 static int x_offset, y_offset;
28 static int unit_pixels;
37 move_line (struct point_state *state0, struct point_state *state1, GC gc)
39 if (state0->same_p && state1->same_p)
43 XDrawLine (dpy, window, black,
44 state0->old_x, state0->old_y, state1->old_x, state1->old_y);
45 XDrawLine (dpy, window, gc,
46 state0->new_x, state0->new_y, state1->new_x, state1->new_y);
50 XSegment segments [2];
51 segments [0].x1 = state0->old_x; segments [0].y1 = state0->old_y;
52 segments [0].x2 = state1->old_x; segments [0].y2 = state1->old_y;
53 segments [1].x1 = state0->new_x; segments [1].y1 = state0->new_y;
54 segments [1].x2 = state1->new_x; segments [1].y2 = state1->new_y;
55 XDrawSegments (dpy, window, gc, segments, 2);
60 hyper (double xy, double xz, double yz, double xw, double yw, double zw)
62 double cos_xy = cos (xy), sin_xy = sin (xy);
63 double cos_xz = cos (xz), sin_xz = sin (xz);
64 double cos_yz = cos (yz), sin_yz = sin (yz);
65 double cos_xw = cos (xw), sin_xw = sin (xw);
66 double cos_yw = cos (yw), sin_yw = sin (yw);
67 double cos_zw = cos (zw), sin_zw = sin (zw);
69 double ax = 1.0, ay = 0.0, az = 0.0, aw = 0.0;
70 double bx = 0.0, by = 1.0, bz = 0.0, bw = 0.0;
71 double cx = 0.0, cy = 0.0, cz = 1.0, cw = 0.0;
72 double dx = 0.0, dy = 0.0, dz = 0.0, dw = 1.0;
74 double _tmp0_, _tmp1_;
76 struct point_state points [16];
77 memset (points, 0, sizeof (points));
79 #define mmmm (&points[0])
80 #define mmmp (&points[1])
81 #define mmpm (&points[2])
82 #define mmpp (&points[3])
83 #define mpmm (&points[4])
84 #define mpmp (&points[5])
85 #define mppm (&points[6])
86 #define mppp (&points[7])
87 #define pmmm (&points[8])
88 #define pmmp (&points[9])
89 #define pmpm (&points[10])
90 #define pmpp (&points[11])
91 #define ppmm (&points[12])
92 #define ppmp (&points[13])
93 #define pppm (&points[14])
94 #define pppp (&points[15])
100 #define compute(a,b,c,d,point_state) \
101 temp_mult = (unit_pixels / (((a*az) + (b*bz) + (c*cz) + (d*dz) + \
102 (a*aw) + (b*bw) + (c*cw) + (d*dw)) \
104 point_state->old_x = point_state->new_x; \
105 point_state->old_y = point_state->new_y; \
106 point_state->new_x = ((((a*ax) + (b*bx) + (c*cx) + (d*dx)) * temp_mult) \
108 point_state->new_y = ((((a*ay) + (b*by) + (c*cy) + (d*dy)) * temp_mult) \
110 point_state->same_p = (point_state->old_x == point_state->new_x && \
111 point_state->old_y == point_state->new_y);
113 compute (-1, -1, -1, -1, mmmm);
114 compute (-1, -1, -1, 1, mmmp);
115 compute (-1, -1, 1, -1, mmpm);
116 compute (-1, -1, 1, 1, mmpp);
117 compute (-1, 1, -1, -1, mpmm);
118 compute (-1, 1, -1, 1, mpmp);
119 compute (-1, 1, 1, -1, mppm);
120 compute (-1, 1, 1, 1, mppp);
121 compute ( 1, -1, -1, -1, pmmm);
122 compute ( 1, -1, -1, 1, pmmp);
123 compute ( 1, -1, 1, -1, pmpm);
124 compute ( 1, -1, 1, 1, pmpp);
125 compute ( 1, 1, -1, -1, ppmm);
126 compute ( 1, 1, -1, 1, ppmp);
127 compute ( 1, 1, 1, -1, pppm);
128 compute ( 1, 1, 1, 1, pppp);
130 move_line (mmmm, mmmp, color0);
131 move_line (mmmm, mmpm, color0);
132 move_line (mmpm, mmpp, color0);
133 move_line (mmmp, mmpp, color0);
135 move_line (pmmm, pmmp, color1);
136 move_line (pmmm, pmpm, color1);
137 move_line (pmpm, pmpp, color1);
138 move_line (pmmp, pmpp, color1);
140 move_line (mpmm, mpmp, color2);
141 move_line (mpmm, mppm, color2);
142 move_line (mppm, mppp, color2);
143 move_line (mpmp, mppp, color2);
145 move_line (mmpp, mppp, color3);
146 move_line (mmpp, pmpp, color3);
147 move_line (pmpp, pppp, color3);
148 move_line (mppp, pppp, color3);
150 move_line (mmmm, mpmm, color4);
151 move_line (mmmm, pmmm, color4);
152 move_line (mpmm, ppmm, color4);
153 move_line (pmmm, ppmm, color4);
155 move_line (mmmp, mpmp, color5);
156 move_line (mmmp, pmmp, color5);
157 move_line (pmmp, ppmp, color5);
158 move_line (mpmp, ppmp, color5);
160 move_line (mmpm, mppm, color6);
161 move_line (mmpm, pmpm, color6);
162 move_line (pmpm, pppm, color6);
163 move_line (mppm, pppm, color6);
165 move_line (ppmm, ppmp, color7);
166 move_line (ppmm, pppm, color7);
167 move_line (pppm, pppp, color7);
168 move_line (ppmp, pppp, color7);
170 /* If you get error messages about the following forms, and you think you're
171 using an ANSI C conforming compiler, then you're mistaken. Possibly you're
172 mixing an ANSI compiler with a non-ANSI preprocessor, or vice versa.
173 Regardless, your system is broken; it's not a bug in this program.
175 #if defined(__STDC__) || defined(__ANSI_CPP__)
176 # define rotate(name,dim0,dim1,cos,sin) \
177 _tmp0_ = ((name##dim0 * cos) + (name##dim1 * sin)); \
178 _tmp1_ = ((name##dim1 * cos) - (name##dim0 * sin)); \
179 name##dim0 = _tmp0_; \
182 # define rotates(dim0,dim1) \
183 if (sin_##dim0##dim1 != 0) { \
184 rotate(a, dim0, dim1, cos_##dim0##dim1, sin_##dim0##dim1); \
185 rotate(b, dim0, dim1, cos_##dim0##dim1, sin_##dim0##dim1); \
186 rotate(c, dim0, dim1, cos_##dim0##dim1, sin_##dim0##dim1); \
187 rotate(d, dim0, dim1, cos_##dim0##dim1, sin_##dim0##dim1); \
190 #else /* !__STDC__, courtesy of Andreas Luik <luik@isa.de> */
191 # define rotate(name,dim0,dim1,cos,sin) \
192 _tmp0_ = ((name/**/dim0 * cos) + (name/**/dim1 * sin)); \
193 _tmp1_ = ((name/**/dim1 * cos) - (name/**/dim0 * sin)); \
194 name/**/dim0 = _tmp0_; \
195 name/**/dim1 = _tmp1_;
197 # define rotates(dim0,dim1) \
198 if (sin_/**/dim0/**/dim1 != 0) { \
199 rotate(a,dim0,dim1,cos_/**/dim0/**/dim1,sin_/**/dim0/**/dim1); \
200 rotate(b,dim0,dim1,cos_/**/dim0/**/dim1,sin_/**/dim0/**/dim1); \
201 rotate(c,dim0,dim1,cos_/**/dim0/**/dim1,sin_/**/dim0/**/dim1); \
202 rotate(d,dim0,dim1,cos_/**/dim0/**/dim1,sin_/**/dim0/**/dim1); \
204 #endif /* !__STDC__ */
214 screenhack_handle_events (dpy);
215 if (delay) usleep (delay);
220 char *progclass = "Hypercube";
222 char *defaults [] = {
223 ".background: black",
224 ".foreground: white",
231 "*color6: dodgerblue",
246 XrmOptionDescRec options [] = {
247 { "-color0", ".color0", XrmoptionSepArg, 0 },
248 { "-color1", ".color1", XrmoptionSepArg, 0 },
249 { "-color2", ".color2", XrmoptionSepArg, 0 },
250 { "-color3", ".color3", XrmoptionSepArg, 0 },
251 { "-color4", ".color4", XrmoptionSepArg, 0 },
252 { "-color5", ".color5", XrmoptionSepArg, 0 },
253 { "-color6", ".color6", XrmoptionSepArg, 0 },
254 { "-color7", ".color7", XrmoptionSepArg, 0 },
256 { "-xw", ".xw", XrmoptionSepArg, 0 },
257 { "-xy", ".xy", XrmoptionSepArg, 0 },
258 { "-xz", ".xz", XrmoptionSepArg, 0 },
259 { "-yw", ".yw", XrmoptionSepArg, 0 },
260 { "-yz", ".yz", XrmoptionSepArg, 0 },
261 { "-zw", ".zw", XrmoptionSepArg, 0 },
263 { "-observer-z", ".observer-z", XrmoptionSepArg, 0 },
264 { "-delay", ".delay", XrmoptionSepArg, 0 },
269 screenhack (Display *d, Window w)
272 XWindowAttributes xgwa;
274 double xy, xz, yz, xw, yw, zw;
279 XGetWindowAttributes (dpy, window, &xgwa);
280 cmap = xgwa.colormap;
282 x_offset = xgwa.width / 2;
283 y_offset = xgwa.height / 2;
284 unit_pixels = xgwa.width < xgwa.height ? xgwa.width : xgwa.height;
286 xy = get_float_resource ("xy", "Float");
287 xz = get_float_resource ("xz", "Float");
288 yz = get_float_resource ("yz", "Float");
289 xw = get_float_resource ("xw", "Float");
290 yw = get_float_resource ("yw", "Float");
291 zw = get_float_resource ("zw", "Float");
293 observer_z = get_integer_resource ("observer-z", "Integer");
295 delay = get_integer_resource ("delay", "Integer");
297 bg = get_pixel_resource ("background", "Background", dpy, cmap);
301 gcv.function = GXcopy;
303 black = XCreateGC (dpy, window, GCForeground|GCFunction, &gcv);
304 gcv.foreground = get_pixel_resource ("foreground", "Foreground",
306 color0 = color1 = color2 = color3 = color4 = color5 = color6 = color7 =
307 XCreateGC (dpy, window, GCForeground|GCFunction, &gcv);
312 gcv.function = GXxor;
313 #define make_gc(color,name) \
314 gcv.foreground = bg ^ get_pixel_resource ((name), "Foreground", \
316 color = XCreateGC (dpy, window, GCForeground|GCFunction, &gcv)
318 make_gc (color0,"color0");
319 make_gc (color1,"color1");
320 make_gc (color2,"color2");
321 make_gc (color3,"color3");
322 make_gc (color4,"color4");
323 make_gc (color5,"color5");
324 make_gc (color6,"color6");
325 make_gc (color7,"color7");
328 hyper (xy, xz, yz, xw, yw, zw);