From http://www.jwz.org/xscreensaver/xscreensaver-5.31.tar.gz
[xscreensaver] / hacks / glx / stonerview-move.c
1 /* StonerView: An eccentric visual toy.
2    Copyright 1998-2001 by Andrew Plotkin (erkyrath@eblong.com)
3
4    Permission to use, copy, modify, distribute, and sell this software and its
5    documentation for any purpose is hereby granted without fee, provided that
6    the above copyright notice appear in all copies and that both that
7    copyright notice and this permission notice appear in supporting
8    documentation.  No representations are made about the suitability of this
9    software for any purpose.  It is provided "as is" without express or 
10    implied warranty.
11 */
12
13 #include <math.h>
14
15 #ifdef HAVE_CONFIG_H
16 # include "config.h"
17 #endif
18
19 #include <stdio.h>
20 #include <stdlib.h>
21
22 #include "yarandom.h"
23 #include "stonerview.h"
24
25
26 void
27 stonerview_init_move(stonerview_state *st)
28 {
29   /*st->theta = new_osc_linear(
30     new_osc_wrap(0, 36000, 25),
31     new_osc_constant(2000));*/
32     
33   st->theta = new_osc_linear(st,
34     new_osc_velowrap(st, 0, 36000, new_osc_multiplex(st,
35       new_osc_randphaser(st, 300, 600),
36       new_osc_constant(st, 25),
37       new_osc_constant(st, 75),
38       new_osc_constant(st, 50),
39       new_osc_constant(st, 100))
40     ),
41         
42     new_osc_multiplex(st,
43       new_osc_buffer(st, new_osc_randphaser(st, 300, 600)),
44       new_osc_buffer(st, new_osc_wrap(st, 0, 36000, 10)),
45       new_osc_buffer(st, new_osc_wrap(st, 0, 36000, -8)),
46       new_osc_wrap(st, 0, 36000, 4),
47       new_osc_buffer(st, new_osc_bounce(st, -2000, 2000, 20))
48       )
49     );
50         
51   st->rad = new_osc_buffer(st, new_osc_multiplex(st,
52     new_osc_randphaser(st, 250, 500),
53     new_osc_bounce(st, -1000, 1000, 10),
54     new_osc_bounce(st,   200, 1000, -15),
55     new_osc_bounce(st,   400, 1000, 10),
56     new_osc_bounce(st, -1000, 1000, -20)));
57   /*st->rad = new_osc_constant(st, 1000);*/
58     
59   st->alti = new_osc_linear(st,
60     new_osc_constant(st, -1000),
61     new_osc_constant(st, 2000 / st->num_els));
62
63   /*st->alti = new_osc_multiplex(
64     new_osc_buffer(st, new_osc_randphaser(60, 270)),
65     new_osc_buffer(st, new_osc_bounce(-1000, 1000, 48)),
66     new_osc_linear(
67       new_osc_constant(-1000),
68       new_osc_constant(2000 / st->num_els)),
69     new_osc_buffer(st, new_osc_bounce(-1000, 1000, 27)),
70       new_osc_linear(
71       new_osc_constant(-1000),
72       new_osc_constant(2000 / st->num_els))
73     );*/
74     
75   /*st->color = new_osc_buffer(st, new_osc_randphaser(5, 35));*/
76     
77   /*st->color = new_osc_buffer(st, new_osc_multiplex(
78     new_osc_randphaser(25, 70),
79     new_osc_wrap(0, 3600, 20),
80     new_osc_wrap(0, 3600, 30),
81     new_osc_wrap(0, 3600, -20),
82     new_osc_wrap(0, 3600, 10)));*/
83   st->color = new_osc_multiplex(st,
84     new_osc_buffer(st, new_osc_randphaser(st, 150, 300)),
85     new_osc_buffer(st, new_osc_wrap(st, 0, 3600, 13)),
86     new_osc_buffer(st, new_osc_wrap(st, 0, 3600, 32)),
87     new_osc_buffer(st, new_osc_wrap(st, 0, 3600, 17)),
88     new_osc_buffer(st, new_osc_wrap(st, 0, 3600, 7)));
89
90   stonerview_move_increment(st);
91 }
92
93 /* Set up the list of polygon data for rendering. */
94 void
95 stonerview_move_increment(stonerview_state *st)
96 {
97   int ix, val;
98 /*  double fval; */
99 /*  double recipels = (1.0 / (double)st->num_els); */
100   double pt[2];
101   double ptrad, pttheta;
102     
103   for (ix=0; ix<st->num_els; ix++) {
104     stonerview_elem_t *el = &st->elist[ix];
105         
106     /* Grab r and theta... */
107     val = osc_get(st, st->theta, ix);
108     pttheta = val * (0.01 * M_PI / 180.0); 
109     ptrad = (double)osc_get(st, st->rad, ix) * 0.001;
110     /* And convert them to x,y coordinates. */
111     pt[0] = ptrad * cos(pttheta);
112     pt[1] = ptrad * sin(pttheta);
113         
114     /* Set x,y,z. */
115     el->pos[0] = pt[0];
116     el->pos[1] = pt[1];
117     el->pos[2] = (double)osc_get(st, st->alti, ix) * 0.001;
118         
119     /* Set which way the square is rotated. This is fixed for now, although
120        it would be trivial to make the squares spin as they revolve. */
121     el->vervec[0] = 0.11;
122     el->vervec[1] = 0.0;
123         
124     /* Grab the color, and convert it to RGB values. Technically, we're
125        converting an HSV value to RGB, where S and V are always 1. */
126     val = osc_get(st, st->color, ix);
127     if (val < 1200) {
128       el->col[0] = ((double)val / 1200.0);
129       el->col[1] = 0;
130       el->col[2] = (double)(1200 - val) / 1200.0;
131     } 
132     else if (val < 2400) {
133       el->col[0] = (double)(2400 - val) / 1200.0;
134       el->col[1] = ((double)(val - 1200) / 1200.0);
135       el->col[2] = 0;
136     }
137     else {
138       el->col[0] = 0;
139       el->col[1] = (double)(3600 - val) / 1200.0;
140       el->col[2] = ((double)(val - 2400) / 1200.0);
141     }
142     el->col[3] = 1.0;
143   }
144     
145   osc_increment(st);
146 }
147