From http://www.jwz.org/xscreensaver/xscreensaver-5.30.tar.gz
[xscreensaver] / hacks / apollonian.c
index bc3fcc4e10b904b7c058a4c488425c3ed2bad0b1..72c0d002e55fe94d38092add108c93ad5afa664e 100644 (file)
@@ -69,10 +69,13 @@ static const char sccsid[] = "@(#)apollonian.c      5.02 2001/07/01 xlockmore";
 # define DEFAULTS      "*delay:   1000000 \n" \
                                        "*count:   64      \n" \
                                        "*cycles:  20      \n" \
-                                       "*ncolors: 64      \n"
+                                       "*ncolors: 64      \n" \
+                                       "*font:    fixed" "\n" \
+                                       "*fpsTop: true     \n" \
+                                       "*fpsSolid: true   \n" \
+                                       "*ignoreRotation: True" \
+
 # define refresh_apollonian 0
-# define reshape_apollonian 0
-# define apollonian_handle_event 0
 # include "xlockmore.h"                /* in xscreensaver distribution */
 # include "erase.h"
 #else /* STANDALONE */
@@ -610,24 +613,27 @@ 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);
 }
 
 ENTRYPOINT void
@@ -764,6 +770,8 @@ init_apollonian (ModeInfo * mi)
        randomize_c(i, &(cp->c3));
        randomize_c(i, &(cp->c4));
 #endif 
+
+    mi->recursion_depth = -1;
 }
 
 ENTRYPOINT void
@@ -793,16 +801,16 @@ 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))
@@ -814,6 +822,24 @@ draw_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)
 {