X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fvines.c;h=1abf29916de8add2071b45dbb50070ea4f798f76;hb=4361b69d3178d7fc98d0388f9a223af6c2651aba;hp=4c562f9d344811170efe55db40f374382269cfb3;hpb=ce3185de9d9705e259f2b60dd4b5509007fa17d4;p=xscreensaver diff --git a/hacks/vines.c b/hacks/vines.c index 4c562f9d..1abf2991 100644 --- a/hacks/vines.c +++ b/hacks/vines.c @@ -1,46 +1,76 @@ -/* -*- Mode: C; tab-width: 4 -*- - * vines --- another geometric pattern generator. - */ -#if !defined( lint ) && !defined( SABER ) -static const char sccsid[] = "@(#)vines.c 4.02 97/04/01 xlockmore"; +/* -*- Mode: C; tab-width: 4 -*- */ +/* vines --- vine fractals */ + +#if 0 +static const char sccsid[] = "@(#)vines.c 5.00 2000/11/01 xlockmore"; #endif -/* xlockmore mode written by Tracy Camp - * campt@hurrah.com 1997 - * released to the public domain +/*- + * Copyright (c) 1997 by Tracy Camp campt@hurrah.com + * + * Permission to use, copy, modify, and distribute this software and its + * documentation for any purpose and without fee is hereby granted, + * provided that the above copyright notice appear in all copies and that + * both that copyright notice and this permission notice appear in + * supporting documentation. + * + * This file is provided AS IS with no warranties of any kind. The author + * shall have no liability with respect to the infringement of copyrights, + * trade secrets or any patents by this file or any part thereof. In no + * event will the author be liable for any lost revenue or profits or + * other special, indirect and consequential damages. + * + * If you make a modification I would of course appreciate a copy. * + * Revision History: + * 01-Nov-2000: Allocation checks + * 11-Jul-1997: David Hansen + * Changed names to vines and modified draw loop + * to honor batchcount so vines can be grown or plotted. + * 10-May-1997: Compatible with xscreensaver + * 21-Mar-1997: David Hansen + * Updated mode to draw complete patterns on every + * iteration instead of growing the vine. Also made + * adjustments to randomization and changed variable + * names to make logic easier to follow. + */ + +/*- * This was modifed from a 'screen saver' that a friend and I * wrote on our TI-8x calculators in high school physics one day * Basically another geometric pattern generator, this ones claim * to fame is a pseudo-fractal looking vine like pattern that creates * nifty whorls and loops. - * - * Revision History: - * 10-May-97: jwz@jwz.org: turned into a standalone program. - * 21-Mar-97: David Hansen - * Updated mode to draw complete patterns on every - * iteration instead of growing the vine. Also made - * adjustments to randomization and changed variable - * names to make logic easier to follow. */ #ifdef STANDALONE -# define PROGCLASS "Vines" -# define HACK_INIT init_vines -# define HACK_DRAW draw_vines -# define vines_opts xlockmore_opts -# define DEFAULTS "*delay: 200000 \n" \ - "*ncolors: 64 \n" \ - "*eraseSpeed: 400 \n" \ - "*eraseMode: -1 \n" -# include "xlockmore.h" /* from the xscreensaver distribution */ +# define MODE_vines +# define DEFAULTS "*delay: 200000 \n" \ + "*count: 0 \n" \ + "*ncolors: 64 \n" \ + "*fpsSolid: true \n" \ + +# include "xlockmore.h" /* in xscreensaver distribution */ +# define reshape_vines 0 +# define vines_handle_event 0 # include "erase.h" -#else /* !STANDALONE */ -# include "xlock.h" /* from the xlockmore distribution */ -#endif /* !STANDALONE */ +#else /* STANDALONE */ +# include "xlock.h" /* in xlockmore distribution */ +#endif /* STANDALONE */ + +#ifdef MODE_vines + +ENTRYPOINT ModeSpecOpt vines_opts = +{0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL}; -ModeSpecOpt vines_opts = { - 0, NULL, 0, NULL, NULL }; +#ifdef USE_MODULES +ModStruct vines_description = +{"vines", "init_vines", "draw_vines", "release_vines", + "refresh_vines", "init_vines", (char *) NULL, &vines_opts, + 200000, 0, 1, 1, 64, 1.0, "", + "Shows fractals", 0, NULL}; + +#endif typedef struct { int a; @@ -48,95 +78,121 @@ typedef struct { int y1; int x2; int y2; + int i; int length; int iterations; int constant; int ang; int centerx; int centery; +#ifdef STANDALONE + eraser_state *eraser; +#endif } vinestruct; -static vinestruct *vines = NULL; +static vinestruct *vines = (vinestruct *) NULL; -void +ENTRYPOINT void refresh_vines(ModeInfo * mi) { -} + MI_CLEARWINDOW(mi); +} /* refresh_vines */ -void +ENTRYPOINT void init_vines(ModeInfo * mi) { - Display *display = MI_DISPLAY(mi); vinestruct *fp; - if (vines == NULL) { - if ((vines = (vinestruct *) calloc(MI_NUM_SCREENS(mi), sizeof (vinestruct))) == NULL) { - return; - } - } + MI_INIT (mi, vines, 0); fp = &vines[MI_SCREEN(mi)]; + fp->i = 0; + fp->length = 0; fp->iterations = 30 + NRAND(100); - XClearWindow(display, MI_WINDOW(mi)); -} +#ifndef STANDALONE + MI_CLEARWINDOW(mi); +#endif +} /* init_vines */ -void +ENTRYPOINT void draw_vines(ModeInfo * mi) { - vinestruct *fp = &vines[MI_SCREEN(mi)]; Display *display = MI_DISPLAY(mi); GC gc = MI_GC(mi); - int i; + int count; + vinestruct *fp; + + if (vines == NULL) + return; + fp = &vines[MI_SCREEN(mi)]; + +#ifdef STANDALONE + if (fp->eraser) { + fp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), fp->eraser); + return; + } +#endif - if (--(fp->iterations) == 0) { + /* MI_IS_DRAWN(mi) = True; */ + if (fp->i >= fp->length) { + if (--(fp->iterations) == 0) { #ifdef STANDALONE - erase_full_window(MI_DISPLAY(mi), MI_WINDOW(mi)); + fp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), fp->eraser); #endif /* STANDALONE */ - init_vines(mi); + init_vines(mi); + } + fp->centerx = NRAND(MI_WIDTH(mi)); + fp->centery = NRAND(MI_HEIGHT(mi)); + + fp->ang = 60 + NRAND(720); + fp->length = 100 + NRAND(3000); + fp->constant = fp->length * (10 + NRAND(10)); + + fp->i = 0; + fp->a = 0; + fp->x1 = 0; + fp->y1 = 0; + fp->x2 = 1; + fp->y2 = 0; + + if (MI_NPIXELS(mi) > 2) + XSetForeground(display, gc, MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)))); + else + XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); } + count = fp->i + MI_COUNT(mi); + if ((count <= fp->i) || (count > fp->length)) + count = fp->length; - fp->centerx = NRAND(MI_WIN_WIDTH(mi)); - fp->centery = NRAND(MI_WIN_HEIGHT(mi)); - - fp->ang = 60 + NRAND(720); - fp->length = 100 + NRAND(3000); - fp->constant = fp->length * (10 + NRAND(10)); - - fp->a = 0; - fp->x1 = 0; - fp->y1 = 0; - fp->x2 = 1; - fp->y2 = 0; - - if (MI_NPIXELS(mi) > 2) - XSetForeground(display, gc, MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)))); - else - XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi)); - - - for (i = 0; i < fp->length; i++) { + while (fp->i < count) { XDrawLine(display, MI_WINDOW(mi), gc, fp->centerx + (fp->x1 / fp->constant), fp->centery - (fp->y1 / fp->constant), fp->centerx + (fp->x2 / fp->constant), fp->centery - (fp->y2 / fp->constant)); - fp->a += (fp->ang * i); + fp->a += (fp->ang * fp->i); fp->x1 = fp->x2; fp->y1 = fp->y2; - fp->x2 += (int) (i * ((cos(fp->a) * 360) / (2 * M_PI))); - fp->y2 += (int) (i * ((sin(fp->a) * 360) / (2 * M_PI))); + fp->x2 += (int) (fp->i * (cos((double) fp->a) * 360.0) / (2.0 * M_PI)); + fp->y2 += (int) (fp->i * (sin((double) fp->a) * 360.0) / (2.0 * M_PI)); + fp->i++; } -} +} /* draw_vines */ -void +ENTRYPOINT void release_vines(ModeInfo * mi) { if (vines != NULL) { (void) free((void *) vines); - vines = NULL; + vines = (vinestruct *) NULL; } -} +} /* release_vines */ + + +XSCREENSAVER_MODULE ("Vines", vines) + +#endif /* MODE_vines */