summaryrefslogtreecommitdiff
path: root/src/post/goom/ifs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/post/goom/ifs.c')
-rw-r--r--src/post/goom/ifs.c414
1 files changed, 217 insertions, 197 deletions
diff --git a/src/post/goom/ifs.c b/src/post/goom/ifs.c
index 72330f4a3..c7e843d09 100644
--- a/src/post/goom/ifs.c
+++ b/src/post/goom/ifs.c
@@ -33,7 +33,7 @@ static const char sccsid[] = "@(#)ifs.c 5.00 2002/04/11 baffe";
* that onto the screen, to reduce flicker.
*/
-/* #ifdef STANDALONE */
+/*#ifdef STANDALONE */
#include <math.h>
#include <stdlib.h>
@@ -55,28 +55,31 @@ static const char sccsid[] = "@(#)ifs.c 5.00 2002/04/11 baffe";
#define SMOOTH_COLORS
-/* #include "xlockmore.h" /\* in xscreensaver distribution *\/ */
-/* #else /\* STANDALONE *\/ */
-/* #include "xlock.h" /\* in xlockmore distribution *\/ */
-/* #endif /\* STANDALONE *\/ */
+/*#include "xlockmore.h" */ /* in xscreensaver distribution */
+/*#else */ /* STANDALONE */
+/*#include "xlock.h" */ /* in xlockmore distribution */
+/*#endif */ /* STANDALONE */
-/* #ifdef MODE_ifs */
+/*#ifdef MODE_ifs */
-/* ModeSpecOpt ifs_opts = */
-/* {0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL}; */
+/*ModeSpecOpt ifs_opts = */
+/*{0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL}; */
-/* #ifdef USE_MODULES */
-/* ModStruct ifs_description = */
-/* {"ifs", "init_ifs", "draw_ifs", "release_ifs", */
-/* "init_ifs", "init_ifs", (char *) NULL, &ifs_opts, */
-/* 1000, 1, 1, 1, 64, 1.0, "", */
-/* "Shows a modified iterated function system", 0, NULL}; */
+/*#ifdef USE_MODULES */
+/*ModStruct ifs_description = */
+/*{"ifs", "init_ifs", "draw_ifs", "release_ifs", */
+/* "init_ifs", "init_ifs", (char *) NULL, &ifs_opts, */
+/* 1000, 1, 1, 1, 64, 1.0, "", */
+/* "Shows a modified iterated function system", 0, NULL}; */
-/* #endif */
+/*#endif */
-#define LRAND() ((long) (rand() & 0x7fffffff))
+#include "goom_tools.h"
+
+#define LRAND() ((long) (RAND() & 0x7fffffff))
#define NRAND(n) ((int) (LRAND() % (n)))
-#define MAXRAND (2147483648.0) /* unsigned 1<<31 as a float */
+#define MAXRAND (2147483648.0) /* unsigned 1<<31 as a * *
+ * * float */
/*****************************************************/
@@ -91,226 +94,238 @@ typedef int F_PT;
#define UNIT ( 1<<FIX )
#define MAX_SIMI 6
-/* settings for a PC 120Mhz... */
+#define MAX_DEPTH_2 10
+#define MAX_DEPTH_3 6
+#define MAX_DEPTH_4 4
+#define MAX_DEPTH_5 2
+
+/* PREVIOUS VALUE
+#define MAX_SIMI 6
+
+* settings for a PC 120Mhz... *
#define MAX_DEPTH_2 10
#define MAX_DEPTH_3 6
#define MAX_DEPTH_4 4
#define MAX_DEPTH_5 3
+*/
#define DBL_To_F_PT(x) (F_PT)( (DBL)(UNIT)*(x) )
typedef struct Similitude_Struct SIMI;
typedef struct Fractal_Struct FRACTAL;
-struct Similitude_Struct {
+struct Similitude_Struct
+{
- DBL c_x, c_y;
- DBL r, r2, A, A2;
- F_PT Ct, St, Ct2, St2;
- F_PT Cx, Cy;
- F_PT R, R2;
+ DBL c_x, c_y;
+ DBL r, r2, A, A2;
+ F_PT Ct, St, Ct2, St2;
+ F_PT Cx, Cy;
+ F_PT R, R2;
};
-struct Fractal_Struct {
-
- int Nb_Simi;
- SIMI Components[5 * MAX_SIMI];
- int Depth, Col;
- int Count, Speed;
- int Width, Height, Lx, Ly;
- DBL r_mean, dr_mean, dr2_mean;
- int Cur_Pt, Max_Pt;
+struct Fractal_Struct
+{
- IFSPoint *Buffer1, *Buffer2;
-/* Pixmap dbuf; */
-/* GC dbuf_gc; */
+ int Nb_Simi;
+ SIMI Components[5 * MAX_SIMI];
+ int Depth, Col;
+ int Count, Speed;
+ int Width, Height, Lx, Ly;
+ DBL r_mean, dr_mean, dr2_mean;
+ int Cur_Pt, Max_Pt;
+
+ IFSPoint *Buffer1, *Buffer2;
+/* Pixmap dbuf; */
+/* GC dbuf_gc; */
};
static FRACTAL *Root = (FRACTAL *) NULL, *Cur_F;
/* Used by the Trace recursive method */
IFSPoint *Buf;
-static int Cur_Pt;
+static int Cur_Pt;
/*****************************************************/
-static DBL
-Gauss_Rand(DBL c, DBL A, DBL S)
+static DBL
+Gauss_Rand (DBL c, DBL A, DBL S)
{
- DBL y;
+ DBL y;
- y = (DBL) LRAND() / MAXRAND;
- y = A * (1.0 - exp(-y * y * S)) / (1.0 - exp(-S));
- if (NRAND(2))
+ y = (DBL) LRAND () / MAXRAND;
+ y = A * (1.0 - exp (-y * y * S)) / (1.0 - exp (-S));
+ if (NRAND (2))
return (c + y);
return (c - y);
}
-static DBL
-Half_Gauss_Rand(DBL c, DBL A, DBL S)
+static DBL
+Half_Gauss_Rand (DBL c, DBL A, DBL S)
{
- DBL y;
+ DBL y;
- y = (DBL) LRAND() / MAXRAND;
- y = A * (1.0 - exp(-y * y * S)) / (1.0 - exp(-S));
+ y = (DBL) LRAND () / MAXRAND;
+ y = A * (1.0 - exp (-y * y * S)) / (1.0 - exp (-S));
return (c + y);
}
static void
-Random_Simis(FRACTAL * F, SIMI * Cur, int i)
+Random_Simis (FRACTAL * F, SIMI * Cur, int i)
{
while (i--) {
- Cur->c_x = Gauss_Rand(0.0, .8, 4.0);
- Cur->c_y = Gauss_Rand(0.0, .8, 4.0);
- Cur->r = Gauss_Rand(F->r_mean, F->dr_mean, 3.0);
- Cur->r2 = Half_Gauss_Rand(0.0, F->dr2_mean, 2.0);
- Cur->A = Gauss_Rand(0.0, 360.0, 4.0) * (M_PI / 180.0);
- Cur->A2 = Gauss_Rand(0.0, 360.0, 4.0) * (M_PI / 180.0);
+ Cur->c_x = Gauss_Rand (0.0, .8, 4.0);
+ Cur->c_y = Gauss_Rand (0.0, .8, 4.0);
+ Cur->r = Gauss_Rand (F->r_mean, F->dr_mean, 3.0);
+ Cur->r2 = Half_Gauss_Rand (0.0, F->dr2_mean, 2.0);
+ Cur->A = Gauss_Rand (0.0, 360.0, 4.0) * (M_PI / 180.0);
+ Cur->A2 = Gauss_Rand (0.0, 360.0, 4.0) * (M_PI / 180.0);
Cur++;
}
}
static void
-free_ifs_buffers(FRACTAL *Fractal)
+free_ifs_buffers (FRACTAL * Fractal)
{
if (Fractal->Buffer1 != NULL) {
- (void) free((void *) Fractal->Buffer1);
+ (void) free ((void *) Fractal->Buffer1);
Fractal->Buffer1 = (IFSPoint *) NULL;
}
if (Fractal->Buffer2 != NULL) {
- (void) free((void *) Fractal->Buffer2);
+ (void) free ((void *) Fractal->Buffer2);
Fractal->Buffer2 = (IFSPoint *) NULL;
}
}
static void
-free_ifs(FRACTAL *Fractal)
+free_ifs (FRACTAL * Fractal)
{
- free_ifs_buffers(Fractal);
+ free_ifs_buffers (Fractal);
}
/***************************************************************/
void
-init_ifs(int width, int height)
+init_ifs (int width, int height)
{
- int i;
- FRACTAL *Fractal;
+ int i;
+ FRACTAL *Fractal;
-/* printf ("initing ifs\n"); */
+/* printf ("initing ifs\n"); */
if (Root == NULL) {
- Root = (FRACTAL *) malloc(sizeof(FRACTAL));
- if (Root == NULL)
- return;
- Root->Buffer1 = (IFSPoint*)NULL;
- Root->Buffer2 = (IFSPoint*)NULL;
+ Root = (FRACTAL *) malloc (sizeof (FRACTAL));
+ if (Root == NULL)
+ return;
+ Root->Buffer1 = (IFSPoint *) NULL;
+ Root->Buffer2 = (IFSPoint *) NULL;
}
Fractal = Root;
-/* fprintf (stderr,"--ifs freeing ex-buffers\n"); */
- free_ifs_buffers(Fractal);
-/* fprintf (stderr,"--ifs ok\n"); */
+/* fprintf (stderr,"--ifs freeing ex-buffers\n"); */
+ free_ifs_buffers (Fractal);
+/* fprintf (stderr,"--ifs ok\n"); */
- i = (NRAND(4)) + 2; /* Number of centers */
+ i = (NRAND (4)) + 2; /* Number of centers */
switch (i) {
- case 3:
- Fractal->Depth = MAX_DEPTH_3;
- Fractal->r_mean = .6;
- Fractal->dr_mean = .4;
- Fractal->dr2_mean = .3;
- break;
-
- case 4:
- Fractal->Depth = MAX_DEPTH_4;
- Fractal->r_mean = .5;
- Fractal->dr_mean = .4;
- Fractal->dr2_mean = .3;
- break;
-
- case 5:
- Fractal->Depth = MAX_DEPTH_5;
- Fractal->r_mean = .5;
- Fractal->dr_mean = .4;
- Fractal->dr2_mean = .3;
- break;
-
- default:
- case 2:
- Fractal->Depth = MAX_DEPTH_2;
- Fractal->r_mean = .7;
- Fractal->dr_mean = .3;
- Fractal->dr2_mean = .4;
- break;
+ case 3:
+ Fractal->Depth = MAX_DEPTH_3;
+ Fractal->r_mean = .6;
+ Fractal->dr_mean = .4;
+ Fractal->dr2_mean = .3;
+ break;
+
+ case 4:
+ Fractal->Depth = MAX_DEPTH_4;
+ Fractal->r_mean = .5;
+ Fractal->dr_mean = .4;
+ Fractal->dr2_mean = .3;
+ break;
+
+ case 5:
+ Fractal->Depth = MAX_DEPTH_5;
+ Fractal->r_mean = .5;
+ Fractal->dr_mean = .4;
+ Fractal->dr2_mean = .3;
+ break;
+
+ default:
+ case 2:
+ Fractal->Depth = MAX_DEPTH_2;
+ Fractal->r_mean = .7;
+ Fractal->dr_mean = .3;
+ Fractal->dr2_mean = .4;
+ break;
}
-/* fprintf( stderr, "N=%d\n", i ); */
+/* fprintf( stderr, "N=%d\n", i ); */
Fractal->Nb_Simi = i;
Fractal->Max_Pt = Fractal->Nb_Simi - 1;
for (i = 0; i <= Fractal->Depth + 2; ++i)
Fractal->Max_Pt *= Fractal->Nb_Simi;
- if ((Fractal->Buffer1 = (IFSPoint *) calloc(Fractal->Max_Pt,
- sizeof (IFSPoint))) == NULL) {
- free_ifs(Fractal);
- return;
+ if ((Fractal->Buffer1 = (IFSPoint *) calloc (Fractal->Max_Pt,
+ sizeof (IFSPoint))) == NULL) {
+ free_ifs (Fractal);
+ return;
}
- if ((Fractal->Buffer2 = (IFSPoint *) calloc(Fractal->Max_Pt,
- sizeof (IFSPoint))) == NULL) {
- free_ifs(Fractal);
- return;
+ if ((Fractal->Buffer2 = (IFSPoint *) calloc (Fractal->Max_Pt,
+ sizeof (IFSPoint))) == NULL) {
+ free_ifs (Fractal);
+ return;
}
-
-/* printf ("--ifs setting params\n"); */
+
+/* printf ("--ifs setting params\n"); */
Fractal->Speed = 6;
- Fractal->Width = width; /* modif by JeKo */
- Fractal->Height = height; /* modif by JeKo */
+ Fractal->Width = width; /* modif by JeKo */
+ Fractal->Height = height; /* modif by JeKo */
Fractal->Cur_Pt = 0;
Fractal->Count = 0;
Fractal->Lx = (Fractal->Width - 1) / 2;
Fractal->Ly = (Fractal->Height - 1) / 2;
- Fractal->Col = rand() % (width * height); /* modif by JeKo */
-
- Random_Simis(Fractal, Fractal->Components, 5 * MAX_SIMI);
-
- /*
- #ifndef NO_DBUF
- if (Fractal->dbuf != None)
- XFreePixmap(display, Fractal->dbuf);
- Fractal->dbuf = XCreatePixmap(display, window,
- Fractal->Width, Fractal->Height, 1);
- /* Allocation checked *
- if (Fractal->dbuf != None) {
- XGCValues gcv;
-
- gcv.foreground = 0;
- gcv.background = 0;
- gcv.graphics_exposures = False;
- gcv.function = GXcopy;
-
- if (Fractal->dbuf_gc != None)
- XFreeGC(display, Fractal->dbuf_gc);
- if ((Fractal->dbuf_gc = XCreateGC(display, Fractal->dbuf,
- GCForeground | GCBackground | GCGraphicsExposures | GCFunction,
- &gcv)) == None) {
- XFreePixmap(display, Fractal->dbuf);
- Fractal->dbuf = None;
- } else {
- XFillRectangle(display, Fractal->dbuf,
- Fractal->dbuf_gc, 0, 0, Fractal->Width, Fractal->Height);
- XSetBackground(display, gc, MI_BLACK_PIXEL(mi));
- XSetFunction(display, gc, GXcopy);
- }
- }
- #endif
- */
- /* MI_CLEARWINDOW(mi); */
+ Fractal->Col = rand () % (width * height); /* modif by JeKo */
+
+ Random_Simis (Fractal, Fractal->Components, 5 * MAX_SIMI);
+
+ /*
+ * #ifndef NO_DBUF
+ * if (Fractal->dbuf != None)
+ * XFreePixmap(display, Fractal->dbuf);
+ * Fractal->dbuf = XCreatePixmap(display, window,
+ * Fractal->Width, Fractal->Height, 1);
+ */
+ /* Allocation checked */
+ /* if (Fractal->dbuf != None) {
+ * XGCValues gcv;
+ *
+ * gcv.foreground = 0;
+ * gcv.background = 0;
+ * gcv.graphics_exposures = False;
+ * gcv.function = GXcopy;
+ *
+ * if (Fractal->dbuf_gc != None)
+ * XFreeGC(display, Fractal->dbuf_gc);
+ * if ((Fractal->dbuf_gc = XCreateGC(display, Fractal->dbuf,
+ * GCForeground | GCBackground | GCGraphicsExposures | GCFunction,
+ * &gcv)) == None) {
+ * XFreePixmap(display, Fractal->dbuf);
+ * Fractal->dbuf = None;
+ * } else {
+ * XFillRectangle(display, Fractal->dbuf,
+ * Fractal->dbuf_gc, 0, 0, Fractal->Width, Fractal->Height);
+ * XSetBackground(display, gc, MI_BLACK_PIXEL(mi));
+ * XSetFunction(display, gc, GXcopy);
+ * }
+ * }
+ * #endif
+ */
+ /* MI_CLEARWINDOW(mi); */
/* don't want any exposure events from XCopyPlane */
- /* XSetGraphicsExposures(display, gc, False); */
-
+ /* XSetGraphicsExposures(display, gc, False); */
+
}
@@ -319,12 +334,12 @@ init_ifs(int width, int height)
/* Should be taken care of already... but just in case */
#if !defined( __GNUC__ ) && !defined(__cplusplus) && !defined(c_plusplus)
#undef inline
-#define inline /* */
+#define inline /* */
#endif
static inline void
-Transform(SIMI * Simi, F_PT xo, F_PT yo, F_PT * x, F_PT * y)
+Transform (SIMI * Simi, F_PT xo, F_PT yo, F_PT * x, F_PT * y)
{
- F_PT xx, yy;
+ F_PT xx, yy;
xo = xo - Simi->Cx;
xo = (xo * Simi->R) / UNIT;
@@ -336,21 +351,25 @@ Transform(SIMI * Simi, F_PT xo, F_PT yo, F_PT * x, F_PT * y)
yy = -yo - Simi->Cy;
yy = (yy * Simi->R2) / UNIT;
- *x = ((xo * Simi->Ct - yo * Simi->St + xx * Simi->Ct2 - yy * Simi->St2) / UNIT) + Simi->Cx;
- *y = ((xo * Simi->St + yo * Simi->Ct + xx * Simi->St2 + yy * Simi->Ct2) / UNIT) + Simi->Cy;
+ *x =
+ ((xo * Simi->Ct - yo * Simi->St + xx * Simi->Ct2 - yy * Simi->St2) /
+ UNIT) + Simi->Cx;
+ *y =
+ ((xo * Simi->St + yo * Simi->Ct + xx * Simi->St2 + yy * Simi->Ct2) /
+ UNIT) + Simi->Cy;
}
/***************************************************************/
static void
-Trace(FRACTAL * F, F_PT xo, F_PT yo)
+Trace (FRACTAL * F, F_PT xo, F_PT yo)
{
- F_PT x, y, i;
- SIMI *Cur;
+ F_PT x, y, i;
+ SIMI *Cur;
Cur = Cur_F->Components;
for (i = Cur_F->Nb_Simi; i; --i, Cur++) {
- Transform(Cur, xo, yo, &x, &y);
+ Transform (Cur, xo, yo, &x, &y);
Buf->x = F->Lx + (x * F->Lx / (UNIT * 2));
Buf->y = F->Ly - (y * F->Ly / (UNIT * 2));
@@ -360,31 +379,31 @@ Trace(FRACTAL * F, F_PT xo, F_PT yo)
if (F->Depth && ((x - xo) >> 4) && ((y - yo) >> 4)) {
F->Depth--;
- Trace(F, x, y);
+ Trace (F, x, y);
F->Depth++;
}
}
}
static void
-Draw_Fractal(/*ModeInfo * mi*/)
+Draw_Fractal ( /* ModeInfo * mi */ )
{
- FRACTAL *F = Root;
- int i, j;
- F_PT x, y, xo, yo;
- SIMI *Cur, *Simi;
+ FRACTAL *F = Root;
+ int i, j;
+ F_PT x, y, xo, yo;
+ SIMI *Cur, *Simi;
for (Cur = F->Components, i = F->Nb_Simi; i; --i, Cur++) {
- Cur->Cx = DBL_To_F_PT(Cur->c_x);
- Cur->Cy = DBL_To_F_PT(Cur->c_y);
+ Cur->Cx = DBL_To_F_PT (Cur->c_x);
+ Cur->Cy = DBL_To_F_PT (Cur->c_y);
- Cur->Ct = DBL_To_F_PT(cos(Cur->A));
- Cur->St = DBL_To_F_PT(sin(Cur->A));
- Cur->Ct2 = DBL_To_F_PT(cos(Cur->A2));
- Cur->St2 = DBL_To_F_PT(sin(Cur->A2));
+ Cur->Ct = DBL_To_F_PT (cos (Cur->A));
+ Cur->St = DBL_To_F_PT (sin (Cur->A));
+ Cur->Ct2 = DBL_To_F_PT (cos (Cur->A2));
+ Cur->St2 = DBL_To_F_PT (sin (Cur->A2));
- Cur->R = DBL_To_F_PT(Cur->r);
- Cur->R2 = DBL_To_F_PT(Cur->r2);
+ Cur->R = DBL_To_F_PT (Cur->r);
+ Cur->R2 = DBL_To_F_PT (Cur->r2);
}
@@ -397,8 +416,8 @@ Draw_Fractal(/*ModeInfo * mi*/)
for (Simi = F->Components, j = F->Nb_Simi; j; --j, Simi++) {
if (Simi == Cur)
continue;
- Transform(Simi, xo, yo, &x, &y);
- Trace(F, x, y);
+ Transform (Simi, xo, yo, &x, &y);
+ Trace (F, x, y);
}
}
@@ -409,8 +428,8 @@ Draw_Fractal(/*ModeInfo * mi*/)
if (F->dbuf != None) {
XSetForeground(display, F->dbuf_gc, 0);
*/
- /* XDrawPoints(display, F->dbuf, F->dbuf_gc, F->Buffer1, F->Cur_Pt,
- CoordModeOrigin); */
+ /* XDrawPoints(display, F->dbuf, F->dbuf_gc, F->Buffer1, F->Cur_Pt, * * * *
+ * CoordModeOrigin); */
/* XFillRectangle(display, F->dbuf, F->dbuf_gc, 0, 0,
F->Width, F->Height);
} else
@@ -440,18 +459,18 @@ Draw_Fractal(/*ModeInfo * mi*/)
IFSPoint *
-draw_ifs(/*ModeInfo * mi*/ int *nbpt)
+draw_ifs ( /* ModeInfo * mi */ int *nbpt)
{
- int i;
- DBL u, uu, v, vv, u0, u1, u2, u3;
- SIMI *S, *S1, *S2, *S3, *S4;
- FRACTAL *F;
+ int i;
+ DBL u, uu, v, vv, u0, u1, u2, u3;
+ SIMI *S, *S1, *S2, *S3, *S4;
+ FRACTAL *F;
if (Root == NULL)
- return NULL;
- F = Root; /* [/\*MI_SCREEN(mi)*\/0]; */
+ return;
+ F = Root; /* [ */ /*MI_SCREEN(mi)*/ /* 0]; */
if (F->Buffer1 == NULL)
- return NULL;
+ return;
u = (DBL) (F->Count) * (DBL) (F->Speed) / 1000.0;
uu = u * u;
@@ -479,7 +498,7 @@ draw_ifs(/*ModeInfo * mi*/ int *nbpt)
/* MI_IS_DRAWN(mi) = True; */
- Draw_Fractal(/*mi*/);
+ Draw_Fractal ( /* mi */ );
if (F->Count >= 1000 / F->Speed) {
S = F->Components;
@@ -498,12 +517,13 @@ draw_ifs(/*ModeInfo * mi*/ int *nbpt)
*S1 = *S4;
}
- Random_Simis(F, F->Components + 3 * F->Nb_Simi, F->Nb_Simi);
+ Random_Simis (F, F->Components + 3 * F->Nb_Simi, F->Nb_Simi);
- Random_Simis(F, F->Components + 4 * F->Nb_Simi, F->Nb_Simi);
+ Random_Simis (F, F->Components + 4 * F->Nb_Simi, F->Nb_Simi);
F->Count = 0;
- } else
+ }
+ else
F->Count++;
F->Col++;
@@ -518,12 +538,12 @@ draw_ifs(/*ModeInfo * mi*/ int *nbpt)
/***************************************************************/
void
-release_ifs()
+release_ifs ()
{
- if (Root != NULL) {
- (void) free((void *) Root);
- Root = (FRACTAL *) NULL;
- }
+ if (Root != NULL) {
+ (void) free ((void *) Root);
+ Root = (FRACTAL *) NULL;
+ }
}
-/* #endif /\* MODE_ifs *\/ */
+/*#endif */ /* MODE_ifs */