1 |
673 |
markom |
#ifndef NSAVER_H
|
2 |
|
|
#define NSAVER_H
|
3 |
|
|
/*
|
4 |
|
|
* The contents of this file are subject to the Mozilla Public License
|
5 |
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
6 |
|
|
* compliance with the License. You may obtain a copy of the License at
|
7 |
|
|
* http://www.mozilla.org/MPL/
|
8 |
|
|
*
|
9 |
|
|
* Software distributed under the License is distributed on an "AS IS"
|
10 |
|
|
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
11 |
|
|
* License for the specific language governing rights and limitations
|
12 |
|
|
* under the License.
|
13 |
|
|
*
|
14 |
|
|
* The Original Code is NanoScreenSaver.
|
15 |
|
|
*
|
16 |
|
|
* The Initial Developer of the Original Code is Alex Holden.
|
17 |
|
|
* Portions created by Alex Holden are Copyright (C) 2000
|
18 |
|
|
* Alex Holden <alex@linuxhacker.org>. All Rights Reserved.
|
19 |
|
|
*
|
20 |
|
|
* Contributor(s):
|
21 |
|
|
*
|
22 |
|
|
* Alternatively, the contents of this file may be used under the terms
|
23 |
|
|
* of the GNU General Public license (the "[GNU] License"), in which case the
|
24 |
|
|
* provisions of [GNU] License are applicable instead of those
|
25 |
|
|
* above. If you wish to allow use of your version of this file only
|
26 |
|
|
* under the terms of the [GNU] License and not to allow others to use
|
27 |
|
|
* your version of this file under the MPL, indicate your decision by
|
28 |
|
|
* deleting the provisions above and replace them with the notice and
|
29 |
|
|
* other provisions required by the [GNU] License. If you do not delete
|
30 |
|
|
* the provisions above, a recipient may use your version of this file
|
31 |
|
|
* under either the MPL or the [GNU] License.
|
32 |
|
|
*/
|
33 |
|
|
|
34 |
|
|
#define MAX(X, Y) ((X) > (Y) ? (X) : (Y))
|
35 |
|
|
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
|
36 |
|
|
#define RANDRANGE(LO, HI) ((LO) + ((double)((HI) - (LO)) * rand() \
|
37 |
|
|
/ (RAND_MAX + 1.0)))
|
38 |
|
|
|
39 |
|
|
typedef struct {
|
40 |
|
|
GR_WINDOW_ID main_window;
|
41 |
|
|
GR_GC_ID main_gc;
|
42 |
|
|
GR_EVENT event;
|
43 |
|
|
long animate_interval;
|
44 |
|
|
struct timeval timeout;
|
45 |
|
|
int saver;
|
46 |
|
|
void *priv;
|
47 |
|
|
GR_SCREEN_INFO si;
|
48 |
|
|
} nstate;
|
49 |
|
|
|
50 |
|
|
void *my_malloc(size_t size);
|
51 |
|
|
void get_random_point_on_screen(nstate *state, GR_COORD *x, GR_COORD *y,
|
52 |
|
|
GR_COLOR *c);
|
53 |
|
|
int init(nstate *state);
|
54 |
|
|
void calculate_timeout(nstate *state);
|
55 |
|
|
unsigned long timeout_delay(nstate *state);
|
56 |
|
|
unsigned long timeout_delay(nstate *state);
|
57 |
|
|
void do_animate(nstate *state);
|
58 |
|
|
int do_screensaver_event(nstate *state);
|
59 |
|
|
int handle_event(nstate *state);
|
60 |
|
|
|
61 |
|
|
#define NUM_SAVERS 8
|
62 |
|
|
|
63 |
|
|
void saver1_init(nstate *state);
|
64 |
|
|
void saver1_exposure(nstate *state);
|
65 |
|
|
void saver1_animate(nstate *state);
|
66 |
|
|
|
67 |
|
|
#define SAVER2_DELAY 1
|
68 |
|
|
#define SAVER2_MAXPIXELS 65535
|
69 |
|
|
#define SAVER2_PIXELS_PER_FRAME 16
|
70 |
|
|
|
71 |
|
|
void saver2_init(nstate *state);
|
72 |
|
|
void saver2_exposure(nstate *state);
|
73 |
|
|
void saver2_animate(nstate *state);
|
74 |
|
|
|
75 |
|
|
#define SAVER3_DELAY 1
|
76 |
|
|
#define SAVER3_MAXSEGMENTS 65535
|
77 |
|
|
#define SAVER3_SEGMENTS_PER_FRAME 4
|
78 |
|
|
|
79 |
|
|
typedef struct {
|
80 |
|
|
int maxsegments;
|
81 |
|
|
GR_COORD lastx;
|
82 |
|
|
GR_COORD lasty;
|
83 |
|
|
} s3state;
|
84 |
|
|
|
85 |
|
|
void saver3_init(nstate *state);
|
86 |
|
|
void saver3_exposure(nstate *state);
|
87 |
|
|
void saver3_animate(nstate *state);
|
88 |
|
|
|
89 |
|
|
#define SAVER4_DELAY 4
|
90 |
|
|
#define SAVER4_NUMWORMS 10
|
91 |
|
|
#define SAVER4_WORMLENGTH 100
|
92 |
|
|
#define SAVER4_COLLISION_RELUCTANCE 20
|
93 |
|
|
|
94 |
|
|
typedef struct {
|
95 |
|
|
GR_COLOR colour;
|
96 |
|
|
GR_POINT points[SAVER4_WORMLENGTH];
|
97 |
|
|
} s4worm;
|
98 |
|
|
|
99 |
|
|
typedef struct {
|
100 |
|
|
int length;
|
101 |
|
|
int tip;
|
102 |
|
|
s4worm worms[SAVER4_NUMWORMS];
|
103 |
|
|
} s4state;
|
104 |
|
|
|
105 |
|
|
void saver4_init(nstate *state);
|
106 |
|
|
void saver4_exposure(nstate *state);
|
107 |
|
|
void saver4_get_new_worm_position(nstate *state, s4state *s, int worm,
|
108 |
|
|
GR_COORD *newx, GR_COORD *newy);
|
109 |
|
|
int saver4_worm_collides(nstate *state, s4state *s, int x, int y, int thisworm,
|
110 |
|
|
int thispoint);
|
111 |
|
|
void saver4_animate(nstate *state);
|
112 |
|
|
|
113 |
|
|
#define SAVER5_DELAY 1
|
114 |
|
|
#define SAVER5_NUMSTARS 300
|
115 |
|
|
#define SAVER5_STARS_INCREMENT 2
|
116 |
|
|
#define SAVER5_STARS_ACCEL_RATE 30
|
117 |
|
|
|
118 |
|
|
typedef struct {
|
119 |
|
|
double angle;
|
120 |
|
|
int pos;
|
121 |
|
|
} s5star;
|
122 |
|
|
|
123 |
|
|
typedef struct {
|
124 |
|
|
int numstars;
|
125 |
|
|
s5star stars[SAVER5_NUMSTARS];
|
126 |
|
|
} s5state;
|
127 |
|
|
|
128 |
|
|
void saver5_init(nstate *state);
|
129 |
|
|
int saver5_drawstar(nstate *state, s5state *s, int star, int delete);
|
130 |
|
|
void saver5_exposure(nstate *state);
|
131 |
|
|
void saver5_animate(nstate *state);
|
132 |
|
|
|
133 |
|
|
#define SAVER6_DELAY 5
|
134 |
|
|
#define SAVER6_MAXVERTICES 20
|
135 |
|
|
#define SAVER6_MINFULLVERTICES 5
|
136 |
|
|
#define SAVER6_MINVERTICES 3
|
137 |
|
|
#define SAVER6_MINDROP 10
|
138 |
|
|
#define SAVER6_MAXBOLTS 4
|
139 |
|
|
#define SAVER6_MAXFORKS 20
|
140 |
|
|
#define SAVER6_MAXEND_Y 50
|
141 |
|
|
#define SAVER6_THICKNESS 6
|
142 |
|
|
#define SAVER6_MINDURATION 10
|
143 |
|
|
#define SAVER6_MAXDURATION 20
|
144 |
|
|
#define SAVER6_MAXNEWBOLTTIME 300
|
145 |
|
|
#define SAVER6_MAXZIGZAG 10
|
146 |
|
|
#define SAVER6_MAXPERTURBATION 5
|
147 |
|
|
#define SAVER6_FORK_PROBABILITY 0.5
|
148 |
|
|
|
149 |
|
|
typedef struct {
|
150 |
|
|
int valid;
|
151 |
|
|
GR_POINT vertices[SAVER6_THICKNESS][SAVER6_MAXVERTICES];
|
152 |
|
|
} s6fork;
|
153 |
|
|
|
154 |
|
|
typedef struct {
|
155 |
|
|
int duration;
|
156 |
|
|
s6fork forks[SAVER6_MAXFORKS];
|
157 |
|
|
} s6bolt;
|
158 |
|
|
|
159 |
|
|
typedef struct {
|
160 |
|
|
int new_bolt_time;
|
161 |
|
|
s6bolt bolts[SAVER6_MAXBOLTS];
|
162 |
|
|
} s6state;
|
163 |
|
|
|
164 |
|
|
void saver6_init(nstate *state);
|
165 |
|
|
void saver6_drawfork(nstate *state, s6state *s, int bolt, int fork, int delete);
|
166 |
|
|
void saver6_drawbolt(nstate *state, s6state *s, int bolt, int delete);
|
167 |
|
|
void saver6_drawlightning(nstate *state, s6state *s, int delete);
|
168 |
|
|
void saver6_exposure(nstate *state);
|
169 |
|
|
void saver6_setvertices(s6state *s, int bolt, int fork, int vert, GR_COORD x,
|
170 |
|
|
GR_COORD y);
|
171 |
|
|
void saver6_makefork(nstate *state, s6state *s, int bolt, int fork, GR_COORD x,
|
172 |
|
|
GR_COORD y);
|
173 |
|
|
void saver6_perturb(nstate *state, GR_COORD *x, GR_COORD *y, int maxperturb);
|
174 |
|
|
void saver6_makebolt(nstate *state, s6state *s, int bolt);
|
175 |
|
|
void saver6_newbolt(nstate *state, s6state *s);
|
176 |
|
|
void saver6_perturb_bolt(nstate *state, s6state *s, int bolt, int fork);
|
177 |
|
|
void saver6_perturb_lightning(nstate *state, s6state *s);
|
178 |
|
|
void saver6_animate(nstate *state);
|
179 |
|
|
|
180 |
|
|
/* The algorithm used in saver7 was adapted from "grav" by Greg Bowering */
|
181 |
|
|
|
182 |
|
|
#define SAVER7_DELAY 2
|
183 |
|
|
#define SAVER7_PLANETS 15
|
184 |
|
|
#define SAVER7_PLANETS_USE_DAMPING
|
185 |
|
|
#define SAVER7_STARCOLOUR YELLOW
|
186 |
|
|
#define SAVER7_STARRADIUS 5
|
187 |
|
|
#define SAVER7_PLANETRADIUS 3
|
188 |
|
|
#define SAVER7_DIST 16.0
|
189 |
|
|
#define SAVER7_ALMOSTDIST (SAVER7_DIST - 0.01)
|
190 |
|
|
#define SAVER7_MAX_STARTDIM (SAVER7_ALMOSTDIST / 2.0)
|
191 |
|
|
#define SAVER7_MIN_STARTDIM -SAVER7_MAX_STARTDIM
|
192 |
|
|
#define SAVER7_MAX_STARTVEL 0.04
|
193 |
|
|
#define SAVER7_MIN_STARTVEL -SAVER7_MAX_STARTVEL
|
194 |
|
|
#define SAVER7_G -0.02
|
195 |
|
|
#define SAVER7_COLLIDE 0.0001
|
196 |
|
|
#define SAVER7_DAMPING_FACTOR 0.999999
|
197 |
|
|
#define SAVER7_MAX_ACCEL 0.1
|
198 |
|
|
|
199 |
|
|
typedef struct {
|
200 |
|
|
double r;
|
201 |
|
|
double rv;
|
202 |
|
|
double x;
|
203 |
|
|
double xv;
|
204 |
|
|
double y;
|
205 |
|
|
double yv;
|
206 |
|
|
GR_COORD ax;
|
207 |
|
|
GR_COORD ay;
|
208 |
|
|
GR_COLOR colour;
|
209 |
|
|
} s7planet;
|
210 |
|
|
|
211 |
|
|
typedef struct {
|
212 |
|
|
s7planet planets[SAVER7_PLANETS];
|
213 |
|
|
GR_COORD starx;
|
214 |
|
|
GR_COORD stary;
|
215 |
|
|
} s7state;
|
216 |
|
|
|
217 |
|
|
void saver7_init(nstate *state);
|
218 |
|
|
void saver7_exposure(nstate *state);
|
219 |
|
|
void saver7_animate(nstate *state);
|
220 |
|
|
|
221 |
|
|
/* The algorithm used in saver8 is based on that found at:
|
222 |
|
|
http://www.go2net.com/internet/deep/1997/04/16/body.html */
|
223 |
|
|
|
224 |
|
|
#define SAVER8_DELAY 1
|
225 |
|
|
#define SAVER8_NUMCOLOURS 64 /* Don't set this higher than 512! */
|
226 |
|
|
#define SAVER8_MINFACTOR 1
|
227 |
|
|
#define SAVER8_MAXFACTOR 20
|
228 |
|
|
#define SAVER8_LINES_PER_FRAME 5
|
229 |
|
|
|
230 |
|
|
typedef struct {
|
231 |
|
|
GR_COLOR colours[SAVER8_NUMCOLOURS];
|
232 |
|
|
int current_line;
|
233 |
|
|
int factor;
|
234 |
|
|
} s8state;
|
235 |
|
|
|
236 |
|
|
void saver8_init(nstate *state);
|
237 |
|
|
void saver8_drawpattern(nstate *state);
|
238 |
|
|
void saver8_exposure(nstate *state);
|
239 |
|
|
void saver8_animate(nstate *state);
|
240 |
|
|
|
241 |
|
|
typedef void(*saver_function)(nstate *);
|
242 |
|
|
|
243 |
|
|
saver_function init_functions[NUM_SAVERS] = {
|
244 |
|
|
saver1_init,
|
245 |
|
|
saver2_init,
|
246 |
|
|
saver3_init,
|
247 |
|
|
saver4_init,
|
248 |
|
|
saver5_init,
|
249 |
|
|
saver6_init,
|
250 |
|
|
saver7_init,
|
251 |
|
|
saver8_init
|
252 |
|
|
};
|
253 |
|
|
saver_function exposure_functions[NUM_SAVERS] = {
|
254 |
|
|
saver1_exposure,
|
255 |
|
|
saver2_exposure,
|
256 |
|
|
saver3_exposure,
|
257 |
|
|
saver4_exposure,
|
258 |
|
|
saver5_exposure,
|
259 |
|
|
saver6_exposure,
|
260 |
|
|
saver7_exposure,
|
261 |
|
|
saver8_exposure
|
262 |
|
|
};
|
263 |
|
|
saver_function animate_functions[NUM_SAVERS] = {
|
264 |
|
|
saver1_animate,
|
265 |
|
|
saver2_animate,
|
266 |
|
|
saver3_animate,
|
267 |
|
|
saver4_animate,
|
268 |
|
|
saver5_animate,
|
269 |
|
|
saver6_animate,
|
270 |
|
|
saver7_animate,
|
271 |
|
|
saver8_animate
|
272 |
|
|
};
|
273 |
|
|
#endif
|