/* -*- Mode: C; tab-width: 4 -*- */
/* apollonian --- Apollonian Circles */
-#if !defined( lint ) && !defined( SABER )
+#if 0
static const char sccsid[] = "@(#)apollonian.c 5.02 2001/07/01 xlockmore";
#endif
*/
#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
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
euclidean = 0, spherical, hyperbolic
};
-const char * space_string[] = {
+static const char * space_string[] = {
"euclidean",
"spherical",
"hyperbolic"
(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},
#endif
int time;
int game;
+#ifdef STANDALONE
+ eraser_state *eraser;
+#endif
} apollonianstruct;
static apollonianstruct *apollonians = (apollonianstruct *) NULL;
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;
#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);
}
#ifndef DEBUG
-void
+static void
randomize_c(int randomize, circle * c)
{
if (randomize / 2) {
}
#endif
-void
-init_apollonian(ModeInfo * mi)
+ENTRYPOINT void
+init_apollonian (ModeInfo * mi)
{
apollonianstruct *cp;
int i;
cquad(&(cp->c1), &(cp->c2), &(cp->c3), &(cp->c4));
}
cp->time = 0;
+#ifndef STANDALONE
MI_CLEARWINDOW(mi);
+#endif
if (cp->game != 0) {
double q123;
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;
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;
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;
}
}
+XSCREENSAVER_MODULE ("Apollonian", apollonian)
+
#endif /* MODE_apollonian */