1 /* -*- Mode: C; tab-width: 4 -*- */
2 /* thornbird --- continuously varying Thornbird set */
5 static const char sccsid[] = "@(#)thornbird.c 5.00 2000/11/01 xlockmore";
9 * Copyright (c) 1996 by Tim Auckland <tda10.geo@yahoo.com>
11 * Permission to use, copy, modify, and distribute this software and its
12 * documentation for any purpose and without fee is hereby granted,
13 * provided that the above copyright notice appear in all copies and that
14 * both that copyright notice and this permission notice appear in
15 * supporting documentation.
17 * This file is provided AS IS with no warranties of any kind. The author
18 * shall have no liability with respect to the infringement of copyrights,
19 * trade secrets or any patents by this file or any part thereof. In no
20 * event will the author be liable for any lost revenue or profits or
21 * other special, indirect and consequential damages.
23 * "thornbird" shows a view of the "Bird in a Thornbush" fractal,
24 * continuously varying the three free parameters.
27 * 01-Nov-2000: Allocation checks
28 * 04-Jun-1999: 3D tumble added by Tim Auckland
29 * 31-Jul-1997: Adapted from discrete.c Copyright (c) 1996 by Tim Auckland
33 # define MODE_thornbird
34 #define DEFAULTS "*delay: 10000 \n" \
38 "*fpsSolid: true \n" \
39 "*ignoreRotation: True \n" \
41 # define BRIGHT_COLORS
42 # define release_thornbird 0
43 # define thornbird_handle_event 0
44 # include "xlockmore.h" /* in xscreensaver distribution */
45 #else /* STANDALONE */
46 # include "xlock.h" /* in xlockmore distribution */
47 #endif /* STANDALONE */
51 ENTRYPOINT ModeSpecOpt thornbird_opts =
52 {0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
55 ModStruct thornbird_description =
56 {"thornbird", "init_thornbird", "draw_thornbird", (char *) NULL,
57 "refresh_thornbird", "init_thornbird", (char *) NULL, þbird_opts,
58 1000, 800, 16, 1, 64, 1.0, "",
59 "Shows an animated Bird in a Thorn Bush fractal map", 0, NULL};
63 #define balance_rand(v) ((LRAND()/MAXRAND*(v))-((v)/2)) /* random around 0 */
67 int maxy; /* max of the screen */
74 double j; /* thornbird parameters */
89 XPoint **pointBuffer; /* pointer for XDrawPoints */
92 static thornbirdstruct *thornbirds = (thornbirdstruct *) NULL;
95 free_thornbird(ModeInfo * mi)
97 thornbirdstruct *hp = þbirds[MI_SCREEN(mi)];
98 if (hp->pointBuffer != NULL) {
101 for (buffer = 0; buffer < hp->nbuffers; buffer++)
102 if (hp->pointBuffer[buffer] != NULL)
103 (void) free((void *) hp->pointBuffer[buffer]);
104 (void) free((void *) hp->pointBuffer);
105 hp->pointBuffer = (XPoint **) NULL;
110 init_thornbird (ModeInfo * mi)
114 MI_INIT (mi, thornbirds, free_thornbird);
115 hp = þbirds[MI_SCREEN(mi)];
118 hp->maxx = MI_WIDTH(mi);
119 hp->maxy = MI_HEIGHT(mi);
127 hp->nbuffers = MI_CYCLES(mi);
129 if (hp->pointBuffer == NULL)
130 if ((hp->pointBuffer = (XPoint **) calloc(MI_CYCLES(mi),
131 sizeof (XPoint *))) == NULL) {
136 if (hp->pointBuffer[0] == NULL)
137 if ((hp->pointBuffer[0] = (XPoint *) malloc(MI_COUNT(mi) *
138 sizeof (XPoint))) == NULL) {
143 /* select frequencies for parameter variation */
144 hp->liss.f1 = LRAND() % 5000;
145 hp->liss.f2 = LRAND() % 2000;
147 /* choose random 3D tumbling */
148 hp->tumble.theta = 0;
150 hp->tumble.dtheta = balance_rand(0.001);
151 hp->tumble.dphi = balance_rand(0.005);
153 /* Clear the background. */
161 draw_thornbird(ModeInfo * mi)
163 Display *dsp = MI_DISPLAY(mi);
164 Window win = MI_WINDOW(mi);
166 int batchcount = MI_COUNT(mi);
173 double sint, cost, sinp, cosp;
176 if (thornbirds == NULL)
178 hp = þbirds[MI_SCREEN(mi)];
179 if (hp->pointBuffer == NULL)
182 erase = (hp->inc + 1) % MI_CYCLES(mi);
183 current = hp->inc % MI_CYCLES(mi);
187 xp = hp->pointBuffer[current];
189 /* vary papameters */
190 hp->a = 1.99 + (0.4 * sin(hp->inc / hp->liss.f1) +
191 0.05 * cos(hp->inc / hp->liss.f2));
192 hp->c = 0.80 + (0.15 * cos(hp->inc / hp->liss.f1) +
193 0.05 * sin(hp->inc / hp->liss.f2));
196 hp->tumble.theta += hp->tumble.dtheta;
197 hp->tumble.phi += hp->tumble.dphi;
198 sint = sin(hp->tumble.theta);
199 cost = cos(hp->tumble.theta);
200 sinp = sin(hp->tumble.phi);
201 cosp = cos(hp->tumble.phi);
208 hp->i = (1 - hp->c) * cos(M_PI * hp->a * oldj) + hp->c * hp->b;
213 + sint*hp->j + cost*cosp*hp->i - cost*sinp*hp->b));
216 - cost*hp->j + sint*cosp*hp->i - sint*sinp*hp->b));
220 MI_IS_DRAWN(mi) = True;
222 if (MI_COUNT(mi) < 1) MI_COUNT(mi) = 1;
223 if (hp->pointBuffer[erase] == NULL) {
224 if ((hp->pointBuffer[erase] = (XPoint *) malloc(MI_COUNT(mi) *
225 sizeof (XPoint))) == NULL) {
230 XSetForeground(dsp, gc, MI_BLACK_PIXEL(mi));
231 XDrawPoints(dsp, win, gc, hp->pointBuffer[erase],
232 batchcount, CoordModeOrigin);
234 if (MI_NPIXELS(mi) > 2) {
235 XSetForeground(dsp, gc, MI_PIXEL(mi, hp->pix));
237 if (erase == 0) /* change colours after "cycles" cycles */
239 if (!((hp->inc + 1) % (1 + (MI_CYCLES(mi) / 3)))) /* jwz: sooner */
241 if (++hp->pix >= MI_NPIXELS(mi))
244 XSetForeground(dsp, gc, MI_WHITE_PIXEL(mi));
246 XDrawPoints(dsp, win, gc, hp->pointBuffer[current],
247 batchcount, CoordModeOrigin);
252 reshape_thornbird(ModeInfo * mi, int width, int height)
254 XClearWindow (MI_DISPLAY (mi), MI_WINDOW(mi));
259 refresh_thornbird (ModeInfo * mi)
265 XSCREENSAVER_MODULE ("Thornbird", thornbird)
267 #endif /* MODE_thornbird */