-/* noof, Copyright (c) 2004 Mark Kilgard <mjk@nvidia.com>
+/* noof, Copyright (c) 2004 Bill Torzewski <billt@worksitez.com>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* implied warranty.
*
* Originally a demo included with GLUT;
+ * (Apparently this was called "diatoms" on Irix.)
* ported to raw GL and xscreensaver by jwz, 12-Feb-2004.
*/
-#include <X11/Intrinsic.h>
-
-extern XtAppContext app;
-
-#define PROGCLASS "Noof"
-#define HACK_INIT init_noof
-#define HACK_DRAW draw_noof
-#define HACK_RESHAPE reshape_noof
-#define noof_opts xlockmore_opts
-
#define DEFAULTS "*delay: 10000 \n" \
"*showFPS: False \n" \
"*fpsSolid: True \n" \
+# define refresh_noof 0
+# define release_noof 0
+# define noof_handle_event 0
#include "xlockmore.h"
#ifdef USE_GL /* whole file */
+#define N_SHAPES 7
+
+ENTRYPOINT ModeSpecOpt noof_opts = {0, NULL, 0, NULL, NULL};
+
typedef struct {
GLXContext *glx_context;
+
+ float pos[N_SHAPES * 3];
+ float dir[N_SHAPES * 3];
+ float acc[N_SHAPES * 3];
+ float col[N_SHAPES * 3];
+ float hsv[N_SHAPES * 3];
+ float hpr[N_SHAPES * 3];
+ float ang[N_SHAPES];
+ float spn[N_SHAPES];
+ float sca[N_SHAPES];
+ float geep[N_SHAPES];
+ float peep[N_SHAPES];
+ float speedsq[N_SHAPES];
+ int blad[N_SHAPES];
+
+ float ht, wd;
+
+ int tko;
+
} noof_configuration;
static noof_configuration *bps = NULL;
-ModeSpecOpt noof_opts = {0, NULL, 0, NULL, NULL};
-/* --- shape parameters def'n --- */
-#define N_SHAPES 7
-static float pos[N_SHAPES * 3];
-static float dir[N_SHAPES * 3];
-static float acc[N_SHAPES * 3];
-static float col[N_SHAPES * 3];
-static float hsv[N_SHAPES * 3];
-static float hpr[N_SHAPES * 3];
-static float ang[N_SHAPES];
-static float spn[N_SHAPES];
-static float sca[N_SHAPES];
-static float geep[N_SHAPES];
-static float peep[N_SHAPES];
-static float speedsq[N_SHAPES];
-static int blad[N_SHAPES];
-
-static float ht, wd;
-
static void
-initshapes(int i)
+initshapes(noof_configuration *bp, int i)
{
int k;
float f;
/* random init of pos, dir, color */
for (k = i * 3; k <= i * 3 + 2; k++) {
- f = random() / 2147483647.0;
- pos[k] = f;
- f = random() / 2147483647.0;
+ f = random() / (double) RAND_MAX;
+ bp->pos[k] = f;
+ f = random() / (double) RAND_MAX;
f = (f - 0.5) * 0.05;
- dir[k] = f;
- f = random() / 2147483647.0;
+ bp->dir[k] = f;
+ f = random() / (double) RAND_MAX;
f = (f - 0.5) * 0.0002;
- acc[k] = f;
- f = random() / 2147483647.0;
- col[k] = f;
+ bp->acc[k] = f;
+ f = random() / (double) RAND_MAX;
+ bp->col[k] = f;
}
- speedsq[i] = dir[i * 3] * dir[i * 3] + dir[i * 3 + 1] * dir[i * 3 + 1];
- f = random() / 2147483647.0;
- blad[i] = 2 + (int) (f * 17.0);
- f = random() / 2147483647.0;
- ang[i] = f;
- f = random() / 2147483647.0;
- spn[i] = (f - 0.5) * 40.0 / (10 + blad[i]);
- f = random() / 2147483647.0;
- sca[i] = (f * 0.1 + 0.08);
- dir[i * 3] *= sca[i];
- dir[i * 3 + 1] *= sca[i];
-
- f = random() / 2147483647.0;
- hsv[i * 3] = f * 360.0;
-
- f = random() / 2147483647.0;
- hsv[i * 3 + 1] = f * 0.6 + 0.4;
-
- f = random() / 2147483647.0;
- hsv[i * 3 + 2] = f * 0.7 + 0.3;
-
- f = random() / 2147483647.0;
- hpr[i * 3] = f * 0.005 * 360.0;
- f = random() / 2147483647.0;
- hpr[i * 3 + 1] = f * 0.03;
- f = random() / 2147483647.0;
- hpr[i * 3 + 2] = f * 0.02;
-
- geep[i] = 0;
- f = random() / 2147483647.0;
- peep[i] = 0.01 + f * 0.2;
+ bp->speedsq[i] = bp->dir[i * 3] * bp->dir[i * 3] + bp->dir[i * 3 + 1] * bp->dir[i * 3 + 1];
+ f = random() / (double) RAND_MAX;
+ bp->blad[i] = 2 + (int) (f * 17.0);
+ f = random() / (double) RAND_MAX;
+ bp->ang[i] = f;
+ f = random() / (double) RAND_MAX;
+ bp->spn[i] = (f - 0.5) * 40.0 / (10 + bp->blad[i]);
+ f = random() / (double) RAND_MAX;
+ bp->sca[i] = (f * 0.1 + 0.08);
+ bp->dir[i * 3] *= bp->sca[i];
+ bp->dir[i * 3 + 1] *= bp->sca[i];
+
+ f = random() / (double) RAND_MAX;
+ bp->hsv[i * 3] = f * 360.0;
+
+ f = random() / (double) RAND_MAX;
+ bp->hsv[i * 3 + 1] = f * 0.6 + 0.4;
+
+ f = random() / (double) RAND_MAX;
+ bp->hsv[i * 3 + 2] = f * 0.7 + 0.3;
+
+ f = random() / (double) RAND_MAX;
+ bp->hpr[i * 3] = f * 0.005 * 360.0;
+ f = random() / (double) RAND_MAX;
+ bp->hpr[i * 3 + 1] = f * 0.03;
+ f = random() / (double) RAND_MAX;
+ bp->hpr[i * 3 + 2] = f * 0.02;
+
+ bp->geep[i] = 0;
+ f = random() / (double) RAND_MAX;
+ bp->peep[i] = 0.01 + f * 0.2;
}
-static int tko = 0;
-
-static float bladeratio[] =
+static const float bladeratio[] =
{
/* nblades = 2..7 */
0.0, 0.0, 3.00000, 1.73205, 1.00000, 0.72654, 0.57735, 0.48157,
};
static void
-drawleaf(int l)
+drawleaf(noof_configuration *bp, int l)
{
int b, blades;
float x, y;
float wobble;
- blades = blad[l];
+ blades = bp->blad[l];
- y = 0.10 * sin(geep[l] * M_PI / 180.0) + 0.099 * sin(geep[l] * 5.12 * M_PI / 180.0);
+ y = 0.10 * sin(bp->geep[l] * M_PI / 180.0) + 0.099 * sin(bp->geep[l] * 5.12 * M_PI / 180.0);
if (y < 0)
y = -y;
- x = 0.15 * cos(geep[l] * M_PI / 180.0) + 0.149 * cos(geep[l] * 5.12 * M_PI / 180.0);
+ x = 0.15 * cos(bp->geep[l] * M_PI / 180.0) + 0.149 * cos(bp->geep[l] * 5.12 * M_PI / 180.0);
if (x < 0.0)
x = 0.0 - x;
- if (y < 0.001 && x > 0.000002 && ((tko & 0x1) == 0)) {
- initshapes(l); /* let it become reborn as something
+ if (y < 0.001 && x > 0.000002 && ((bp->tko & 0x1) == 0)) {
+ initshapes(bp, l); /* let it become reborn as something
else */
- tko++;
+ bp->tko++;
return;
} {
- float w1 = sin(geep[l] * 15.3 * M_PI / 180.0);
- wobble = 3.0 + 2.00 * sin(geep[l] * 0.4 * M_PI / 180.0) + 3.94261 * w1;
+ float w1 = sin(bp->geep[l] * 15.3 * M_PI / 180.0);
+ wobble = 3.0 + 2.00 * sin(bp->geep[l] * 0.4 * M_PI / 180.0) + 3.94261 * w1;
}
/**
for (b = 0; b < blades; b++) {
glPushMatrix();
- glTranslatef(pos[l * 3], pos[l * 3 + 1], pos[l * 3 + 2]);
- glRotatef(ang[l] + b * (360.0 / blades), 0.0, 0.0, 1.0);
- glScalef(wobble * sca[l], wobble * sca[l], wobble * sca[l]);
+ glTranslatef(bp->pos[l * 3], bp->pos[l * 3 + 1], bp->pos[l * 3 + 2]);
+ glRotatef(bp->ang[l] + b * (360.0 / blades), 0.0, 0.0, 1.0);
+ glScalef(wobble * bp->sca[l], wobble * bp->sca[l], wobble * bp->sca[l]);
/**
if(tko & 0x40000) glColor3f(col[l*3], col[l*3+1], col[l*3+2]);
else
glEnable(GL_BLEND);
glBegin(GL_TRIANGLE_STRIP);
- glVertex2f(x * sca[l], 0.0);
+ glVertex2f(x * bp->sca[l], 0.0);
glVertex2f(x, y);
glVertex2f(x, -y); /* C */
glVertex2f(0.3, 0.0); /* D */
if(tko++ & 0x40000) glColor3f(0,0,0);
else
*/
- glColor3f(col[l * 3], col[l * 3 + 1], col[l * 3 + 2]);
+ glColor3f(bp->col[l * 3], bp->col[l * 3 + 1], bp->col[l * 3 + 2]);
glBegin(GL_LINE_LOOP);
- glVertex2f(x * sca[l], 0.0);
+ glVertex2f(x * bp->sca[l], 0.0);
glVertex2f(x, y);
glVertex2f(0.3, 0.0); /* D */
glVertex2f(x, -y); /* C */
}
static void
-motionUpdate(int t)
+motionUpdate(noof_configuration *bp, int t)
{
- if (pos[t * 3] < -sca[t] * wd && dir[t * 3] < 0.0) {
- dir[t * 3] = -dir[t * 3];
+ if (bp->pos[t * 3] < -bp->sca[t] * bp->wd && bp->dir[t * 3] < 0.0) {
+ bp->dir[t * 3] = -bp->dir[t * 3];
/**
acc[t*3+1] += 0.8*acc[t*3];
acc[t*3] = -0.8*acc[t*3];
*/
- } else if (pos[t * 3] > (1 + sca[t]) * wd && dir[t * 3] > 0.0) {
- dir[t * 3] = -dir[t * 3];
+ } else if (bp->pos[t * 3] > (1 + bp->sca[t]) * bp->wd && bp->dir[t * 3] > 0.0) {
+ bp->dir[t * 3] = -bp->dir[t * 3];
/**
acc[t*3+1] += 0.8*acc[t*3];
acc[t*3] = -0.8*acc[t*3];
*/
- } else if (pos[t * 3 + 1] < -sca[t] * ht && dir[t * 3 + 1] < 0.0) {
- dir[t * 3 + 1] = -dir[t * 3 + 1];
+ } else if (bp->pos[t * 3 + 1] < -bp->sca[t] * bp->ht && bp->dir[t * 3 + 1] < 0.0) {
+ bp->dir[t * 3 + 1] = -bp->dir[t * 3 + 1];
/**
acc[t*3] += 0.8*acc[t*3+1];
acc[t*3+1] = -0.8*acc[t*3+1];
*/
- } else if (pos[t * 3 + 1] > (1 + sca[t]) * ht && dir[t * 3 + 1] > 0.0) {
- dir[t * 3 + 1] = -dir[t * 3 + 1];
+ } else if (bp->pos[t * 3 + 1] > (1 + bp->sca[t]) * bp->ht && bp->dir[t * 3 + 1] > 0.0) {
+ bp->dir[t * 3 + 1] = -bp->dir[t * 3 + 1];
/**
acc[t*3] += 0.8*acc[t*3+1];
acc[t*3+1] = -0.8*acc[t*3+1];
*/
}
- pos[t * 3] += dir[t * 3];
- pos[t * 3 + 1] += dir[t * 3 + 1];
+ bp->pos[t * 3] += bp->dir[t * 3];
+ bp->pos[t * 3 + 1] += bp->dir[t * 3 + 1];
/**
dir[t*3] += acc[t*3];
dir[t*3+1] += acc[t*3+1];
*/
- ang[t] += spn[t];
- geep[t] += peep[t];
- if (geep[t] > 360 * 5.0)
- geep[t] -= 360 * 5.0;
- if (ang[t] < 0.0) {
- ang[t] += 360.0;
+ bp->ang[t] += bp->spn[t];
+ bp->geep[t] += bp->peep[t];
+ if (bp->geep[t] > 360 * 5.0)
+ bp->geep[t] -= 360 * 5.0;
+ if (bp->ang[t] < 0.0) {
+ bp->ang[t] += 360.0;
}
- if (ang[t] > 360.0) {
- ang[t] -= 360.0;
+ if (bp->ang[t] > 360.0) {
+ bp->ang[t] -= 360.0;
}
}
static void
-colorUpdate(int i)
+colorUpdate(noof_configuration *bp, int i)
{
- if (hsv[i * 3 + 1] <= 0.5 && hpr[i * 3 + 1] < 0.0)
- hpr[i * 3 + 1] = -hpr[i * 3 + 1]; /* adjust s */
- if (hsv[i * 3 + 1] >= 1.0 && hpr[i * 3 + 1] > 0.0)
- hpr[i * 3 + 1] = -hpr[i * 3 + 1]; /* adjust s */
- if (hsv[i * 3 + 2] <= 0.4 && hpr[i * 3 + 2] < 0.0)
- hpr[i * 3 + 2] = -hpr[i * 3 + 2]; /* adjust s */
- if (hsv[i * 3 + 2] >= 1.0 && hpr[i * 3 + 2] > 0.0)
- hpr[i * 3 + 2] = -hpr[i * 3 + 2]; /* adjust s */
-
- hsv[i * 3] += hpr[i * 3];
- hsv[i * 3 + 1] += hpr[i * 3 + 1];
- hsv[i * 3 + 2] += hpr[i * 3 + 2];
+ if (bp->hsv[i * 3 + 1] <= 0.5 && bp->hpr[i * 3 + 1] < 0.0)
+ bp->hpr[i * 3 + 1] = -bp->hpr[i * 3 + 1]; /* adjust s */
+ if (bp->hsv[i * 3 + 1] >= 1.0 && bp->hpr[i * 3 + 1] > 0.0)
+ bp->hpr[i * 3 + 1] = -bp->hpr[i * 3 + 1]; /* adjust s */
+ if (bp->hsv[i * 3 + 2] <= 0.4 && bp->hpr[i * 3 + 2] < 0.0)
+ bp->hpr[i * 3 + 2] = -bp->hpr[i * 3 + 2]; /* adjust s */
+ if (bp->hsv[i * 3 + 2] >= 1.0 && bp->hpr[i * 3 + 2] > 0.0)
+ bp->hpr[i * 3 + 2] = -bp->hpr[i * 3 + 2]; /* adjust s */
+
+ bp->hsv[i * 3] += bp->hpr[i * 3];
+ bp->hsv[i * 3 + 1] += bp->hpr[i * 3 + 1];
+ bp->hsv[i * 3 + 2] += bp->hpr[i * 3 + 2];
/* --- hsv -> rgb --- */
#define H(hhh) hhh[i*3 ]
#define G(hhh) hhh[i*3+1]
#define B(hhh) hhh[i*3+2]
- if (V(hsv) < 0.0)
- V(hsv) = 0.0;
- if (V(hsv) > 1.0)
- V(hsv) = 1.0;
- if (S(hsv) <= 0.0) {
- R(col) = V(hsv);
- G(col) = V(hsv);
- B(col) = V(hsv);
+ if (V(bp->hsv) < 0.0)
+ V(bp->hsv) = 0.0;
+ if (V(bp->hsv) > 1.0)
+ V(bp->hsv) = 1.0;
+ if (S(bp->hsv) <= 0.0) {
+ R(bp->col) = V(bp->hsv);
+ G(bp->col) = V(bp->hsv);
+ B(bp->col) = V(bp->hsv);
} else {
float f, h, p, q, t, v;
int hi;
- while (H(hsv) < 0.0)
- H(hsv) += 360.0;
- while (H(hsv) >= 360.0)
- H(hsv) -= 360.0;
+ while (H(bp->hsv) < 0.0)
+ H(bp->hsv) += 360.0;
+ while (H(bp->hsv) >= 360.0)
+ H(bp->hsv) -= 360.0;
- if (S(hsv) < 0.0)
- S(hsv) = 0.0;
- if (S(hsv) > 1.0)
- S(hsv) = 1.0;
+ if (S(bp->hsv) < 0.0)
+ S(bp->hsv) = 0.0;
+ if (S(bp->hsv) > 1.0)
+ S(bp->hsv) = 1.0;
- h = H(hsv) / 60.0;
+ h = H(bp->hsv) / 60.0;
hi = (int) (h);
f = h - hi;
- v = V(hsv);
- p = V(hsv) * (1 - S(hsv));
- q = V(hsv) * (1 - S(hsv) * f);
- t = V(hsv) * (1 - S(hsv) * (1 - f));
+ v = V(bp->hsv);
+ p = V(bp->hsv) * (1 - S(bp->hsv));
+ q = V(bp->hsv) * (1 - S(bp->hsv) * f);
+ t = V(bp->hsv) * (1 - S(bp->hsv) * (1 - f));
if (hi <= 0) {
- R(col) = v;
- G(col) = t;
- B(col) = p;
+ R(bp->col) = v;
+ G(bp->col) = t;
+ B(bp->col) = p;
} else if (hi == 1) {
- R(col) = q;
- G(col) = v;
- B(col) = p;
+ R(bp->col) = q;
+ G(bp->col) = v;
+ B(bp->col) = p;
} else if (hi == 2) {
- R(col) = p;
- G(col) = v;
- B(col) = t;
+ R(bp->col) = p;
+ G(bp->col) = v;
+ B(bp->col) = t;
} else if (hi == 3) {
- R(col) = p;
- G(col) = q;
- B(col) = v;
+ R(bp->col) = p;
+ G(bp->col) = q;
+ B(bp->col) = v;
} else if (hi == 4) {
- R(col) = t;
- G(col) = p;
- B(col) = v;
+ R(bp->col) = t;
+ G(bp->col) = p;
+ B(bp->col) = v;
} else {
- R(col) = v;
- G(col) = p;
- B(col) = q;
+ R(bp->col) = v;
+ G(bp->col) = p;
+ B(bp->col) = q;
}
}
}
static void
-gravity(float fx)
+gravity(noof_configuration *bp, float fx)
{
int a, b;
for (b = 0; b < a; b++) {
float t, d2;
- t = pos[b * 3] - pos[a * 3];
+ t = bp->pos[b * 3] - bp->pos[a * 3];
d2 = t * t;
- t = pos[b * 3 + 1] - pos[a * 3 + 1];
+ t = bp->pos[b * 3 + 1] - bp->pos[a * 3 + 1];
d2 += t * t;
if (d2 < 0.000001)
d2 = 0.00001;
if (d2 < 0.1) {
float v0, v1, z;
- v0 = pos[b * 3] - pos[a * 3];
- v1 = pos[b * 3 + 1] - pos[a * 3 + 1];
+ v0 = bp->pos[b * 3] - bp->pos[a * 3];
+ v1 = bp->pos[b * 3 + 1] - bp->pos[a * 3 + 1];
z = 0.00000001 * fx / (d2);
- dir[a * 3] += v0 * z * sca[b];
- dir[b * 3] += -v0 * z * sca[a];
- dir[a * 3 + 1] += v1 * z * sca[b];
- dir[b * 3 + 1] += -v1 * z * sca[a];
+ bp->dir[a * 3] += v0 * z * bp->sca[b];
+ bp->dir[b * 3] += -v0 * z * bp->sca[a];
+ bp->dir[a * 3 + 1] += v1 * z * bp->sca[b];
+ bp->dir[b * 3 + 1] += -v1 * z * bp->sca[a];
}
}
}
}
-void
+ENTRYPOINT void
draw_noof (ModeInfo *mi)
{
int i;
+ noof_configuration *bp = &bps[MI_SCREEN(mi)];
+
+ if (!bp->glx_context)
+ return;
+ glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context));
/**
if((random() & 0xff) == 0x34){
}
*/
- gravity(-2.0);
+ gravity(bp, -2.0);
for (i = 0; i < N_SHAPES; i++) {
- motionUpdate(i);
- colorUpdate(i);
- drawleaf(i);
+ motionUpdate(bp, i);
+ colorUpdate(bp, i);
+ drawleaf(bp, i);
}
if (mi->fps_p) do_fps (mi);
}
-void
+ENTRYPOINT void
reshape_noof(ModeInfo *mi, int w, int h)
{
+ noof_configuration *bp = &bps[MI_SCREEN(mi)];
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h) {
- wd = 1.0;
- ht = (GLfloat) h / (GLfloat) w;
+ bp->wd = 1.0;
+ bp->ht = (GLfloat) h / (GLfloat) w;
glOrtho(0.0, 1.0,
0.0, 1.0 * (GLfloat) h / (GLfloat) w,
-16.0, 4.0);
} else {
- wd = (GLfloat) w / (GLfloat) h;
- ht = 1.0;
+ bp->wd = (GLfloat) w / (GLfloat) h;
+ bp->ht = 1.0;
glOrtho(0.0, 1.0 * (GLfloat) w / (GLfloat) h,
0.0, 1.0,
-16.0, 4.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
-void
+ENTRYPOINT void
init_noof (ModeInfo *mi)
{
int i;
glShadeModel(GL_FLAT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
for (i = 0; i < N_SHAPES; i++)
- initshapes(i);
+ initshapes(bp, i);
reshape_noof (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
}
+XSCREENSAVER_MODULE ("Noof", noof)
+
#endif /* USE_GL */