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: hopalong.c /main/3 1995/11/02 16:07:11 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 * hopalong.c - Real Plane Fractals for dtscreen, the X Window System lockscreen.
35 * Copyright (c) 1991 by Patrick J. Naughton.
37 * See dtscreen.c for copying information.
40 * 29-Oct-90: fix bad (int) cast.
41 * 29-Jul-90: support for multiple screens.
42 * 08-Jul-90: new timing and colors and new algorithm for fractals.
43 * 15-Dec-89: Fix for proper skipping of {White,Black}Pixel() in colors.
44 * 08-Oct-89: Fixed long standing typo bug in RandomInitHop();
45 * Fixed bug in memory allocation in inithop();
46 * Moved seconds() to an extern.
47 * Got rid of the % mod since .mod is slow on a sparc.
49 * 31-Aug-88: Forked from dtscreen.c for modularity.
50 * 23-Mar-88: Coded HOPALONG routines from Scientific American Sept. 86 p. 14.
59 int centery; /* center of the screen */
64 double j; /* hopalong parameters */
70 static XPoint *pointBuffer = 0; /* pointer for XDrawPoints */
75 inithop(perwindow *pwin)
78 XWindowAttributes xgwa;
81 if (pwin->data) free(pwin->data);
82 pwin->data = (void *)malloc(sizeof(hopstruct));
83 memset(pwin->data, '\0', sizeof(hopstruct));
84 hp = (hopstruct *)pwin->data;
85 XGetWindowAttributes(dsp, pwin->w, &xgwa);
86 hp->centerx = xgwa.width / 2;
87 hp->centery = xgwa.height / 2;
88 range = sqrt((double) hp->centerx * hp->centerx +
89 (double) hp->centery * hp->centery) /
90 (10.0 + random() % 10);
93 hp->inc = (int) ((random() / MAXRAND) * 200) - 100;
94 hp->a = (random() / MAXRAND) * range - range / 2.0;
95 hp->b = (random() / MAXRAND) * range - range / 2.0;
96 hp->c = (random() / MAXRAND) * range - range / 2.0;
103 pointBuffer = (XPoint *) malloc(batchcount * sizeof(XPoint));
105 XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
106 XFillRectangle(dsp, pwin->w, pwin->gc, 0, 0,
107 hp->centerx * 2, hp->centery * 2);
108 XSetForeground(dsp, pwin->gc, WhitePixelOfScreen(pwin->perscreen->screen));
109 hp->startTime = seconds();
114 drawhop(perwindow *pwin)
118 XPoint *xp = pointBuffer;
119 hopstruct *hp = (hopstruct *)pwin->data;
122 if (!mono && pwin->perscreen->npixels > 2) {
123 XSetForeground(dsp, pwin->gc, pwin->perscreen->pixels[hp->pix]);
124 if (++hp->pix >= pwin->perscreen->npixels)
129 hp->j = hp->a - hp->i;
130 hp->i = oldj + (hp->i < 0
131 ? sqrt(fabs(hp->b * (hp->i + hp->inc) - hp->c))
132 : -sqrt(fabs(hp->b * (hp->i + hp->inc) - hp->c)));
133 xp->x = hp->centerx + (int) (hp->i + hp->j);
134 xp->y = hp->centery - (int) (hp->i - hp->j);
137 XDrawPoints(dsp, pwin->w, pwin->gc,
138 pointBuffer, batchcount, CoordModeOrigin);
139 if (seconds() - hp->startTime > TIMEOUT)