2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: rotor.c /main/3 1995/11/02 16:08:34 rswiston $ */
27 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
28 * (c) Copyright 1993, 1994 International Business Machines Corp. *
29 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
30 * (c) Copyright 1993, 1994 Novell, Inc. *
33 * rotor.c - A swirly rotor for dtscreen, the X Window System lockscreen.
35 * Copyright (c) 1991 by Patrick J. Naughton.
37 * See dtscreen.c for copying information.
40 * 11-Nov-90: put into dtscreen (by Steve Zellers, zellers@sun.com)
41 * 16-Oct-90: Received from Tom Lawrence (tcl@cs.brown.edu: 'flight' simulator)
45 * A 'batchcount' of 3 or 4 works best!
53 #define SAVE 100 /* this is a good constant to tweak */
56 #define MAXANGLE 10000.0 /* irrectangular */
57 #define DEFAULTCOUNT 3
59 /*typedef unsigned char Boolean; */
62 #if defined (__STDC__) || defined (AIXV3)
65 #define CAT(X,Y) IDENT(X)Y
73 float radius_drift_max;
74 float radius_drift_now;
79 float ratio_drift_max;
80 float ratio_drift_now;
83 typedef struct flightstruct {
84 struct elem *elements;
97 Boolean smallscreen; /* for iconified view */
104 initrotor(perwindow *pwin)
107 XWindowAttributes xgwa;
112 if (pwin->data) free(pwin->data);
113 pwin->data = (void *)malloc(sizeof(flightstruct));
114 memset(pwin->data, 0, sizeof(flightstruct));
115 fs = (flightstruct *)pwin->data;
116 XGetWindowAttributes(dsp, pwin->w, &xgwa);
117 fs->centerx = xgwa.width / 2;
118 fs->centery = xgwa.height / 2;
121 * sometimes, you go into small view, only to see a really whizzy pattern
122 * that you would like to look more closely at. Normally, clicking in the
123 * icon reinitializes everything - but I don't, cuz I'm that kind of guy.
124 * HENCE, the wassmall stuff you see here.
127 wassmall = fs->smallscreen;
128 fs->smallscreen = (xgwa.width < 100);
130 if (wassmall && !fs->smallscreen)
131 fs->firsttime = True;
134 batchcount = DEFAULTCOUNT;
135 fs->num = batchcount;
137 if ((fs->elements = (struct elem *)
138 malloc(sizeof(struct elem) * fs->num)) == 0) {
142 memset(fs->savex, 0, sizeof(fs->savex));
144 pelem = fs->elements;
146 for (x = fs->num; --x >= 0; pelem++) {
147 pelem->radius_drift_max = 1.0;
148 pelem->radius_drift_now = 1.0;
150 pelem->end_radius = 100.0;
152 pelem->ratio_drift_max = 1.0;
153 pelem->ratio_drift_now = 1.0;
154 pelem->end_ratio = 10.0;
159 fs->lastx = fs->centerx;
160 fs->lasty = fs->centery;
161 fs->angle = (random() % (long) MAXANGLE) / 3;
162 fs->forward = fs->firsttime = True;
164 XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
165 XFillRectangle(dsp, pwin->w, pwin->gc, 0, 0, xgwa.width, xgwa.height);
169 drawrotor(perwindow *pwin)
171 register flightstruct *fs;
172 register struct elem *pelem;
182 #define SCALE(W,N) CAT(W,N)/=12; CAT(W,N)+=(CAT(fs->center,W)-2)
183 #define SCALEIFSMALL() if (fs->smallscreen) { \
184 SCALE(x,1); SCALE(x,2); \
185 SCALE(y,1); SCALE(y,2); \
188 fs = (flightstruct *)pwin->data;
189 for (rp = 0; rp < REPS; rp++) {
193 for (i = fs->num, pelem = fs->elements; --i >= 0; pelem++) {
194 if (pelem->radius_drift_max <= pelem->radius_drift_now) {
195 pelem->start_radius = pelem->end_radius;
197 (float) (random() % 40000) / 100.0 - 200.0;
198 pelem->radius_drift_max =
199 (float) (random() % 100000) + 10000.0;
200 pelem->radius_drift_now = 0.0;
202 if (pelem->ratio_drift_max <= pelem->ratio_drift_now) {
203 pelem->start_ratio = pelem->end_ratio;
205 (float) (random() % 2000) / 100.0 - 10.0;
206 pelem->ratio_drift_max =
207 (float) (random() % 100000) + 10000.0;
208 pelem->ratio_drift_now = 0.0;
210 pelem->ratio = pelem->start_ratio +
211 (pelem->end_ratio - pelem->start_ratio) /
212 pelem->ratio_drift_max * pelem->ratio_drift_now;
213 pelem->angle = fs->angle * pelem->ratio;
214 pelem->radius = pelem->start_radius +
215 (pelem->end_radius - pelem->start_radius) /
216 pelem->radius_drift_max * pelem->radius_drift_now;
218 thisx += (int) (cos(pelem->angle) * pelem->radius);
219 thisy += (int) (sin(pelem->angle) * pelem->radius);
221 pelem->ratio_drift_now += 1.0;
222 pelem->radius_drift_now += 1.0;
226 fs->firsttime = False;
228 XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
230 x1 = (int) fs->savex[fs->rotor];
231 y1 = (int) fs->savey[fs->rotor];
232 x2 = (int) fs->savex[fs->prev];
233 y2 = (int) fs->savey[fs->prev];
237 XDrawLine(dsp, pwin->w, pwin->gc, x1, y1, x2, y2);
239 if (!mono && pwin->perscreen->npixels > 2) {
240 XSetForeground(dsp, pwin->gc,
241 pwin->perscreen->pixels[fs->pix]);
242 if (++fs->pix >= pwin->perscreen->npixels)
245 XSetForeground(dsp, pwin->gc,
246 WhitePixelOfScreen(pwin->perscreen->screen));
255 XDrawLine(dsp, pwin->w, pwin->gc, x1, y1, x2, y2);
257 fs->savex[fs->rotor] = fs->lastx = thisx;
258 fs->savey[fs->rotor] = fs->lasty = thisy;
266 if (fs->angle >= MAXANGLE) {
267 fs->angle = MAXANGLE;
272 if (fs->angle <= 0) {