~ubuntu-branches/ubuntu/dapper/xscreensaver/dapper

« back to all changes in this revision

Viewing changes to hacks/grav.c

  • Committer: Bazaar Package Importer
  • Author(s): Oliver Grawert
  • Date: 2005-10-11 21:00:42 UTC
  • mfrom: (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20051011210042-u7q6zslgevdxspr3
Tags: 4.21-4ubuntu17
updated pt_BR again, fixed to UTF-8 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 4 -*-
2
 
 * grav --- simulation of a planetary system.
3
 
 */
4
 
#if !defined( lint ) && !defined( SABER )
5
 
static const char sccsid[] = "@(#)grav.c        4.00 97/01/01 xlockmore";
 
1
/* -*- Mode: C; tab-width: 4 -*- */
 
2
/* grav --- planets spinning around a pulsar */
 
3
 
 
4
#if 0
 
5
static const char sccsid[] = "@(#)grav.c        5.00 2000/11/01 xlockmore";
6
6
#endif
7
7
 
8
 
/* Copyright (c) 1993 Greg Bowering <gb@pobox.com>
 
8
/*-
 
9
 * Copyright (c) 1993 by Greg Boewring <gb@pobox.com>
9
10
 *
10
11
 * Permission to use, copy, modify, and distribute this software and its
11
12
 * documentation for any purpose and without fee is hereby granted,
19
20
 * event will the author be liable for any lost revenue or profits or
20
21
 * other special, indirect and consequential damages.
21
22
 *
22
 
 * Revision history:
23
 
 * 10-May-97: jwz@jwz.org: turned into a standalone program.
24
 
 * 11-Jul-94: color version
25
 
 * 06-Oct-93: by Greg Bowering <gb@pobox.com>
 
23
 * Revision History:
 
24
 * 01-Nov-2000: Allocation checks
 
25
 * 10-May-1997: Compatible with xscreensaver
 
26
 * 11-Jul-1994: color version
 
27
 * 06-Oct-1993: Written by Greg Bowering <gb@pobox.com>
26
28
 */
27
29
 
28
30
#ifdef STANDALONE
29
 
# define PROGCLASS                                      "Grav"
30
 
# define HACK_INIT                                      init_grav
31
 
# define HACK_DRAW                                      draw_grav
32
 
# define grav_opts                                      xlockmore_opts
33
 
# define DEFAULTS       "*count:                12    \n"                       \
34
 
                                        "*delay:                10000 \n"                       \
35
 
                                        "*ncolors:              64   \n"
36
 
# define BRIGHT_COLORS
37
 
# include "xlockmore.h"                         /* from the xscreensaver distribution */
38
 
#else  /* !STANDALONE */
39
 
# include "xlock.h"                                     /* from the xlockmore distribution */
40
 
#endif /* !STANDALONE */
 
31
#define MODE_grav
 
32
#define PROGCLASS "Grav"
 
33
#define HACK_INIT init_grav
 
34
#define HACK_DRAW draw_grav
 
35
#define grav_opts xlockmore_opts
 
36
#define DEFAULTS "*delay: 10000 \n" \
 
37
 "*count: 12 \n" \
 
38
 "*ncolors: 64 \n"
 
39
#define BRIGHT_COLORS
 
40
#include "xlockmore.h"          /* in xscreensaver distribution */
 
41
#else /* STANDALONE */
 
42
#include "xlock.h"              /* in xlockmore distribution */
 
43
 
 
44
#endif /* STANDALONE */
 
45
 
 
46
#ifdef MODE_grav
 
47
 
 
48
#define DEF_DECAY "False"       /* Damping for decaying orbits */
 
49
#define DEF_TRAIL "False"       /* For trails (works good in mono only) */
 
50
 
 
51
static Bool decay;
 
52
static Bool trail;
 
53
 
 
54
static XrmOptionDescRec opts[] =
 
55
{
 
56
        {"-decay", ".grav.decay", XrmoptionNoArg, "on"},
 
57
        {"+decay", ".grav.decay", XrmoptionNoArg, "off"},
 
58
        {"-trail", ".grav.trail", XrmoptionNoArg, "on"},
 
59
        {"+trail", ".grav.trail", XrmoptionNoArg, "off"}
 
60
};
 
61
static argtype vars[] =
 
62
{
 
63
        {&decay, "decay", "Decay", DEF_DECAY, t_Bool},
 
64
        {&trail, "trail", "Trail", DEF_TRAIL, t_Bool}
 
65
};
 
66
static OptionStruct desc[] =
 
67
{
 
68
        {"-/+decay", "turn on/off decaying orbits"},
 
69
        {"-/+trail", "turn on/off trail dots"}
 
70
};
 
71
 
 
72
ModeSpecOpt grav_opts =
 
73
{sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
 
74
 
 
75
#ifdef USE_MODULES
 
76
ModStruct   grav_description =
 
77
{"grav", "init_grav", "draw_grav", "release_grav",
 
78
 "refresh_grav", "init_grav", (char *) NULL, &grav_opts,
 
79
 10000, -12, 1, 1, 64, 1.0, "",
 
80
 "Shows orbiting planets", 0, NULL};
 
81
 
 
82
#endif
41
83
 
42
84
#define GRAV                    -0.02   /* Gravitational constant */
43
85
#define DIST                    16.0
80
122
 
81
123
#define FLOATRAND(min,max)      ((min)+(LRAND()/MAXRAND)*((max)-(min)))
82
124
 
83
 
#define DEF_DECAY "False"       /* Damping for decaying orbits */
84
 
#define DEF_TRAIL "False"       /* For trails (works good in mono only) */
85
 
 
86
 
static Bool decay;
87
 
static Bool trail;
88
 
 
89
 
static XrmOptionDescRec opts[] =
90
 
{
91
 
        {"-decay", ".grav.decay", XrmoptionNoArg, (caddr_t) "on"},
92
 
        {"+decay", ".grav.decay", XrmoptionNoArg, (caddr_t) "off"},
93
 
        {"-trail", ".grav.trail", XrmoptionNoArg, (caddr_t) "on"},
94
 
        {"+trail", ".grav.trail", XrmoptionNoArg, (caddr_t) "off"}
95
 
};
96
 
static argtype vars[] =
97
 
{
98
 
        {(caddr_t *) & decay, "decay", "Decay", DEF_DECAY, t_Bool},
99
 
        {(caddr_t *) & trail, "trail", "Trail", DEF_TRAIL, t_Bool}
100
 
};
101
 
static OptionStruct desc[] =
102
 
{
103
 
        {"-/+decay", "turn on/off decaying orbits"},
104
 
        {"-/+trail", "turn on/off trail dots"}
105
 
};
106
 
 
107
 
ModeSpecOpt grav_opts = { 4, opts, 2, vars, desc };
108
 
 
109
125
typedef struct {
110
 
        double        P[DIMENSIONS], V[DIMENSIONS], A[DIMENSIONS];
111
 
        int           xi, yi, ri;
 
126
        double      P[DIMENSIONS], V[DIMENSIONS], A[DIMENSIONS];
 
127
        int         xi, yi, ri;
112
128
        unsigned long colors;
113
129
} planetstruct;
114
130
 
119
135
        planetstruct *planets;
120
136
} gravstruct;
121
137
 
122
 
static gravstruct *gravs = NULL;
 
138
static gravstruct *gravs = (gravstruct *) NULL;
123
139
 
124
140
static void
125
141
init_planet(ModeInfo * mi, planetstruct * planet)
132
148
        if (MI_NPIXELS(mi) > 2)
133
149
                planet->colors = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
134
150
        else
135
 
                planet->colors = MI_WIN_WHITE_PIXEL(mi);
 
151
                planet->colors = MI_WHITE_PIXEL(mi);
136
152
        /* Initialize positions */
137
153
        POS(X) = FLOATRAND(-XR, XR);
138
154
        POS(Y) = FLOATRAND(-YR, YR);
200
216
                planet->xi = planet->yi = -1;
201
217
 
202
218
        /* Mask */
203
 
        XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi));
 
219
        XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
204
220
        Planet(gp->x, gp->y);
205
221
        if (trail) {
206
222
                XSetForeground(display, gc, planet->colors);
221
237
{
222
238
        Display    *display = MI_DISPLAY(mi);
223
239
        GC          gc = MI_GC(mi);
224
 
        gravstruct *gp;
225
240
        unsigned char ball;
 
241
        gravstruct *gp;
226
242
 
227
243
        if (gravs == NULL) {
228
244
                if ((gravs = (gravstruct *) calloc(MI_NUM_SCREENS(mi),
231
247
        }
232
248
        gp = &gravs[MI_SCREEN(mi)];
233
249
 
234
 
        gp->width = MI_WIN_WIDTH(mi);
235
 
        gp->height = MI_WIN_HEIGHT(mi);
 
250
        gp->width = MI_WIDTH(mi);
 
251
        gp->height = MI_HEIGHT(mi);
236
252
 
237
253
        gp->sr = STARRADIUS;
238
254
 
239
 
        gp->nplanets = MI_BATCHCOUNT(mi);
 
255
        gp->nplanets = MI_COUNT(mi);
240
256
        if (gp->nplanets < 0) {
241
257
                if (gp->planets) {
242
258
                        (void) free((void *) gp->planets);
243
 
                        gp->planets = NULL;
 
259
                        gp->planets = (planetstruct *) NULL;
244
260
                }
245
261
                gp->nplanets = NRAND(-gp->nplanets) + 1;        /* Add 1 so its not too boring */
246
262
        }
247
 
        if (!gp->planets)
248
 
                gp->planets = (planetstruct *) calloc(gp->nplanets, sizeof (planetstruct));
 
263
        if (gp->planets == NULL) {
 
264
                if ((gp->planets = (planetstruct *) calloc(gp->nplanets,
 
265
                                sizeof (planetstruct))) == NULL)
 
266
                        return;
 
267
        }
249
268
 
250
 
        XClearWindow(display, MI_WINDOW(mi));
 
269
        MI_CLEARWINDOW(mi);
251
270
 
252
271
        if (MI_NPIXELS(mi) > 2)
253
272
                gp->starcolor = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi)));
254
273
        else
255
 
                gp->starcolor = MI_WIN_WHITE_PIXEL(mi);
 
274
                gp->starcolor = MI_WHITE_PIXEL(mi);
256
275
        for (ball = 0; ball < (unsigned char) gp->nplanets; ball++)
257
276
                init_planet(mi, &gp->planets[ball]);
258
277
 
268
287
        Display    *display = MI_DISPLAY(mi);
269
288
        Window      window = MI_WINDOW(mi);
270
289
        GC          gc = MI_GC(mi);
271
 
        gravstruct *gp = &gravs[MI_SCREEN(mi)];
272
290
        register unsigned char ball;
273
 
 
 
291
        gravstruct *gp;
 
292
 
 
293
        if (gravs == NULL)
 
294
                        return;
 
295
        gp = &gravs[MI_SCREEN(mi)];
 
296
        if (gp->planets == NULL)
 
297
                return;
 
298
 
 
299
        MI_IS_DRAWN(mi) = True;
274
300
        /* Mask centrepoint */
275
 
        XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi));
 
301
        XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
276
302
        XDrawArc(display, window, gc,
277
303
                 gp->width / 2 - gp->sr / 2, gp->height / 2 - gp->sr / 2, gp->sr, gp->sr,
278
304
                 0, 23040);
311
337
                                (void) free((void *) gp->planets);
312
338
                }
313
339
                (void) free((void *) gravs);
314
 
                gravs = NULL;
 
340
                gravs = (gravstruct *) NULL;
315
341
        }
316
342
}
317
343
 
318
344
void
319
345
refresh_grav(ModeInfo * mi)
320
346
{
321
 
        /* Do nothing, it will refresh by itself */
 
347
        MI_CLEARWINDOW(mi);
322
348
}
 
349
 
 
350
#endif /* MODE_grav */