1 /* -*- Mode: C; tab-width: 4 -*- emacs friendly */
2 /* gflux - creates a fluctuating 3D grid
3 * requires OpenGL or MesaGL
5 * Copyright (c) Josiah Pease, 2000, 2003
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation. No representations are made about the suitability of this
11 * software for any purpose. It is provided "as is" without express or
14 * Thanks go to all those who worked on...
15 * MesaGL, OpenGL, UtahGLX, XFree86, gcc, vim, rxvt, the PNM (anymap) format
16 * xscreensaver and the thousands of other tools, apps and daemons that make
18 * Personal thanks to Kevin Moss, Paul Sheahee and Jamie Zawinski
20 * some xscreensaver code lifted from superquadrics. Most other glx hacks
21 * used as reference at some time.
23 * This hack and others can cause UtahGLX to crash my X server
24 * wireframe looks good with software only rendering anyway
25 * If anyone can work out why and supply a fix I'd love to hear from them
27 * Josiah Pease <gfluxcode@jpease.force9.co.uk> 21 July 2000
30 * 10 June 2000 : wireframe rippling grid standalone written
31 * 18 June 2000 : xscreensaver code added
32 * 25 June 2000 : solid and light added
33 * 04 July 2000 : majour bug hunt, xscreensaver code rewritten
34 * 08 July 2000 : texture mapping, rotation and zoom added
35 * 21 July 2000 : cleaned up code from bug hunts, manpage written
36 * 24 November 2000 : fixed x co-ord calculation in solid - textured
37 * 05 March 2001 : put back non pnmlib code with #ifdefs
38 * 11 May 2002 : fixed image problems with large images
43 #define DEFAULTS "*delay: 20000\n" \
47 "*suppressRotationAnimation: True\n" \
49 # define refresh_gflux 0
50 # include "xlockmore.h" /* from the xscreensaver distribution */
51 #else /* !STANDALONE */
52 # include "xlock.h" /* from the xlockmore distribution */
53 #endif /* !STANDALONE */
55 #ifdef USE_GL /* whole file */
59 # include <X11/Xmu/Drawing.h>
61 # include <Xmu/Drawing.h>
66 #define countof(x) (sizeof((x))/sizeof((*x)))
73 #include "grab-ximage.h"
74 #include "gltrackball.h"
77 static enum {wire=0,solid,light,checker,grab} _draw;
79 # define DEF_SQUARES "19"
80 # define DEF_RESOLUTION "4"
83 # define DEF_SPEED "0.05"
84 # define DEF_ROTATIONX "0.01"
85 # define DEF_ROTATIONY "0.0"
86 # define DEF_ROTATIONZ "0.1"
87 # define DEF_WAVES "3"
88 # define DEF_WAVE_CHANGE "50"
89 # define DEF_WAVE_HEIGHT "1.0"
90 # define DEF_WAVE_FREQ "3.0"
91 # define DEF_ZOOM "1.0"
95 static int _squares; /* grid size */
96 static int _resolution; /* wireframe resolution */
100 static float _rotationx;
101 static float _rotationy;
102 static float _rotationz;
106 static int _waveChange;
107 static float _waveHeight;
108 static float _waveFreq;
114 static XrmOptionDescRec opts[] = {
115 {"-squares", ".gflux.squares", XrmoptionSepArg, 0},
116 {"-resolution", ".gflux.resolution", XrmoptionSepArg, 0},
117 /* {"-draw", ".gflux.draw", XrmoptionSepArg, 0},*/
118 {"-mode", ".gflux.mode", XrmoptionSepArg, 0},
119 {"-wireframe", ".gflux.mode", XrmoptionNoArg, "wire"},
120 {"-flat", ".gflux.flat", XrmoptionSepArg, 0},
121 {"-speed", ".gflux.speed", XrmoptionSepArg, 0},
122 {"-rotationx", ".gflux.rotationx", XrmoptionSepArg, 0},
123 {"-rotationy", ".gflux.rotationy", XrmoptionSepArg, 0},
124 {"-rotationz", ".gflux.rotationz", XrmoptionSepArg, 0},
125 {"-waves", ".gflux.waves", XrmoptionSepArg, 0},
126 {"-waveChange", ".gflux.waveChange", XrmoptionSepArg, 0},
127 {"-waveHeight", ".gflux.waveHeight", XrmoptionSepArg, 0},
128 {"-waveFreq", ".gflux.waveFreq", XrmoptionSepArg, 0},
129 {"-zoom", ".gflux.zoom", XrmoptionSepArg, 0},
133 static argtype vars[] = {
134 {&_squares, "squares", "Squares", DEF_SQUARES, t_Int},
135 {&_resolution, "resolution", "Resolution", DEF_RESOLUTION, t_Int},
136 /* {&_draw, "draw", "Draw", DEF_DRAW, t_Int},*/
137 {&_flat, "flat", "Flat", DEF_FLAT, t_Int},
138 {&_speed, "speed", "Speed", DEF_SPEED, t_Float},
139 {&_rotationx, "rotationx", "Rotationx", DEF_ROTATIONX, t_Float},
140 {&_rotationy, "rotationy", "Rotationy", DEF_ROTATIONY, t_Float},
141 {&_rotationz, "rotationz", "Rotationz", DEF_ROTATIONZ, t_Float},
142 {&_waves, "waves", "Waves", DEF_WAVES, t_Int},
143 {&_waveChange, "waveChange", "WaveChange", DEF_WAVE_CHANGE, t_Int},
144 {&_waveHeight, "waveHeight", "WaveHeight", DEF_WAVE_HEIGHT, t_Float},
145 {&_waveFreq, "waveFreq", "WaveFreq", DEF_WAVE_FREQ, t_Float},
146 {&_zoom, "zoom", "Zoom", DEF_ZOOM, t_Float},
150 static OptionStruct desc[] =
152 {"-squares num", "size of grid in squares (19)"},
153 {"-resolution num", "detail of lines making grid, wireframe only (4)"},
154 /* {"-draw num", "draw method to use: 0=wireframe 1=solid 2=lit (0)"},*/
155 {"-flat num", "shading method, not wireframe: 0=smooth 1=flat (0)"},
156 {"-speed num", "speed of waves (0.05)"},
157 {"-rotationx num", "speed of xrotation (0.01)"},
158 {"-rotationy num", "speed of yrotation (0.00)"},
159 {"-rotationz num", "speed of zrotation (0.10)"},
160 {"-waves num", "number of simultanious waves (3)"},
161 {"-waveChange num", "number of cyles for a wave to change (50)"},
162 {"-waveHeight num", "height of waves (1.0)"},
163 {"-waveFreq num", "max frequency of a wave (3.0)"},
164 {"-zoom num", "camera control (1.0)"},
167 ENTRYPOINT ModeSpecOpt gflux_opts = {countof(opts), opts, countof(vars), vars, desc};
170 ModStruct gflux_description =
171 {"gflux", "init_gflux", "draw_gflux", "release_gflux",
172 "draw_gflux", "init_gflux", NULL, &gflux_opts,
173 1000, 1, 2, 1, 4, 1.0, "",
174 "GFlux: an OpenGL gflux", 0, NULL};
177 /* structure for holding the gflux data */
178 typedef struct gfluxstruct {
180 int screen_width, screen_height;
181 GLXContext *glx_context;
184 #define MAXWAVES 10 /* should be dynamic */
186 double freq[MAXWAVES];
187 double dispy[MAXWAVES];
188 double dispx[MAXWAVES];
194 int img_width, img_height;
195 int (*drawFunc)(struct gfluxstruct *);
197 trackball_state *trackball;
209 Bool waiting_for_image_p;
212 static gfluxstruct *gfluxes = NULL;
215 static void initLighting(void);
216 static void grabTexture(gfluxstruct *);
217 static void createTexture(gfluxstruct *);
218 static int displaySolid(gfluxstruct *); /* drawFunc implementations */
219 static int displayLight(gfluxstruct *);
220 static int displayTexture(gfluxstruct *);
221 static int displayWire(gfluxstruct *);
222 static void calcGrid(gfluxstruct *);
223 static double getGrid(gfluxstruct *,double,double,double);
225 /* as macro for speed */
226 /* could do with colour cycling here */
227 /* void genColour(double);*/
228 #define genColour(X) \
230 gp->colour[0] = 0.0;\
231 gp->colour[1] = 0.5+0.5*(X);\
232 gp->colour[2] = 0.5-0.5*(X);\
235 /* BEGINNING OF FUNCTIONS */
239 gflux_handle_event (ModeInfo *mi, XEvent *event)
241 gfluxstruct *gp = &gfluxes[MI_SCREEN(mi)];
243 if (gltrackball_event_handler (event, gp->trackball,
244 MI_WIDTH (mi), MI_HEIGHT (mi),
247 else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
260 userRot(gfluxstruct *gp)
262 gltrackball_rotate (gp->trackball);
265 /* draw the gflux once */
266 ENTRYPOINT void draw_gflux(ModeInfo * mi)
268 gfluxstruct *gp = &gfluxes[MI_SCREEN(mi)];
269 Display *display = MI_DISPLAY(mi);
270 Window window = MI_WINDOW(mi);
272 if (!gp->glx_context) return;
274 /* Just keep running before the texture has come in. */
275 /* if (gp->waiting_for_image_p) return; */
277 glXMakeCurrent(display, window, *(gp->glx_context));
280 mi->polygon_count = gp->drawFunc(gp);
281 if (mi->fps_p) do_fps (mi);
282 glXSwapBuffers(display, window);
286 /* Standard reshape function */
288 reshape_gflux(ModeInfo *mi, int width, int height)
290 glViewport( 0, 0, width, height );
291 glMatrixMode(GL_PROJECTION);
293 glFrustum(-_zoom,_zoom,-0.8*_zoom,0.8*_zoom,2,6);
294 glTranslatef(0.0,0.0,-4.0);
295 glMatrixMode(GL_MODELVIEW);
298 # ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */
300 GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
301 int o = (int) current_device_rotation();
302 if (o != 0 && o != 180 && o != -180)
303 glScalef (1/h, 1/h, 1/h);
309 /* main OpenGL initialization routine */
310 static void initializeGL(ModeInfo *mi, GLsizei width, GLsizei height)
312 gfluxstruct *gp = &gfluxes[MI_SCREEN(mi)];
314 reshape_gflux(mi, width, height);
315 glViewport( 0, 0, width, height );
317 gp->tex_xscale = 1.0; /* maybe changed later */
318 gp->tex_yscale = 1.0;
322 gp->drawFunc = (displaySolid);
323 glEnable(GL_DEPTH_TEST);
326 gp->drawFunc = (displayLight);
327 glEnable(GL_DEPTH_TEST);
331 gp->drawFunc = (displayTexture);
332 glEnable(GL_DEPTH_TEST);
337 gp->drawFunc = (displayTexture);
338 glEnable(GL_DEPTH_TEST);
344 gp->drawFunc = (displayWire);
345 glDisable(GL_DEPTH_TEST);
349 if(_flat) glShadeModel(GL_FLAT);
350 else glShadeModel(GL_SMOOTH);
355 /* xgflux initialization routine */
356 ENTRYPOINT void init_gflux(ModeInfo * mi)
358 int screen = MI_SCREEN(mi);
361 if (gfluxes == NULL) {
362 if ((gfluxes = (gfluxstruct *)
363 calloc(MI_NUM_SCREENS(mi), sizeof (gfluxstruct))) == NULL)
366 gp = &gfluxes[screen];
368 gp->trackball = gltrackball_init (True);
370 gp->time = frand(1000.0); /* don't run two screens in lockstep */
373 char *s = get_string_resource (mi->dpy, "mode", "Mode");
374 if (!s || !*s) _draw = grab;
375 else if (!strcasecmp (s, "wire")) _draw = wire;
376 else if (!strcasecmp (s, "solid")) _draw = solid;
377 else if (!strcasecmp (s, "light")) _draw = light;
378 else if (!strcasecmp (s, "checker")) _draw = checker;
379 else if (!strcasecmp (s, "grab")) _draw = grab;
383 "%s: mode must be one of: wire, solid, "
384 "light, checker, or grab; not \"%s\"\n",
391 gp->window = MI_WINDOW(mi);
392 if ((gp->glx_context = init_GL(mi)) != NULL) {
393 reshape_gflux(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
394 initializeGL(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
401 ENTRYPOINT void release_gflux(ModeInfo * mi)
403 if (gfluxes != NULL) {
404 free((void *) gfluxes);
411 static void createTexture(gfluxstruct *gp)
414 unsigned int data[] = { 0xFFFFFFFF, 0xAAAAAAAA, 0xFFFFFFFF, 0xAAAAAAAA,
415 0xAAAAAAAA, 0xFFFFFFFF, 0xAAAAAAAA, 0xFFFFFFFF,
416 0xFFFFFFFF, 0xAAAAAAAA, 0xFFFFFFFF, 0xAAAAAAAA,
417 0xAAAAAAAA, 0xFFFFFFFF, 0xAAAAAAAA, 0xFFFFFFFF };
419 gp->tex_xscale = size;
420 gp->tex_yscale = size;
422 glGenTextures (1, &gp->texName);
423 glBindTexture (GL_TEXTURE_2D, gp->texName);
425 glTexImage2D (GL_TEXTURE_2D, 0, 3, size, size, 0,
426 GL_RGBA, GL_UNSIGNED_BYTE, data);
428 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
429 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
431 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
432 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
437 image_loaded_cb (const char *filename, XRectangle *geometry,
438 int image_width, int image_height,
439 int texture_width, int texture_height,
442 gfluxstruct *gp = (gfluxstruct *) closure;
443 gp->img_geom = *geometry;
445 gp->tex_xscale = (GLfloat) image_width / texture_width;
446 gp->tex_yscale = -(GLfloat) image_height / texture_height;
447 gp->img_width = image_width;
448 gp->img_height = image_height;
450 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
451 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
452 (gp->mipmap_p ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR));
454 gp->waiting_for_image_p = False;
458 grabTexture(gfluxstruct *gp)
460 if (MI_IS_WIREFRAME(gp->modeinfo))
463 gp->waiting_for_image_p = True;
465 load_texture_async (gp->modeinfo->xgwa.screen, gp->modeinfo->window,
466 *gp->glx_context, 0, 0, gp->mipmap_p, gp->texName,
467 image_loaded_cb, gp);
471 static void initLighting(void)
473 static const float ambientA[] = {0.0, 0.0, 0.0, 1.0};
474 static const float diffuseA[] = {1.0, 1.0, 1.0, 1.0};
475 static const float positionA[] = {5.0, 5.0, 15.0, 1.0};
477 static const float front_mat_shininess[] = {30.0};
478 static const float front_mat_specular[] = {0.5, 0.5, 0.5, 1.0};
480 static const float mat_diffuse[] = {0.5, 0.5, 0.5, 1.0};
482 glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess);
483 glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular);
485 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
487 glLightfv(GL_LIGHT0, GL_AMBIENT, ambientA);
488 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseA);
489 glLightfv(GL_LIGHT0, GL_POSITION, positionA);
490 glEnable(GL_LIGHTING);
492 glLightModelf(GL_LIGHT_MODEL_TWO_SIDE,1);
494 glEnable(GL_NORMALIZE); /* would it be faster ... */
495 glEnable(GL_COLOR_MATERIAL);
496 glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
499 /************************************/
500 /* draw implementations */
501 /* somewhat inefficient since they */
502 /* all calculate previously */
503 /* calculated values again */
504 /* storing the values in an array */
505 /* is a posibility */
506 /************************************/
507 static int displayTexture(gfluxstruct *gp)
512 double dx = 2.0/((double)_squares);
513 double dy = 2.0/((double)_squares);
515 double du = 2.0/((double)_squares);
516 double dv = 2.0/((double)_squares);
518 double xs = gp->tex_xscale;
519 double ys = gp->tex_yscale;
521 double minx, miny, maxx, maxy;
525 minx = (GLfloat) gp->img_geom.x / gp->img_width;
526 miny = (GLfloat) gp->img_geom.y / gp->img_height;
527 maxx = ((GLfloat) (gp->img_geom.x + gp->img_geom.width) /
529 maxy = ((GLfloat) (gp->img_geom.y + gp->img_geom.height) /
533 minx = (minx * 2) - 1;
534 miny = (miny * 2) - 1;
535 maxx = (maxx * 2) - 1;
536 maxy = (maxy * 2) - 1;
546 glMatrixMode (GL_TEXTURE);
548 glTranslatef(-1,-1,0);
550 glMatrixMode (GL_MODELVIEW);
554 glRotatef(gp->anglex,1,0,0);
555 glRotatef(gp->angley,0,1,0);
556 glRotatef(gp->anglez,0,0,1);
557 glScalef(1,1,(GLfloat)_waveHeight);
558 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
559 glEnable(GL_TEXTURE_2D);
562 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
563 glBindTexture(GL_TEXTURE_2D, gp->texName);
564 check_gl_error("texture binding");
566 glColor3f(0.5,0.5,0.5);
568 for(x = minx, u = minu; x < maxx - 0.01; x += dx, u += du) {
569 glBegin(GL_QUAD_STRIP);
570 for (y = miny, v = minv; y <= maxy + 0.01; y += dy, v += dv) {
571 z = getGrid(gp,x,y,gp->time);
572 glTexCoord2f(u*xs,v*ys);
574 getGrid(gp,x+dx,y,gp->time)-getGrid(gp, x-dx,y,gp->time),
575 getGrid(gp,x,y+dy,gp->time)-getGrid(gp, x,y-dy,gp->time),
580 z = getGrid(gp,x+dx,y,gp->time);
581 glTexCoord2f((u+du)*xs,v*ys);
583 getGrid(gp,x+dx+dx,y,gp->time)-getGrid(gp, x,y,gp->time),
584 getGrid(gp,x+dx,y+dy,gp->time)-getGrid(gp, x+dx,y-dy,gp->time),
587 glVertex3f(x+dx,y,z);
593 /* Draw a border around the grid.
595 glColor3f(0.4, 0.4, 0.4);
596 glDisable(GL_TEXTURE_2D);
597 glEnable (GL_LINE_SMOOTH);
599 glBegin(GL_LINE_LOOP);
601 for (x = minx; x <= maxx; x += dx) {
602 glVertex3f (x, y, getGrid (gp, x, y, gp->time));
606 for (y = miny; y <= maxy; y += dy) {
607 glVertex3f (x, y, getGrid (gp, x, y, gp->time));
611 for (x = maxx; x >= minx; x -= dx) {
612 glVertex3f (x, y, getGrid (gp, x, y, gp->time));
616 for (y = maxy; y >= miny; y -= dy) {
617 glVertex3f (x, y, getGrid (gp, x, y, gp->time));
621 glEnable(GL_TEXTURE_2D);
623 if (! gp->button_down_p) {
625 gp->anglex -= _rotationx;
626 gp->angley -= _rotationy;
627 gp->anglez -= _rotationz;
632 static int displaySolid(gfluxstruct *gp)
637 double dx = 2.0/((double)_squares);
638 double dy = 2.0/((double)_squares);
641 glRotatef(gp->anglex,1,0,0);
642 glRotatef(gp->angley,0,1,0);
643 glRotatef(gp->anglez,0,0,1);
645 glScalef(1,1,(GLfloat)_waveHeight);
646 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
648 for(x=-1;x<0.9999;x+=dx) {
649 glBegin(GL_QUAD_STRIP);
650 for(y=-1;y<=1;y+=dy) {
651 z = getGrid(gp, x,y,gp->time);
653 glColor3fv(gp->colour);
656 z = getGrid(gp, x+dx,y,gp->time);
658 glColor3fv(gp->colour);
659 glVertex3f(x+dx,y,z);
665 if (! gp->button_down_p) {
667 gp->anglex -= _rotationx;
668 gp->angley -= _rotationy;
669 gp->anglez -= _rotationz;
675 static int displayLight(gfluxstruct *gp)
680 double dx = 2.0/((double)_squares);
681 double dy = 2.0/((double)_squares);
684 glRotatef(gp->anglex,1,0,0);
685 glRotatef(gp->angley,0,1,0);
686 glRotatef(gp->anglez,0,0,1);
688 glScalef(1,1,(GLfloat)_waveHeight);
689 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
691 for(x=-1;x<0.9999;x+=dx) {
692 glBegin(GL_QUAD_STRIP);
693 for(y=-1;y<=1;y+=dy) {
694 z = getGrid(gp, x,y,gp->time);
696 glColor3fv(gp->colour);
698 getGrid(gp, x+dx,y,gp->time)-getGrid(gp, x-dx,y,gp->time),
699 getGrid(gp, x,y+dy,gp->time)-getGrid(gp, x,y-dy,gp->time),
704 z = getGrid(gp, x+dx,y,gp->time);
706 glColor3fv(gp->colour);
708 getGrid(gp, x+dx+dx,y,gp->time)-getGrid(gp, x,y,gp->time),
709 getGrid(gp, x+dx,y+dy,gp->time)-getGrid(gp, x+dx,y-dy,gp->time),
712 glVertex3f(x+dx,y,z);
718 if (! gp->button_down_p) {
720 gp->anglex -= _rotationx;
721 gp->angley -= _rotationy;
722 gp->anglez -= _rotationz;
727 static int displayWire(gfluxstruct *gp)
732 double dx1 = 2.0/((double)(_squares*_resolution)) - 0.00001;
733 double dy1 = 2.0/((double)(_squares*_resolution)) - 0.00001;
734 double dx2 = 2.0/((double)_squares) - 0.00001;
735 double dy2 = 2.0/((double)_squares) - 0.00001;
738 glRotatef(gp->anglex,1,0,0);
739 glRotatef(gp->angley,0,1,0);
740 glRotatef(gp->anglez,0,0,1);
742 glScalef(1,1,(GLfloat)_waveHeight);
743 glClear(GL_COLOR_BUFFER_BIT);
745 for(x=-1;x<=1;x+=dx2) {
746 glBegin(GL_LINE_STRIP);
747 for(y=-1;y<=1;y+=dy1) {
748 z = getGrid(gp, x,y,gp->time);
750 glColor3fv(gp->colour);
756 for(y=-1;y<=1;y+=dy2) {
757 glBegin(GL_LINE_STRIP);
758 for(x=-1;x<=1;x+=dx1) {
759 z = getGrid(gp, x,y,gp->time);
761 glColor3fv(gp->colour);
768 if (! gp->button_down_p) {
770 gp->anglex -= _rotationx;
771 gp->angley -= _rotationy;
772 gp->anglez -= _rotationz;
777 /* generates new ripples */
778 static void calcGrid(gfluxstruct *gp)
782 if (gp->button_down_p) return;
784 tmp = 1.0/((double)_waveChange);
785 if(!(gp->counter%_waveChange)) {
786 gp->newWave = ((int)(gp->counter*tmp))%_waves;
787 gp->dispx[gp->newWave] = -frand(1.0);
788 gp->dispy[gp->newWave] = -frand(1.0);
789 gp->freq[gp->newWave] = _waveFreq * frand(1.0);
790 gp->wa[gp->newWave] = 0.0;
793 gp->wa[gp->newWave] += tmp;
794 gp->wa[(gp->newWave+1)%_waves] -= tmp;
797 /* returns a height for the grid given time and x,y space co-ords */
798 static double getGrid(gfluxstruct *gp, double x, double y, double a)
804 tmp = 1.0/((float)_waves);
805 for(i=0;i<_waves;i++) {
806 retval += gp->wa[i] * tmp * sin( gp->freq[i]
807 * ( (x+gp->dispx[i]) * (x+gp->dispx[i])
808 + (y+gp->dispy[i]) * (y+gp->dispy[i]) +a ) );
814 XSCREENSAVER_MODULE ("GFlux", gflux)