1
1
/* -*- Mode: C; tab-width: 4 -*- */
2
2
/* mountain -- square grid mountains */
4
#if !defined( lint ) && !defined( SABER )
5
static const char sccsid[] = "@(#)mountain.c 4.04 97/07/28 xlockmore";
5
static const char sccsid[] = "@(#)mountain.c 5.00 2000/11/01 xlockmore";
22
21
* other special, indirect and consequential damages.
24
23
* Revision History:
25
* 10-May-97: Compatible with xscreensaver
24
* 01-Nov-2000: Allocation checks
25
* 10-May-1997: Compatible with xscreensaver
29
# define PROGCLASS "Mountain"
30
# define HACK_INIT init_mountain
31
# define HACK_DRAW draw_mountain
32
# define mountain_opts xlockmore_opts
33
# define DEFAULTS "*delay: 0 \n" \
37
# define SMOOTH_COLORS
31
#define PROGCLASS "Mountain"
32
#define HACK_INIT init_mountain
33
#define HACK_DRAW draw_mountain
34
#define mountain_opts xlockmore_opts
35
#define DEFAULTS "*delay: 1000 \n" \
38
40
#include "xlockmore.h" /* in xscreensaver distribution */
39
41
#else /* STANDALONE */
40
42
#include "xlock.h" /* in xlockmore distribution */
41
43
#endif /* STANDALONE */
43
47
ModeSpecOpt mountain_opts =
44
{0, NULL, 0, NULL, NULL};
48
{0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL};
51
ModStruct mountain_description =
52
{"mountain", "init_mountain", "draw_mountain", "release_mountain",
53
"refresh_mountain", "init_mountain", (char *) NULL, &mountain_opts,
54
1000, 30, 4000, 1, 64, 1.0, "",
55
"Shows Papo's mountain range", 0, NULL};
46
59
/* ~ 5000 Max mountain height (1000 - 10000) */
47
60
#define MAXHEIGHT (3 * (mp->width + mp->height))
60
73
int h[WORLDWIDTH][WORLDWIDTH];
61
int time; /* up time */
74
long time; /* up time */
66
static mountainstruct *mountains = NULL;
80
static mountainstruct *mountains = (mountainstruct *) NULL;
69
83
spread(int (*m)[50], int x, int y)
116
130
if (MI_NPIXELS(mi) > 2)
117
131
XSetForeground(display, gc, MI_PIXEL(mi, c));
119
XSetForeground(display, gc, MI_WIN_WHITE_PIXEL(mi));
120
XFillPolygon(display, window, gc, p, 4, Complex, CoordModeOrigin);
122
if (!mp->pixelmode) {
123
XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi));
124
XDrawLines(display, window, gc, p, 5, CoordModeOrigin);
133
XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
136
if ((Bool) (LRAND() & 1))
137
XDrawLines(display, window, gc, p, 5, CoordModeOrigin);
139
XFillPolygon(display, window, gc, p, 4, Complex, CoordModeOrigin);
140
if (!mp->pixelmode) {
141
XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
142
XDrawLines(display, window, gc, p, 5, CoordModeOrigin);
147
XDrawLines(display, window, gc, p, 5, CoordModeOrigin);
149
XFillPolygon(display, window, gc, p, 4, Complex, CoordModeOrigin);
151
if (!mp->pixelmode) {
152
XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
153
XDrawLines(display, window, gc, p, 5, CoordModeOrigin);
127
158
if (mp->x == WORLDWIDTH - 1) {
147
178
mp = &mountains[MI_SCREEN(mi)];
148
mp->width = MI_WIN_WIDTH(mi);
149
mp->height = MI_WIN_HEIGHT(mi);
180
mp->width = MI_WIDTH(mi);
181
mp->height = MI_HEIGHT(mi);
150
182
mp->pixelmode = (mp->width + mp->height < 200);
153
185
mp->x = mp->y = 0;
156
gcv.foreground = MI_WIN_WHITE_PIXEL(mi);
157
gcv.background = MI_WIN_BLACK_PIXEL(mi);
159
mp->stippled_GC = XCreateGC(MI_DISPLAY(mi), MI_WINDOW(mi),
160
GCForeground | GCBackground, &gcv);
162
XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi));
164
for (y = 0; y < WORLDWIDTH; y++)
165
for (x = 0; x < WORLDWIDTH; x++)
186
if (MI_IS_FULLRANDOM(mi)) {
187
mp->joke = (Bool) (NRAND(10) == 0);
188
mp->wireframe = (Bool) (LRAND() & 1);
191
mp->wireframe = MI_IS_WIREFRAME(mi);
194
if (mp->stippledGC == None) {
195
gcv.foreground = MI_WHITE_PIXEL(mi);
196
gcv.background = MI_BLACK_PIXEL(mi);
197
if ((mp->stippledGC = XCreateGC(MI_DISPLAY(mi), MI_WINDOW(mi),
198
GCForeground | GCBackground, &gcv)) == None)
203
for (y = 0; y < (int) WORLDWIDTH; y++)
204
for (x = 0; x < (int) WORLDWIDTH; x++)
168
j = MI_BATCHCOUNT(mi);
170
209
j = NRAND(-j) + 1;
171
210
for (i = 0; i < j; i++)
193
232
draw_mountain(ModeInfo * mi)
195
mountainstruct *mp = &mountains[MI_SCREEN(mi)];
236
if (mountains == NULL)
238
mp = &mountains[MI_SCREEN(mi)];
239
if (mp->stippledGC == NULL)
242
MI_IS_DRAWN(mi) = True;
197
244
switch (mp->stage) {
199
246
drawamountain(mi);
202
MI_PAUSE(mi) = 2000000;
203
/*if (++mp->time > MI_CYCLES(mi)); */
249
if (++mp->time > MI_CYCLES(mi))
207
253
init_mountain(mi);
218
264
for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
219
265
mountainstruct *mp = &mountains[screen];
221
XFreeGC(MI_DISPLAY(mi), mp->stippled_GC);
268
XFreeGC(MI_DISPLAY(mi), mp->stippledGC);
223
270
(void) free((void *) mountains);
271
mountains = (mountainstruct *) NULL;
229
276
refresh_mountain(ModeInfo * mi)
231
mountainstruct *mp = &mountains[MI_SCREEN(mi)];
280
if (mountains == NULL)
282
mp = &mountains[MI_SCREEN(mi)];
289
#endif /* MODE_mountain */