2 * Copyright (c) 1988-91 by Patrick J. Naughton.
4 * Permission to use, copy, modify, and distribute this software and its
5 * documentation for any purpose and without fee is hereby granted,
6 * provided that the above copyright notice appear in all copies and that
7 * both that copyright notice and this permission notice appear in
8 * supporting documentation.
10 * This file is provided AS IS with no warranties of any kind. The author
11 * shall have no liability with respect to the infringement of copyrights,
12 * trade secrets or any patents by this file or any part thereof. In no
13 * event will the author be liable for any lost revenue or profits or
14 * other special, indirect and consequential damages.
18 * Copyright (c) 1991, 2015, Oracle and/or its affiliates. All rights reserved.
20 * Permission is hereby granted, free of charge, to any person obtaining a
21 * copy of this software and associated documentation files (the "Software"),
22 * to deal in the Software without restriction, including without limitation
23 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
24 * and/or sell copies of the Software, and to permit persons to whom the
25 * Software is furnished to do so, subject to the following conditions:
27 * The above copyright notice and this permission notice (including the next
28 * paragraph) shall be included in all copies or substantial portions of the
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
34 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
36 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
37 * DEALINGS IN THE SOFTWARE.
41 * flame.c - recursive fractal cosmic dust.
43 * Copyright (c) 1991 by Patrick J. Naughton.
45 * See xlock.c for copying information.
48 * 24-Jun-91: fixed portability problem with integer mod (%).
49 * 06-Jun-91: Written. (received from Spot, spot@cs.cmu.edu).
55 #define MAXTOTAL 10000
59 double f
[2][3][20]; /* three non-homogeneous transforms */
72 static flamestruct flames
[MAXSCREENS
];
77 static short lasthalf
= 0;
81 r
= (unsigned long) lasthalf
;
84 r
= (unsigned long) random();
85 lasthalf
= (short) (r
>> 16);
87 return (short) (r
% mv
);
93 flamestruct
*fs
= &flames
[screen
];
94 XWindowAttributes xwa
;
96 srandom((uint_t
) time((long *) 0));
98 if ((batchcount
< 1) || (batchcount
> 64))
101 XGetWindowAttributes(dsp
, win
, &xwa
);
102 fs
->width
= xwa
.width
;
103 fs
->height
= xwa
.height
;
105 fs
->max_levels
= batchcount
;
108 XSetForeground(dsp
, Scr
[screen
].gc
, ssblack
[screen
].pixel
);
109 XFillRectangle(dsp
, win
, Scr
[screen
].gc
, 0, 0, fs
->width
, fs
->height
);
111 if (Scr
[screen
].npixels
> 2) {
112 fs
->pixcol
= halfrandom(Scr
[screen
].npixels
);
113 XSetForeground(dsp
, Scr
[screen
].gc
, Scr
[screen
].pixels
[fs
->pixcol
]);
115 XSetForeground(dsp
, Scr
[screen
].gc
, sswhite
[screen
].pixel
);
127 if (l
== fs
->max_levels
) {
129 if (fs
->total_points
> MAXTOTAL
) /* how long each fractal runs */
132 if (x
> -1.0 && x
< 1.0 && y
> -1.0 && y
< 1.0) {
133 fs
->pts
[fs
->num_points
].x
= (short) ((fs
->width
/ 2) * (x
+ 1.0));
134 fs
->pts
[fs
->num_points
].y
= (short) ((fs
->height
/ 2) * (y
+ 1.0));
136 if (fs
->num_points
> MAXBATCH
) { /* point buffer size */
137 XDrawPoints(dsp
, fs
->win
, Scr
[screen
].gc
, fs
->pts
,
138 fs
->num_points
, CoordModeOrigin
);
144 for (i
= 0; i
< fs
->SNUM
; i
++) {
146 nx
= fs
->f
[0][0][i
] * x
+ fs
->f
[0][1][i
] * y
+ fs
->f
[0][2][i
];
147 ny
= fs
->f
[1][0][i
] * x
+ fs
->f
[1][1][i
] * y
+ fs
->f
[1][2][i
];
152 if (!recurse(fs
, nx
, ny
, l
+ 1))
161 drawflame(Window win
)
163 flamestruct
*fs
= &flames
[screen
];
168 if (!(fs
->cur_level
++ % fs
->max_levels
)) {
169 XClearWindow(dsp
, fs
->win
);
172 if (Scr
[screen
].npixels
> 2) {
173 XSetForeground(dsp
, Scr
[screen
].gc
,
174 Scr
[screen
].pixels
[fs
->pixcol
]);
175 if (--fs
->pixcol
< 0)
176 fs
->pixcol
= Scr
[screen
].npixels
- 1;
180 /* number of functions */
181 fs
->SNUM
= 2 + (fs
->cur_level
% 3);
183 /* how many of them are of alternate form */
187 fs
->ANUM
= halfrandom(fs
->SNUM
) + 2;
189 /* 6 coefs per function */
190 for (k
= 0; k
< fs
->SNUM
; k
++) {
191 for (i
= 0; i
< 2; i
++)
192 for (j
= 0; j
< 3; j
++)
193 fs
->f
[i
][j
][k
] = ((double) (random() & 1023) / 512.0 - 1.0);
196 fs
->total_points
= 0;
197 (void) recurse(fs
, 0.0, 0.0, 0);
198 XDrawPoints(dsp
, win
, Scr
[screen
].gc
,
199 fs
->pts
, fs
->num_points
, CoordModeOrigin
);