X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fapollonian.c;h=72c0d002e55fe94d38092add108c93ad5afa664e;hb=6afd6db0ae9396cd7ff897ade597cd5483f49b0e;hp=0c1888acd4c834d5d84ae6f3a16a3ceec040f1ef;hpb=96a411663168b0ba5432b407a83be55f3df0c802;p=xscreensaver diff --git a/hacks/apollonian.c b/hacks/apollonian.c index 0c1888ac..72c0d002 100644 --- a/hacks/apollonian.c +++ b/hacks/apollonian.c @@ -65,19 +65,21 @@ static const char sccsid[] = "@(#)apollonian.c 5.02 2001/07/01 xlockmore"; */ #ifdef STANDALONE -#define MODE_apollonian -#define PROGCLASS "Apollonian" -#define HACK_INIT init_apollonian -#define HACK_DRAW draw_apollonian -#define apollonian_opts xlockmore_opts -#define DEFAULTS "*delay: 1000000 \n" \ - "*count: 64 \n" \ - "*cycles: 20 \n" \ - "*ncolors: 64 \n" -#include "xlockmore.h" /* in xscreensaver distribution */ -#include "erase.h" +# define MODE_apollonian +# define DEFAULTS "*delay: 1000000 \n" \ + "*count: 64 \n" \ + "*cycles: 20 \n" \ + "*ncolors: 64 \n" \ + "*font: fixed" "\n" \ + "*fpsTop: true \n" \ + "*fpsSolid: true \n" \ + "*ignoreRotation: True" \ + +# define refresh_apollonian 0 +# include "xlockmore.h" /* in xscreensaver distribution */ +# include "erase.h" #else /* STANDALONE */ -#include "xlock.h" /* in xlockmore distribution */ +# include "xlock.h" /* in xlockmore distribution */ #endif /* STANDALONE */ #ifdef MODE_apollonian @@ -90,23 +92,23 @@ static Bool label; static XrmOptionDescRec opts[] = { - {(char *) "-altgeom", (char *) ".apollonian.altgeom", XrmoptionNoArg, (caddr_t) "on"}, - {(char *) "+altgeom", (char *) ".apollonian.altgeom", XrmoptionNoArg, (caddr_t) "off"}, - {(char *) "-label", (char *) ".apollonian.label", XrmoptionNoArg, (caddr_t) "on"}, - {(char *) "+label", (char *) ".apollonian.label", XrmoptionNoArg, (caddr_t) "off"}, + {"-altgeom", ".apollonian.altgeom", XrmoptionNoArg, "on"}, + {"+altgeom", ".apollonian.altgeom", XrmoptionNoArg, "off"}, + {"-label", ".apollonian.label", XrmoptionNoArg, "on"}, + {"+label", ".apollonian.label", XrmoptionNoArg, "off"}, }; static argtype vars[] = { - {(caddr_t *) & altgeom, (char *) "altgeom", (char *) "AltGeom", (char *) DEF_ALTGEOM, t_Bool}, - {(caddr_t *) & label, (char *) "label", (char *) "Label", (char *) DEF_LABEL, t_Bool}, + {&altgeom, "altgeom", "AltGeom", DEF_ALTGEOM, t_Bool}, + {&label, "label", "Label", DEF_LABEL, t_Bool}, }; static OptionStruct desc[] = { - {(char *) "-/+altgeom", (char *) "turn on/off alternate geometries (off euclidean space, on includes spherical and hyperbolic)"}, - {(char *) "-/+label", (char *) "turn on/off alternate space and number labeling"}, + {"-/+altgeom", "turn on/off alternate geometries (off euclidean space, on includes spherical and hyperbolic)"}, + {"-/+label", "turn on/off alternate space and number labeling"}, }; -ModeSpecOpt apollonian_opts = +ENTRYPOINT ModeSpecOpt apollonian_opts = {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc}; #ifdef DOFONT @@ -136,7 +138,7 @@ enum space { euclidean = 0, spherical, hyperbolic }; -const char * space_string[] = { +static const char * space_string[] = { "euclidean", "spherical", "hyperbolic" @@ -159,7 +161,7 @@ the label in the standard picture) then the "spherical label" is (e^2+x^2+y^2-1)/(2*e) (an integer!) and the "hyperbolic label", is calulated by h + s = e. */ -circle examples[][4] = { +static circle examples[][4] = { { /* double semi-bounded */ { 0, 0, 0, 0, 1}, { 0, 0, 0, 0, -1}, @@ -296,6 +298,9 @@ typedef struct { #endif int time; int game; +#ifdef STANDALONE + eraser_state *eraser; +#endif } apollonianstruct; static apollonianstruct *apollonians = (apollonianstruct *) NULL; @@ -547,7 +552,7 @@ p(ModeInfo *mi, circle c) XDrawString(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi), ((int) (cp->size * c.x / (2.0 * c.e) + cp->offset.x)), ((int) (cp->size * c.y / (2.0 * c.e) + MI_HEIGHT(mi) - - FONT_HEIGHT / 2)), space_string[cp->geometry], + FONT_HEIGHT / 2)), (char *) space_string[cp->geometry], strlen(space_string[cp->geometry])); } return; @@ -608,28 +613,31 @@ p(ModeInfo *mi, circle c) #define BIG 7 static void -f(ModeInfo *mi, circle c1, circle c2, circle c3, circle c4) +f(ModeInfo *mi, circle c1, circle c2, circle c3, circle c4, int depth) { apollonianstruct *cp = &apollonians[MI_SCREEN(mi)]; int e = (int) ((cp->c1.e >= 0.0) ? 1.0 : -cp->c1.e); circle c; + if (depth > mi->recursion_depth) mi->recursion_depth = depth; + c.e = 2*(c1.e+c2.e+c3.e) - c4.e; c.s = 2*(c1.s+c2.s+c3.s) - c4.s; c.h = 2*(c1.h+c2.h+c3.h) - c4.h; c.x = 2*(c1.x+c2.x+c3.x) - c4.x; c.y = 2*(c1.y+c2.y+c3.y) - c4.y; - if (c.e > cp->size * e || c.x / c.e > BIG || c.y / c.e > BIG || + if (c.e == 0 || + c.e > cp->size * e || c.x / c.e > BIG || c.y / c.e > BIG || c.x / c.e < -BIG || c.y / c.e < -BIG) return; p(mi, c); - f(mi, c2, c3, c, c1); - f(mi, c1, c3, c, c2); - f(mi, c1, c2, c, c3); + f(mi, c2, c3, c, c1, depth+1); + f(mi, c1, c3, c, c2, depth+1); + f(mi, c1, c2, c, c3, depth+1); } -static void -free_apollonian(Display *display, apollonianstruct *cp) +ENTRYPOINT void +free_apollonian (Display *display, apollonianstruct *cp) { if (cp->quad != NULL) { (void) free((void *) cp->quad); @@ -648,7 +656,7 @@ free_apollonian(Display *display, apollonianstruct *cp) } #ifndef DEBUG -void +static void randomize_c(int randomize, circle * c) { if (randomize / 2) { @@ -665,8 +673,8 @@ randomize_c(int randomize, circle * c) } #endif -void -init_apollonian(ModeInfo * mi) +ENTRYPOINT void +init_apollonian (ModeInfo * mi) { apollonianstruct *cp; int i; @@ -720,7 +728,9 @@ init_apollonian(ModeInfo * mi) cquad(&(cp->c1), &(cp->c2), &(cp->c3), &(cp->c4)); } cp->time = 0; +#ifndef STANDALONE MI_CLEARWINDOW(mi); +#endif if (cp->game != 0) { double q123; @@ -760,10 +770,12 @@ init_apollonian(ModeInfo * mi) randomize_c(i, &(cp->c3)); randomize_c(i, &(cp->c4)); #endif + + mi->recursion_depth = -1; } -void -draw_apollonian(ModeInfo * mi) +ENTRYPOINT void +draw_apollonian (ModeInfo * mi) { apollonianstruct *cp; @@ -771,6 +783,12 @@ draw_apollonian(ModeInfo * mi) return; cp = &apollonians[MI_SCREEN(mi)]; +#ifdef STANDALONE + if (cp->eraser) { + cp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), cp->eraser); + return; + } +#endif MI_IS_DRAWN(mi) = True; @@ -783,29 +801,47 @@ draw_apollonian(ModeInfo * mi) p(mi, cp->c4); break; case 1: - f(mi, cp->c1, cp->c2, cp->c3, cp->c4); + f(mi, cp->c1, cp->c2, cp->c3, cp->c4, 0); break; case 2: - f(mi, cp->c1, cp->c2, cp->c4, cp->c3); + f(mi, cp->c1, cp->c2, cp->c4, cp->c3, 0); break; case 3: - f(mi, cp->c1, cp->c3, cp->c4, cp->c2); + f(mi, cp->c1, cp->c3, cp->c4, cp->c2, 0); break; case 4: - f(mi, cp->c2, cp->c3, cp->c4, cp->c1); + f(mi, cp->c2, cp->c3, cp->c4, cp->c1, 0); } } if (++cp->time > MI_CYCLES(mi)) { #ifdef STANDALONE - erase_full_window(MI_DISPLAY(mi), MI_WINDOW(mi)); + cp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), cp->eraser); #endif /* STANDALONE */ init_apollonian(mi); } } -void -release_apollonian(ModeInfo * mi) +ENTRYPOINT void +reshape_apollonian(ModeInfo * mi, int width, int height) +{ + XClearWindow (MI_DISPLAY (mi), MI_WINDOW(mi)); + init_apollonian (mi); +} + +ENTRYPOINT Bool +apollonian_handle_event (ModeInfo *mi, XEvent *event) +{ + if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event)) + { + reshape_apollonian (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); + return True; + } + return False; +} + +ENTRYPOINT void +release_apollonian (ModeInfo * mi) { if (apollonians != NULL) { int screen; @@ -817,4 +853,6 @@ release_apollonian(ModeInfo * mi) } } +XSCREENSAVER_MODULE ("Apollonian", apollonian) + #endif /* MODE_apollonian */