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: flame.c /main/3 1995/11/02 16:07:01 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 * flame.c - recursive fractal cosmic flames.
35 * Copyright (c) 1991 by Patrick J. Naughton.
37 * See dtscreen.c for copying information.
40 * 27-Jun-91: vary number of functions used.
41 * 24-Jun-91: fixed portability problem with integer mod (%).
42 * 06-Jun-91: Written. (received from Scott Graves, spot@cs.cmu.edu).
49 #define MAXTOTAL 10000
54 double f[2][3][MAXLEV];/* three non-homogeneous transforms */
70 static short lasthalf = 0;
84 initflame(perwindow *pwin)
86 XWindowAttributes xwa;
89 if (pwin->data) free(pwin->data);
90 pwin->data = (void *)malloc(sizeof(flamestruct));
91 memset(pwin->data, '\0', sizeof(flamestruct));
92 fs = (flamestruct *)pwin->data;
94 srandom(time((time_t *) 0));
96 XGetWindowAttributes(dsp, pwin->w, &xwa);
97 fs->width = xwa.width;
98 fs->height = xwa.height;
100 fs->max_levels = batchcount;
103 XSetForeground(dsp, pwin->gc, BlackPixelOfScreen(pwin->perscreen->screen));
104 XFillRectangle(dsp, pwin->w, pwin->gc, 0, 0, fs->width, fs->height);
106 if (pwin->perscreen->npixels > 2) {
107 fs->pixcol = halfrandom(pwin->perscreen->npixels);
108 XSetForeground(dsp, pwin->gc, pwin->perscreen->pixels[fs->pixcol]);
110 XSetForeground(dsp, pwin->gc, WhitePixelOfScreen(pwin->perscreen->screen));
115 recurse(flamestruct *fs, double x, double y, int l)
120 if (l == fs->max_levels) {
122 if (fs->total_points > MAXTOTAL) /* how long each fractal runs */
125 if (x > -1.0 && x < 1.0 && y > -1.0 && y < 1.0) {
126 fs->pts[fs->num_points].x = (int) ((fs->width / 2) * (x + 1.0));
127 fs->pts[fs->num_points].y = (int) ((fs->height / 2) * (y + 1.0));
129 if (fs->num_points > MAXBATCH) { /* point buffer size */
130 XDrawPoints(dsp, fs->pwin->w, fs->pwin->gc, fs->pts,
131 fs->num_points, CoordModeOrigin);
136 for (i = 0; i < fs->snum; i++) {
137 nx = fs->f[0][0][i] * x + fs->f[0][1][i] * y + fs->f[0][2][i];
138 ny = fs->f[1][0][i] * x + fs->f[1][1][i] * y + fs->f[1][2][i];
143 if (!recurse(fs, nx, ny, l + 1))
152 drawflame(perwindow *pwin)
154 flamestruct *fs = (flamestruct *)pwin->data;
159 if (!(fs->cur_level++ % fs->max_levels)) {
160 XClearWindow(dsp, fs->pwin->w);
163 if (pwin->perscreen->npixels > 2) {
164 XSetForeground(dsp, pwin->gc,
165 pwin->perscreen->pixels[fs->pixcol]);
166 if (--fs->pixcol < 0)
167 fs->pixcol = pwin->perscreen->npixels - 1;
171 /* number of functions */
172 fs->snum = 2 + (fs->cur_level % (MAXLEV - 1));
174 /* how many of them are of alternate form */
178 fs->anum = halfrandom(fs->snum) + 2;
180 /* 6 dtfs per function */
181 for (k = 0; k < fs->snum; k++) {
182 for (i = 0; i < 2; i++)
183 for (j = 0; j < 3; j++)
184 fs->f[i][j][k] = ((double) (random() & 1023) / 512.0 - 1.0);
187 fs->total_points = 0;
188 (void) recurse(fs, 0.0, 0.0, 0);
189 XDrawPoints(dsp, pwin->w, pwin->gc,
190 fs->pts, fs->num_points, CoordModeOrigin);