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" \
42 # define BRIGHT_COLORS
43 # define release_thornbird 0
44 # define reshape_thornbird 0
45 # define thornbird_handle_event 0
46 # include "xlockmore.h" /* in xscreensaver distribution */
47 #else /* STANDALONE */
48 # include "xlock.h" /* in xlockmore distribution */
49 #endif /* STANDALONE */
53 ENTRYPOINT ModeSpecOpt thornbird_opts =
54 {0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
57 ModStruct thornbird_description =
58 {"thornbird", "init_thornbird", "draw_thornbird", (char *) NULL,
59 "refresh_thornbird", "init_thornbird", "free_thornbird", þbird_opts,
60 1000, 800, 16, 1, 64, 1.0, "",
61 "Shows an animated Bird in a Thorn Bush fractal map", 0, NULL};
65 #define balance_rand(v) ((LRAND()/MAXRAND*(v))-((v)/2)) /* random around 0 */
69 int maxy; /* max of the screen */
76 double j; /* thornbird parameters */
91 XPoint **pointBuffer; /* pointer for XDrawPoints */
94 static thornbirdstruct *thornbirds = (thornbirdstruct *) NULL;
97 free_thornbird(ModeInfo * mi)
99 thornbirdstruct *hp = þbirds[MI_SCREEN(mi)];
100 if (hp->pointBuffer != NULL) {
103 for (buffer = 0; buffer < hp->nbuffers; buffer++)
104 if (hp->pointBuffer[buffer] != NULL)
105 (void) free((void *) hp->pointBuffer[buffer]);
106 (void) free((void *) hp->pointBuffer);
107 hp->pointBuffer = (XPoint **) NULL;
112 init_thornbird (ModeInfo * mi)
116 MI_INIT (mi, thornbirds);
117 hp = þbirds[MI_SCREEN(mi)];
120 hp->maxx = MI_WIDTH(mi);
121 hp->maxy = MI_HEIGHT(mi);
129 hp->nbuffers = MI_CYCLES(mi);
131 if (hp->pointBuffer == NULL)
132 if ((hp->pointBuffer = (XPoint **) calloc(MI_CYCLES(mi),
133 sizeof (XPoint *))) == NULL) {
138 if (hp->pointBuffer[0] == NULL)
139 if ((hp->pointBuffer[0] = (XPoint *) malloc(MI_COUNT(mi) *
140 sizeof (XPoint))) == NULL) {
145 /* select frequencies for parameter variation */
146 hp->liss.f1 = LRAND() % 5000;
147 hp->liss.f2 = LRAND() % 2000;
149 /* choose random 3D tumbling */
150 hp->tumble.theta = 0;
152 hp->tumble.dtheta = balance_rand(0.001);
153 hp->tumble.dphi = balance_rand(0.005);
155 /* Clear the background. */
163 draw_thornbird(ModeInfo * mi)
165 Display *dsp = MI_DISPLAY(mi);
166 Window win = MI_WINDOW(mi);
168 int batchcount = MI_COUNT(mi);
175 double sint, cost, sinp, cosp;
178 if (thornbirds == NULL)
180 hp = þbirds[MI_SCREEN(mi)];
181 if (hp->pointBuffer == NULL)
184 erase = (hp->inc + 1) % MI_CYCLES(mi);
185 current = hp->inc % MI_CYCLES(mi);
189 xp = hp->pointBuffer[current];
191 /* vary papameters */
192 hp->a = 1.99 + (0.4 * sin(hp->inc / hp->liss.f1) +
193 0.05 * cos(hp->inc / hp->liss.f2));
194 hp->c = 0.80 + (0.15 * cos(hp->inc / hp->liss.f1) +
195 0.05 * sin(hp->inc / hp->liss.f2));
198 hp->tumble.theta += hp->tumble.dtheta;
199 hp->tumble.phi += hp->tumble.dphi;
200 sint = sin(hp->tumble.theta);
201 cost = cos(hp->tumble.theta);
202 sinp = sin(hp->tumble.phi);
203 cosp = cos(hp->tumble.phi);
210 hp->i = (1 - hp->c) * cos(M_PI * hp->a * oldj) + hp->c * hp->b;
215 + sint*hp->j + cost*cosp*hp->i - cost*sinp*hp->b));
218 - cost*hp->j + sint*cosp*hp->i - sint*sinp*hp->b));
222 MI_IS_DRAWN(mi) = True;
224 if (MI_COUNT(mi) < 1) MI_COUNT(mi) = 1;
225 if (hp->pointBuffer[erase] == NULL) {
226 if ((hp->pointBuffer[erase] = (XPoint *) malloc(MI_COUNT(mi) *
227 sizeof (XPoint))) == NULL) {
232 XSetForeground(dsp, gc, MI_BLACK_PIXEL(mi));
233 XDrawPoints(dsp, win, gc, hp->pointBuffer[erase],
234 batchcount, CoordModeOrigin);
236 if (MI_NPIXELS(mi) > 2) {
237 XSetForeground(dsp, gc, MI_PIXEL(mi, hp->pix));
239 if (erase == 0) /* change colours after "cycles" cycles */
241 if (!((hp->inc + 1) % (1 + (MI_CYCLES(mi) / 3)))) /* jwz: sooner */
243 if (++hp->pix >= MI_NPIXELS(mi))
246 XSetForeground(dsp, gc, MI_WHITE_PIXEL(mi));
248 XDrawPoints(dsp, win, gc, hp->pointBuffer[current],
249 batchcount, CoordModeOrigin);
255 refresh_thornbird (ModeInfo * mi)
262 XSCREENSAVER_MODULE ("Thornbird", thornbird)
264 #endif /* MODE_thornbird */