1 /* -*- Mode: C; tab-width: 4 -*-
2 * vines --- another geometric pattern generator.
4 #if !defined( lint ) && !defined( SABER )
5 static const char sccsid[] = "@(#)vines.c 4.02 97/04/01 xlockmore";
8 /* xlockmore mode written by Tracy Camp
9 * campt@hurrah.com 1997
10 * released to the public domain
12 * This was modifed from a 'screen saver' that a friend and I
13 * wrote on our TI-8x calculators in high school physics one day
14 * Basically another geometric pattern generator, this ones claim
15 * to fame is a pseudo-fractal looking vine like pattern that creates
16 * nifty whorls and loops.
19 * 10-May-97: jwz@jwz.org: turned into a standalone program.
20 * 21-Mar-97: David Hansen <dhansen@metapath.com>
21 * Updated mode to draw complete patterns on every
22 * iteration instead of growing the vine. Also made
23 * adjustments to randomization and changed variable
24 * names to make logic easier to follow.
28 # define PROGCLASS "Vines"
29 # define HACK_INIT init_vines
30 # define HACK_DRAW draw_vines
31 # define vines_opts xlockmore_opts
32 # define DEFAULTS "*delay: 200000 \n" \
34 "*eraseSpeed: 400 \n" \
36 # include "xlockmore.h" /* from the xscreensaver distribution */
38 #else /* !STANDALONE */
39 # include "xlock.h" /* from the xlockmore distribution */
40 #endif /* !STANDALONE */
42 ModeSpecOpt vines_opts = {
43 0, NULL, 0, NULL, NULL };
59 static vinestruct *vines = NULL;
62 refresh_vines(ModeInfo * mi)
67 init_vines(ModeInfo * mi)
69 Display *display = MI_DISPLAY(mi);
73 if ((vines = (vinestruct *) calloc(MI_NUM_SCREENS(mi), sizeof (vinestruct))) == NULL) {
77 fp = &vines[MI_SCREEN(mi)];
79 fp->iterations = 30 + NRAND(100);
81 XClearWindow(display, MI_WINDOW(mi));
85 draw_vines(ModeInfo * mi)
87 vinestruct *fp = &vines[MI_SCREEN(mi)];
88 Display *display = MI_DISPLAY(mi);
92 if (--(fp->iterations) == 0) {
94 erase_full_window(MI_DISPLAY(mi), MI_WINDOW(mi));
95 #endif /* STANDALONE */
99 fp->centerx = NRAND(MI_WIN_WIDTH(mi));
100 fp->centery = NRAND(MI_WIN_HEIGHT(mi));
102 fp->ang = 60 + NRAND(720);
103 fp->length = 100 + NRAND(3000);
104 fp->constant = fp->length * (10 + NRAND(10));
112 if (MI_NPIXELS(mi) > 2)
113 XSetForeground(display, gc, MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))));
115 XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
118 for (i = 0; i < fp->length; i++) {
119 XDrawLine(display, MI_WINDOW(mi), gc,
120 fp->centerx + (fp->x1 / fp->constant),
121 fp->centery - (fp->y1 / fp->constant),
122 fp->centerx + (fp->x2 / fp->constant),
123 fp->centery - (fp->y2 / fp->constant));
125 fp->a += (fp->ang * i);
130 fp->x2 += (int) (i * ((cos(fp->a) * 360) / (2 * M_PI)));
131 fp->y2 += (int) (i * ((sin(fp->a) * 360) / (2 * M_PI)));
136 release_vines(ModeInfo * mi)
139 (void) free((void *) vines);