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

« back to all changes in this revision

Viewing changes to hacks/hopalong.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
 
 * hop --- real plane fractals.
3
 
 */
4
 
#if !defined( lint ) && !defined( SABER )
5
 
static const char sccsid[] = "@(#)hop.c 4.02 97/04/01 xlockmore";
 
1
/* -*- Mode: C; tab-width: 4 -*- */
 
2
/* hop --- real plane fractals */
 
3
 
 
4
#if 0
 
5
static const char sccsid[] = "@(#)hop.c 5.00 2000/11/01 xlockmore";
6
6
#endif
7
7
 
8
 
/* Copyright (c) 1988-91 by Patrick J. Naughton.
 
8
/*-
 
9
 * Copyright (c) 1991 by Patrick J. Naughton.
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,
20
21
 * other special, indirect and consequential damages.
21
22
 *
22
23
 * Revision History:
23
 
 * Changes of David Bagley <bagleyd@bigfoot.com>
24
 
 * 24-Jun-97: EJK and RR functions stolen from xmartin2.2
25
 
 *            Ed Kubaitis <ejk@ux2.cso.uiuc.edu> ejk functions and xmartin 
26
 
 *            Renaldo Recuerdo rr function, generalized exponent version
 
24
 * Changes in xlockmore distribution
 
25
 * 01-Nov-2000: Allocation checks
 
26
 * 24-Jun-1997: EJK and RR functions stolen from xmartin2.2
 
27
 *              Ed Kubaitis <ejk@ux2.cso.uiuc.edu> ejk functions and xmartin
 
28
 *              Renaldo Recuerdo rr function, generalized exponent version
27
29
 *              of the Barry Martin's square root function
28
 
 * 10-May-97: jwz@jwz.org: ported from xlockmore 4.03a10 to be a 
29
 
 *                        standalone program and thus usable with xscreensaver
30
 
 *                        (I threw away my 1992 port and started over.)
31
 
 * 27-Jul-95: added Peter de Jong's hop from Scientific American
32
 
 *            July 87 p. 111.  Sometimes they are amazing but there are a
33
 
 *            few duds (I did not see a pattern in the parameters).
34
 
 * 29-Mar-95: changed name from hopalong to hop
35
 
 * 09-Dec-94: added Barry Martin's sine hop
36
 
 *
37
 
 * (12-Aug-92: jwz@lucid.com: made xlock version run standalone.)
38
 
 *
39
 
 * Changes of Patrick J. Naughton
40
 
 * 29-Oct-90: fix bad (int) cast.
41
 
 * 29-Jul-90: support for multiple screens.
42
 
 * 08-Jul-90: new timing and colors and new algorithm for fractals.
43
 
 * 15-Dec-89: Fix for proper skipping of {White,Black}Pixel() in colors.
44
 
 * 08-Oct-89: Fixed long standing typo bug in RandomInitHop();
45
 
 *            Fixed bug in memory allocation in init_hop();
46
 
 *            Moved seconds() to an extern.
47
 
 *            Got rid of the % mod since .mod is slow on a sparc.
48
 
 * 20-Sep-89: Lint.
49
 
 * 31-Aug-88: Forked from xlock.c for modularity.
50
 
 * 23-Mar-88: Coded HOPALONG routines from Scientific American Sept. 86 p. 14.
51
 
 *            Hopalong was attributed to Barry Martin of Aston University
52
 
 *            (Birmingham, England)
 
30
 * 10-May-1997: Compatible with xscreensaver
 
31
 * 27-Jul-1995: added Peter de Jong's hop from Scientific American
 
32
 *              July 87 p. 111.  Sometimes they are amazing but there are a
 
33
 *              few duds (I did not see a pattern in the parameters).
 
34
 * 29-Mar-1995: changed name from hopalong to hop
 
35
 * 09-Dec-1994: added Barry Martin's sine hop
 
36
 * Changes in original xlock
 
37
 * 29-Oct-1990: fix bad (int) cast.
 
38
 * 29-Jul-1990: support for multiple screens.
 
39
 * 08-Jul-1990: new timing and colors and new algorithm for fractals.
 
40
 * 15-Dec-1989: Fix for proper skipping of {White,Black}Pixel() in colors.
 
41
 * 08-Oct-1989: Fixed long standing typo bug in RandomInitHop();
 
42
 *                  Fixed bug in memory allocation in init_hop();
 
43
 *                  Moved seconds() to an extern.
 
44
 *                  Got rid of the % mod since .mod is slow on a sparc.
 
45
 * 20-Sep-1989: Lint.
 
46
 * 31-Aug-1988: Forked from xlock.c for modularity.
 
47
 * 23-Mar-1988: Coded HOPALONG routines from Scientific American Sept. 86 p. 14.
 
48
 *              Hopalong was attributed to Barry Martin of Aston University
 
49
 *              (Birmingham, England)
53
50
 */
54
51
 
 
52
 
55
53
#ifdef STANDALONE
56
 
# define PROGCLASS                                      "Hopalong"
57
 
# define HACK_INIT                                      init_hop
58
 
# define HACK_DRAW                                      draw_hop
59
 
# define HACK_FREE                                      release_hop
60
 
# define hop_opts                                       xlockmore_opts
61
 
# define DEFAULTS       "*delay:                10000   \n"                     \
62
 
                                        "*count:                1000    \n"                     \
63
 
                                        "*cycles:               2500    \n"                     \
64
 
                                        "*ncolors:              200     \n"
65
 
# define SMOOTH_COLORS
66
 
# include "xlockmore.h"                         /* from the xscreensaver distribution */
67
 
# include "erase.h"
68
 
#else  /* !STANDALONE */
69
 
# include "xlock.h"                                     /* from the xlockmore distribution */
70
 
#endif /* !STANDALONE */
 
54
#define MODE_hop
 
55
#define PROGCLASS "Hop"
 
56
#define HACK_INIT init_hop
 
57
#define HACK_DRAW draw_hop
 
58
#define hop_opts xlockmore_opts
 
59
#define DEFAULTS "*delay: 10000 \n" \
 
60
 "*count: 1000 \n" \
 
61
 "*cycles: 2500 \n" \
 
62
 "*ncolors: 200 \n"
 
63
#define SMOOTH_COLORS
 
64
#include "xlockmore.h"          /* in xscreensaver distribution */
 
65
#include "erase.h"
 
66
#else /* STANDALONE */
 
67
#include "xlock.h"              /* in xlockmore distribution */
 
68
 
 
69
#endif /* STANDALONE */
 
70
 
 
71
#ifdef MODE_hop
71
72
 
72
73
#define DEF_MARTIN "False"
73
74
#define DEF_POPCORN "False"
95
96
 
96
97
static XrmOptionDescRec opts[] =
97
98
{
98
 
        {"-martin", ".hop.martin", XrmoptionNoArg, (caddr_t) "on"},
99
 
        {"+martin", ".hop.martin", XrmoptionNoArg, (caddr_t) "off"},
100
 
        {"-popcorn", ".hop.popcorn", XrmoptionNoArg, (caddr_t) "on"},
101
 
        {"+popcorn", ".hop.popcorn", XrmoptionNoArg, (caddr_t) "off"},
102
 
        {"-ejk1", ".hop.ejk1", XrmoptionNoArg, (caddr_t) "on"},
103
 
        {"+ejk1", ".hop.ejk1", XrmoptionNoArg, (caddr_t) "off"},
104
 
        {"-ejk2", ".hop.ejk2", XrmoptionNoArg, (caddr_t) "on"},
105
 
        {"+ejk2", ".hop.ejk2", XrmoptionNoArg, (caddr_t) "off"},
106
 
        {"-ejk3", ".hop.ejk3", XrmoptionNoArg, (caddr_t) "on"},
107
 
        {"+ejk3", ".hop.ejk3", XrmoptionNoArg, (caddr_t) "off"},
108
 
        {"-ejk4", ".hop.ejk4", XrmoptionNoArg, (caddr_t) "on"},
109
 
        {"+ejk4", ".hop.ejk4", XrmoptionNoArg, (caddr_t) "off"},
110
 
        {"-ejk5", ".hop.ejk5", XrmoptionNoArg, (caddr_t) "on"},
111
 
        {"+ejk5", ".hop.ejk5", XrmoptionNoArg, (caddr_t) "off"},
112
 
        {"-ejk6", ".hop.ejk6", XrmoptionNoArg, (caddr_t) "on"},
113
 
        {"+ejk6", ".hop.ejk6", XrmoptionNoArg, (caddr_t) "off"},
114
 
        {"-rr", ".hop.rr", XrmoptionNoArg, (caddr_t) "on"},
115
 
        {"+rr", ".hop.rr", XrmoptionNoArg, (caddr_t) "off"},
116
 
        {"-jong", ".hop.jong", XrmoptionNoArg, (caddr_t) "on"},
117
 
        {"+jong", ".hop.jong", XrmoptionNoArg, (caddr_t) "off"},
118
 
        {"-sine", ".hop.sine", XrmoptionNoArg, (caddr_t) "on"},
119
 
        {"+sine", ".hop.sine", XrmoptionNoArg, (caddr_t) "off"}
 
99
        {"-martin", ".hop.martin", XrmoptionNoArg, "on"},
 
100
        {"+martin", ".hop.martin", XrmoptionNoArg, "off"},
 
101
        {"-popcorn", ".hop.popcorn", XrmoptionNoArg, "on"},
 
102
        {"+popcorn", ".hop.popcorn", XrmoptionNoArg, "off"},
 
103
        {"-ejk1", ".hop.ejk1", XrmoptionNoArg, "on"},
 
104
        {"+ejk1", ".hop.ejk1", XrmoptionNoArg, "off"},
 
105
        {"-ejk2", ".hop.ejk2", XrmoptionNoArg, "on"},
 
106
        {"+ejk2", ".hop.ejk2", XrmoptionNoArg, "off"},
 
107
        {"-ejk3", ".hop.ejk3", XrmoptionNoArg, "on"},
 
108
        {"+ejk3", ".hop.ejk3", XrmoptionNoArg, "off"},
 
109
        {"-ejk4", ".hop.ejk4", XrmoptionNoArg, "on"},
 
110
        {"+ejk4", ".hop.ejk4", XrmoptionNoArg, "off"},
 
111
        {"-ejk5", ".hop.ejk5", XrmoptionNoArg, "on"},
 
112
        {"+ejk5", ".hop.ejk5", XrmoptionNoArg, "off"},
 
113
        {"-ejk6", ".hop.ejk6", XrmoptionNoArg, "on"},
 
114
        {"+ejk6", ".hop.ejk6", XrmoptionNoArg, "off"},
 
115
        {"-rr", ".hop.rr", XrmoptionNoArg, "on"},
 
116
        {"+rr", ".hop.rr", XrmoptionNoArg, "off"},
 
117
        {"-jong", ".hop.jong", XrmoptionNoArg, "on"},
 
118
        {"+jong", ".hop.jong", XrmoptionNoArg, "off"},
 
119
        {"-sine", ".hop.sine", XrmoptionNoArg, "on"},
 
120
        {"+sine", ".hop.sine", XrmoptionNoArg, "off"}
120
121
};
121
122
static argtype vars[] =
122
123
{
123
 
        {(caddr_t *) & martin, "martin", "Martin", DEF_MARTIN, t_Bool},
124
 
        {(caddr_t *) & popcorn, "popcorn", "Popcorn", DEF_POPCORN, t_Bool},
125
 
        {(caddr_t *) & ejk1, "ejk1", "EJK1", DEF_EJK1, t_Bool},
126
 
        {(caddr_t *) & ejk2, "ejk2", "EJK2", DEF_EJK2, t_Bool},
127
 
        {(caddr_t *) & ejk3, "ejk3", "EJK3", DEF_EJK3, t_Bool},
128
 
        {(caddr_t *) & ejk4, "ejk4", "EJK4", DEF_EJK4, t_Bool},
129
 
        {(caddr_t *) & ejk5, "ejk5", "EJK5", DEF_EJK5, t_Bool},
130
 
        {(caddr_t *) & ejk6, "ejk6", "EJK6", DEF_EJK6, t_Bool},
131
 
        {(caddr_t *) & rr, "rr", "RR", DEF_RR, t_Bool},
132
 
        {(caddr_t *) & jong, "jong", "Jong", DEF_JONG, t_Bool},
133
 
        {(caddr_t *) & sine, "sine", "Sine", DEF_SINE, t_Bool}
 
124
        {&martin,  "martin",  "Martin",  DEF_MARTIN,  t_Bool},
 
125
        {&popcorn, "popcorn", "Popcorn", DEF_POPCORN, t_Bool},
 
126
        {&ejk1, "ejk1", "EJK1", DEF_EJK1, t_Bool},
 
127
        {&ejk2, "ejk2", "EJK2", DEF_EJK2, t_Bool},
 
128
        {&ejk3, "ejk3", "EJK3", DEF_EJK3, t_Bool},
 
129
        {&ejk4, "ejk4", "EJK4", DEF_EJK4, t_Bool},
 
130
        {&ejk5, "ejk5", "EJK5", DEF_EJK5, t_Bool},
 
131
        {&ejk6, "ejk6", "EJK6", DEF_EJK6, t_Bool},
 
132
        {&rr,   "rr",   "RR",   DEF_RR,   t_Bool},
 
133
        {&jong, "jong", "Jong", DEF_JONG, t_Bool},
 
134
        {&sine, "sine", "Sine", DEF_SINE, t_Bool}
134
135
};
135
136
static OptionStruct desc[] =
136
137
{
142
143
        {"-/+ejk4", "turn on/off ejk4 format"},
143
144
        {"-/+ejk5", "turn on/off ejk5 format"},
144
145
        {"-/+ejk6", "turn on/off ejk6 format"},
145
 
        {"-/+rr", "turn on/off rr format"},
 
146
        {"-/+rr",   "turn on/off rr format"},
146
147
        {"-/+jong", "turn on/off jong format"},
147
148
        {"-/+sine", "turn on/off sine format"}
148
149
};
153
154
#ifdef USE_MODULES
154
155
ModStruct   hop_description =
155
156
{"hop", "init_hop", "draw_hop", "release_hop",
156
 
 "refresh_hop", "init_hop", NULL, &hop_opts,
 
157
 "refresh_hop", "init_hop", (char *) NULL, &hop_opts,
157
158
 10000, 1000, 2500, 1, 64, 1.0, "",
158
159
 "Shows real plane iterated fractals", 0, NULL};
159
160
 
188
189
        XPoint     *pointBuffer;        /* pointer for XDrawPoints */
189
190
} hopstruct;
190
191
 
191
 
static hopstruct *hops = NULL;
 
192
static hopstruct *hops = (hopstruct *) NULL;
192
193
 
193
194
void
194
195
init_hop(ModeInfo * mi)
195
196
{
196
197
        Display    *display = MI_DISPLAY(mi);
197
198
        GC          gc = MI_GC(mi);
198
 
        hopstruct  *hp;
199
199
        double      range;
 
200
        hopstruct  *hp;
200
201
 
201
202
        if (hops == NULL) {
202
203
                if ((hops = (hopstruct *) calloc(MI_NUM_SCREENS(mi),
379
380
                hp->pix = NRAND(MI_NPIXELS(mi));
380
381
        hp->bufsize = MI_COUNT(mi);
381
382
 
382
 
        if (!hp->pointBuffer)
383
 
                hp->pointBuffer = (XPoint *) malloc(hp->bufsize * sizeof (XPoint));
 
383
        if (hp->pointBuffer == NULL) {
 
384
                if ((hp->pointBuffer = (XPoint *) malloc(hp->bufsize *
 
385
                                sizeof (XPoint))) == NULL)
 
386
                        return;
 
387
        }
384
388
 
385
389
        MI_CLEARWINDOW(mi);
386
390
 
392
396
void
393
397
draw_hop(ModeInfo * mi)
394
398
{
395
 
        hopstruct  *hp = &hops[MI_SCREEN(mi)];
396
399
        double      oldj, oldi;
397
 
        XPoint     *xp = hp->pointBuffer;
398
 
        int         k = hp->bufsize;
 
400
        XPoint     *xp;
 
401
        int         k;
 
402
        hopstruct  *hp;
 
403
 
 
404
        if (hops == NULL)
 
405
                return;
 
406
        hp = &hops[MI_SCREEN(mi)];
 
407
        if (hp->pointBuffer == NULL)
 
408
                return;
 
409
        xp = hp->pointBuffer;
 
410
        k = hp->bufsize;
399
411
 
400
412
        MI_IS_DRAWN(mi) = True;
401
 
 
402
413
        hp->inc++;
403
414
        if (MI_NPIXELS(mi) > 2) {
404
415
                XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, hp->pix));
536
547
                for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
537
548
                        hopstruct  *hp = &hops[screen];
538
549
 
539
 
                        if (hp->pointBuffer)
 
550
                        if (hp->pointBuffer != NULL)
540
551
                                (void) free((void *) hp->pointBuffer);
541
552
                }
542
 
 
543
553
                (void) free((void *) hops);
544
 
                hops = NULL;
 
554
                hops = (hopstruct *) NULL;
545
555
        }
546
556
}
547
557
 
550
560
{
551
561
        MI_CLEARWINDOW(mi);
552
562
}
 
563
 
 
564
#endif /* MODE_hop */