1 /* -*- Mode: C; tab-width: 4 -*- */
2 /* vines --- vine fractals */
5 static const char sccsid[] = "@(#)vines.c 5.00 2000/11/01 xlockmore";
9 * Copyright (c) 1997 by Tracy Camp campt@hurrah.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 * If you make a modification I would of course appreciate a copy.
26 * 01-Nov-2000: Allocation checks
27 * 11-Jul-1997: David Hansen <dhansen@metapath.com>
28 * Changed names to vines and modified draw loop
29 * to honor batchcount so vines can be grown or plotted.
30 * 10-May-1997: Compatible with xscreensaver
31 * 21-Mar-1997: David Hansen <dhansen@metapath.com>
32 * Updated mode to draw complete patterns on every
33 * iteration instead of growing the vine. Also made
34 * adjustments to randomization and changed variable
35 * names to make logic easier to follow.
39 * This was modifed from a 'screen saver' that a friend and I
40 * wrote on our TI-8x calculators in high school physics one day
41 * Basically another geometric pattern generator, this ones claim
42 * to fame is a pseudo-fractal looking vine like pattern that creates
43 * nifty whorls and loops.
48 # define DEFAULTS "*delay: 200000 \n" \
51 # include "xlockmore.h" /* in xscreensaver distribution */
52 # define reshape_vines 0
53 # define vines_handle_event 0
55 #else /* STANDALONE */
56 # include "xlock.h" /* in xlockmore distribution */
57 #endif /* STANDALONE */
61 ENTRYPOINT ModeSpecOpt vines_opts =
62 {0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
65 ModStruct vines_description =
66 {"vines", "init_vines", "draw_vines", "release_vines",
67 "refresh_vines", "init_vines", (char *) NULL, &vines_opts,
68 200000, 0, 1, 1, 64, 1.0, "",
69 "Shows fractals", 0, NULL};
91 static vinestruct *vines = (vinestruct *) NULL;
94 refresh_vines(ModeInfo * mi)
100 init_vines(ModeInfo * mi)
105 if ((vines = (vinestruct *) calloc(MI_NUM_SCREENS(mi),
106 sizeof (vinestruct))) == NULL) {
110 fp = &vines[MI_SCREEN(mi)];
114 fp->iterations = 30 + NRAND(100);
122 draw_vines(ModeInfo * mi)
124 Display *display = MI_DISPLAY(mi);
131 fp = &vines[MI_SCREEN(mi)];
135 fp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), fp->eraser);
140 /* MI_IS_DRAWN(mi) = True; */
141 if (fp->i >= fp->length) {
142 if (--(fp->iterations) == 0) {
144 fp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), fp->eraser);
145 #endif /* STANDALONE */
148 fp->centerx = NRAND(MI_WIDTH(mi));
149 fp->centery = NRAND(MI_HEIGHT(mi));
151 fp->ang = 60 + NRAND(720);
152 fp->length = 100 + NRAND(3000);
153 fp->constant = fp->length * (10 + NRAND(10));
162 if (MI_NPIXELS(mi) > 2)
163 XSetForeground(display, gc, MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))));
165 XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
167 count = fp->i + MI_COUNT(mi);
168 if ((count <= fp->i) || (count > fp->length))
171 while (fp->i < count) {
172 XDrawLine(display, MI_WINDOW(mi), gc,
173 fp->centerx + (fp->x1 / fp->constant),
174 fp->centery - (fp->y1 / fp->constant),
175 fp->centerx + (fp->x2 / fp->constant),
176 fp->centery - (fp->y2 / fp->constant));
178 fp->a += (fp->ang * fp->i);
183 fp->x2 += (int) (fp->i * (cos((double) fp->a) * 360.0) / (2.0 * M_PI));
184 fp->y2 += (int) (fp->i * (sin((double) fp->a) * 360.0) / (2.0 * M_PI));
190 release_vines(ModeInfo * mi)
193 (void) free((void *) vines);
194 vines = (vinestruct *) NULL;
196 } /* release_vines */
199 XSCREENSAVER_MODULE ("Vines", vines)
201 #endif /* MODE_vines */