1
/* hypnowheel, Copyright (c) 2008 Jamie Zawinski <jwz@jwz.org>
3
* Permission to use, copy, modify, distribute, and sell this software and its
4
* documentation for any purpose is hereby granted without fee, provided that
5
* the above copyright notice appear in all copies and that both that
6
* copyright notice and this permission notice appear in supporting
7
* documentation. No representations are made about the suitability of this
8
* software for any purpose. It is provided "as is" without express or
11
* Draws overlapping spirals, where the tightness of the spirals changes.
16
* -twistiness 0.2 -layers 20
17
* -count 3 -layers 2 -speed 20 -twist 10 -wander
20
#define DEFAULTS "*delay: 20000 \n" \
22
"*showFPS: False \n" \
23
"*fpsSolid: True \n" \
24
"*wireframe: False \n" \
26
# define refresh_hypnowheel 0
27
# define release_hypnowheel 0
28
# define hypnowheel_handle_event 0
30
#define countof(x) (sizeof((x))/sizeof((*x)))
32
#include "xlockmore.h"
37
#ifdef USE_GL /* whole file */
40
#define DEF_WANDER "False"
41
#define DEF_SYMMETRIC "False"
42
#define DEF_SPEED "1.0"
43
#define DEF_TWISTINESS "4.0"
44
#define DEF_LAYERS "4"
54
GLXContext *glx_context;
60
} hypnowheel_configuration;
62
static hypnowheel_configuration *bps = NULL;
65
static GLfloat twistiness;
66
static GLfloat nlayers;
67
static Bool do_wander;
68
static Bool do_symmetric;
70
static XrmOptionDescRec opts[] = {
71
{ "-speed", ".speed", XrmoptionSepArg, 0 },
72
{ "-twistiness", ".twistiness", XrmoptionSepArg, 0 },
73
{ "-layers", ".layers", XrmoptionSepArg, 0 },
74
{ "-wander", ".wander", XrmoptionNoArg, "True" },
75
{ "+wander", ".wander", XrmoptionNoArg, "False" },
76
{ "-symmetric", ".symmetric", XrmoptionNoArg, "True" },
77
{ "+symmetric", ".symmetric", XrmoptionNoArg, "False" },
80
static argtype vars[] = {
81
{&do_wander, "wander", "Wander", DEF_WANDER, t_Bool},
82
{&do_symmetric, "symmetric", "Symmetric", DEF_SYMMETRIC, t_Bool},
83
{&speed, "speed", "Speed", DEF_SPEED, t_Float},
84
{&twistiness, "twistiness", "Twistiness", DEF_TWISTINESS, t_Float},
85
{&nlayers, "layers", "Layers", DEF_LAYERS, t_Float},
88
ENTRYPOINT ModeSpecOpt hypnowheel_opts = {
89
countof(opts), opts, countof(vars), vars, NULL};
93
draw_spiral (ModeInfo *mi, disc *d)
95
int wire = MI_IS_WIREFRAME(mi);
96
hypnowheel_configuration *bp = &bps[MI_SCREEN(mi)];
99
int steps = n * (wire ? 3 : (n < 5 ? 60 : n < 10 ? 20 : 10));
100
GLfloat dth = M_PI*2 / n;
101
GLfloat dr = rr / steps;
103
GLfloat twist = d->twist;
104
GLfloat dtwist = M_PI * 2 * twist / steps;
105
double cscale = 65536.0;
107
if (nlayers > 3 && !wire)
108
cscale *= (nlayers-2); /* don't wash out to white */
110
glColor4f (bp->colors[d->color].red / cscale,
111
bp->colors[d->color].green / cscale,
112
bp->colors[d->color].blue / cscale,
114
for (th = 0; th < M_PI*2; th += dth)
118
glBegin (wire ? GL_LINE_STRIP : GL_QUAD_STRIP);
119
for (r = 0; r <= rr; r += dr)
121
GLfloat th2 = th1 + dth/2 + dtwist;
123
glVertex3f (r * cos(th1), r * sin(th1), 0);
125
glVertex3f (r * cos(th2), r * sin(th2), 0);
134
/* Window management, etc
137
reshape_hypnowheel (ModeInfo *mi, int width, int height)
139
GLfloat h = (GLfloat) height / (GLfloat) width;
141
glViewport (0, 0, (GLint) width, (GLint) height);
143
glMatrixMode(GL_PROJECTION);
145
gluPerspective (30.0, 1/h, 1.0, 100.0);
147
glMatrixMode(GL_MODELVIEW);
149
gluLookAt( 0.0, 0.0, 30.0,
153
glClear(GL_COLOR_BUFFER_BIT);
158
init_hypnowheel (ModeInfo *mi)
160
hypnowheel_configuration *bp;
161
int wire = MI_IS_WIREFRAME(mi);
165
bps = (hypnowheel_configuration *)
166
calloc (MI_NUM_SCREENS(mi), sizeof (hypnowheel_configuration));
168
fprintf(stderr, "%s: out of memory\n", progname);
173
bp = &bps[MI_SCREEN(mi)];
175
bp->glx_context = init_GL(mi);
177
reshape_hypnowheel (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
179
bp->rot = make_rotator (0, 0, 0, 0, speed * 0.0025, False);
182
bp->colors = (XColor *) calloc(bp->ncolors, sizeof(XColor));
183
make_smooth_colormap (0, 0, 0,
184
bp->colors, &bp->ncolors,
187
if (MI_COUNT(mi) < 2) MI_COUNT(mi) = 2;
188
if (nlayers < 1) nlayers = 1;
189
bp->discs = (disc *) calloc (nlayers, sizeof (disc));
191
for (i = 0; i < nlayers; i++)
193
double spin_speed = speed * 0.2;
194
double wander_speed = speed * 0.0012;
195
double spin_accel = 0.2;
197
bp->discs[i].twist = 0;
198
bp->discs[i].alpha = 1;
199
bp->discs[i].color = i * bp->ncolors / nlayers;
201
spin_speed += frand (spin_speed / 5);
202
wander_speed += frand (wander_speed * 3);
204
bp->discs[i].rot = make_rotator (spin_speed, spin_speed, spin_speed,
206
(do_wander ? wander_speed : 0),
210
glDisable (GL_LIGHTING);
211
glDisable (GL_DEPTH_TEST);
212
glDepthMask (GL_FALSE);
213
glDisable (GL_CULL_FACE);
218
glBlendFunc (GL_ONE, GL_ONE);
224
draw_hypnowheel (ModeInfo *mi)
226
hypnowheel_configuration *bp = &bps[MI_SCREEN(mi)];
227
Display *dpy = MI_DISPLAY(mi);
228
Window window = MI_WINDOW(mi);
231
if (!bp->glx_context)
234
glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context));
236
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
242
get_position (bp->rot, &x, &y, &z, True);
243
glTranslatef((x - 0.5) * 8,
247
get_rotation (bp->rot, &x, &y, &z, True);
248
glRotatef (x * 360, 1.0, 0.0, 0.0);
249
glRotatef (y * 360, 0.0, 1.0, 0.0);
250
glRotatef (z * 360, 0.0, 0.0, 1.0);
253
mi->polygon_count = 0;
255
glScalef (45, 45, 45);
257
for (i = 0; i < nlayers; i++)
259
disc *d = &bp->discs[i];
261
rotator *rot = (do_symmetric ? bp->discs[(i & ~0x1)].rot : d->rot);
262
Bool tick = (!do_symmetric || i == 0);
267
if (d->color >= bp->ncolors)
270
get_position (rot, &x, &y, &z, tick);
276
glTranslatef (x, y, 0);
277
d->twist = (z * twistiness *
280
get_rotation (rot, &x, &y, &z, tick);
282
glRotatef (360 * z, 0, 0, 1); /* rotation of this disc */
284
draw_spiral (mi, &bp->discs[i]);
290
if (mi->fps_p) do_fps (mi);
293
glXSwapBuffers(dpy, window);
296
XSCREENSAVER_MODULE ("Hypnowheel", hypnowheel)