From http://www.jwz.org/xscreensaver/xscreensaver-5.38.tar.gz
[xscreensaver] / hacks / hopalong.c
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 #endif
7
8 /*-
9  * Copyright (c) 1991 by Patrick J. Naughton.
10  *
11  * Permission to use, copy, modify, and distribute this software and its
12  * documentation for any purpose and without fee is hereby granted,
13  * provided that the above copyright notice appear in all copies and that
14  * both that copyright notice and this permission notice appear in
15  * supporting documentation.
16  *
17  * This file is provided AS IS with no warranties of any kind.  The author
18  * shall have no liability with respect to the infringement of copyrights,
19  * trade secrets or any patents by this file or any part thereof.  In no
20  * event will the author be liable for any lost revenue or profits or
21  * other special, indirect and consequential damages.
22  *
23  * Revision History:
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
29  *              of the Barry Martin's square root function
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)
50  */
51
52
53 #ifdef STANDALONE
54 #define MODE_hop
55 #define DEFAULTS        "*delay: 10000 \n" \
56                                         "*count: 1000 \n" \
57                                         "*cycles: 2500 \n" \
58                                         "*ncolors: 200 \n" \
59                                         "*fpsSolid: true \n" \
60                                         "*ignoreRotation: True \n" \
61
62 # define SMOOTH_COLORS
63 # define reshape_hop 0
64 # define release_hop 0
65 # define hop_handle_event 0
66 # include "xlockmore.h"         /* in xscreensaver distribution */
67 #else /* STANDALONE */
68 # include "xlock.h"             /* in xlockmore distribution */
69 #endif /* STANDALONE */
70
71 #ifdef MODE_hop
72
73 #define DEF_MARTIN "False"
74 #define DEF_POPCORN "False"
75 #define DEF_EJK1 "False"
76 #define DEF_EJK2 "False"
77 #define DEF_EJK3 "False"
78 #define DEF_EJK4 "False"
79 #define DEF_EJK5 "False"
80 #define DEF_EJK6 "False"
81 #define DEF_RR "False"
82 #define DEF_JONG "False"
83 #define DEF_SINE "False"
84
85 static Bool martin;
86 static Bool popcorn;
87 static Bool ejk1;
88 static Bool ejk2;
89 static Bool ejk3;
90 static Bool ejk4;
91 static Bool ejk5;
92 static Bool ejk6;
93 static Bool rr;
94 static Bool jong;
95 static Bool sine;
96
97 static XrmOptionDescRec opts[] =
98 {
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"}
121 };
122 static argtype vars[] =
123 {
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}
135 };
136 static OptionStruct desc[] =
137 {
138         {"-/+martin", "turn on/off sqrt format"},
139         {"-/+popcorn", "turn on/off Clifford A. Pickover's popcorn format"},
140         {"-/+ejk1", "turn on/off ejk1 format"},
141         {"-/+ejk2", "turn on/off ejk2 format"},
142         {"-/+ejk3", "turn on/off ejk3 format"},
143         {"-/+ejk4", "turn on/off ejk4 format"},
144         {"-/+ejk5", "turn on/off ejk5 format"},
145         {"-/+ejk6", "turn on/off ejk6 format"},
146         {"-/+rr",   "turn on/off rr format"},
147         {"-/+jong", "turn on/off jong format"},
148         {"-/+sine", "turn on/off sine format"}
149 };
150
151 ENTRYPOINT ModeSpecOpt hop_opts =
152 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
153
154 #ifdef USE_MODULES
155 ModStruct   hop_description =
156 {"hop", "init_hop", "draw_hop", (char *) NULL,
157  "refresh_hop", "init_hop", "free_hop", &hop_opts,
158  10000, 1000, 2500, 1, 64, 1.0, "",
159  "Shows real plane iterated fractals", 0, NULL};
160
161 #endif
162
163 #define MARTIN 0
164 #define POPCORN 7
165 #define SINE 8
166 #define EJK1 1
167 #define EJK2 2
168 #define EJK3 9
169 #define EJK4 3
170 #define EJK5 4
171 #define EJK6 10
172 #define RR 5
173 #define JONG 6
174 #ifdef OFFENDING
175 #define OPS 8                   /* 8, 9, 10 might be too close to a swastika for some... */
176 #else
177 #define OPS 11
178 #endif
179
180 typedef struct {
181         int         centerx, centery;   /* center of the screen */
182         double      a, b, c, d;
183         double      i, j;       /* hopalong parameters */
184         int         inc;
185         int         pix;
186         int         op;
187         int         count;
188         int         bufsize;
189         XPoint     *pointBuffer;        /* pointer for XDrawPoints */
190 } hopstruct;
191
192 static hopstruct *hops = (hopstruct *) NULL;
193
194 ENTRYPOINT void
195 init_hop(ModeInfo * mi)
196 {
197         Display    *display = MI_DISPLAY(mi);
198         GC          gc = MI_GC(mi);
199         double      range;
200         hopstruct  *hp;
201
202         MI_INIT (mi, hops);
203         hp = &hops[MI_SCREEN(mi)];
204
205         hp->centerx = MI_WIDTH(mi) / 2;
206         hp->centery = MI_HEIGHT(mi) / 2;
207         /* Make the other operations less common since they are less interesting */
208         if (MI_IS_FULLRANDOM(mi)) {
209                 hp->op = NRAND(OPS);
210         } else {
211                 if (martin)
212                         hp->op = MARTIN;
213                 else if (popcorn)
214                         hp->op = POPCORN;
215                 else if (ejk1)
216                         hp->op = EJK1;
217                 else if (ejk2)
218                         hp->op = EJK2;
219                 else if (ejk3)
220                         hp->op = EJK3;
221                 else if (ejk4)
222                         hp->op = EJK4;
223                 else if (ejk5)
224                         hp->op = EJK5;
225                 else if (ejk6)
226                         hp->op = EJK6;
227                 else if (rr)
228                         hp->op = RR;
229                 else if (jong)
230                         hp->op = JONG;
231                 else if (sine)
232                         hp->op = SINE;
233                 else
234                         hp->op = NRAND(OPS);
235         }
236
237         range = sqrt((double) hp->centerx * hp->centerx +
238              (double) hp->centery * hp->centery) / (1.0 + LRAND() / MAXRAND);
239         hp->i = hp->j = 0.0;
240         hp->inc = (int) ((LRAND() / MAXRAND) * 200) - 100;
241 #undef XMARTIN
242         switch (hp->op) {
243                 case MARTIN:
244 #ifdef XMARTIN
245                         hp->a = (LRAND() / MAXRAND) * 1500.0 + 40.0;
246                         hp->b = (LRAND() / MAXRAND) * 17.0 + 3.0;
247                         hp->c = (LRAND() / MAXRAND) * 3000.0 + 100.0;
248 #else
249                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
250                         hp->b = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
251                         if (LRAND() & 1)
252                                 hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
253                         else
254                                 hp->c = 0.0;
255 #endif
256                         if (MI_IS_VERBOSE(mi))
257                                 (void) fprintf(stdout, "sqrt a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
258                         break;
259                 case EJK1:
260 #ifdef XMARTIN
261                         hp->a = (LRAND() / MAXRAND) * 500.0;
262                         hp->c = (LRAND() / MAXRAND) * 100.0 + 10.0;
263 #else
264                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
265                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 40.0;
266 #endif
267                         hp->b = (LRAND() / MAXRAND) * 0.4;
268                         if (MI_IS_VERBOSE(mi))
269                                 (void) fprintf(stdout, "ejk1 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
270                         break;
271                 case EJK2:
272 #ifdef XMARTIN
273                         hp->a = (LRAND() / MAXRAND) * 500.0;
274 #else
275                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
276 #endif
277                         hp->b = pow(10.0, 6.0 + (LRAND() / MAXRAND) * 24.0);
278                         if (LRAND() & 1)
279                                 hp->b = -hp->b;
280                         hp->c = pow(10.0, (LRAND() / MAXRAND) * 9.0);
281                         if (LRAND() & 1)
282                                 hp->c = -hp->c;
283                         if (MI_IS_VERBOSE(mi))
284                                 (void) fprintf(stdout, "ejk2 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
285                         break;
286                 case EJK3:
287 #ifdef XMARTIN
288                         hp->a = (LRAND() / MAXRAND) * 500.0;
289                         hp->c = (LRAND() / MAXRAND) * 80.0 + 30.0;
290 #else
291                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
292                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 70.0;
293 #endif
294                         hp->b = (LRAND() / MAXRAND) * 0.35 + 0.5;
295                         if (MI_IS_VERBOSE(mi))
296                                 (void) fprintf(stdout, "ejk3 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
297                         break;
298                 case EJK4:
299 #ifdef XMARTIN
300                         hp->a = (LRAND() / MAXRAND) * 1000.0;
301                         hp->c = (LRAND() / MAXRAND) * 40.0 + 30.0;
302 #else
303                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 2.0;
304                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 200.0;
305 #endif
306                         hp->b = (LRAND() / MAXRAND) * 9.0 + 1.0;
307                         if (MI_IS_VERBOSE(mi))
308                                 (void) fprintf(stdout, "ejk4 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
309                         break;
310                 case EJK5:
311 #ifdef XMARTIN
312                         hp->a = (LRAND() / MAXRAND) * 600.0;
313                         hp->c = (LRAND() / MAXRAND) * 90.0 + 20.0;
314 #else
315                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 2.0;
316                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 200.0;
317 #endif
318                         hp->b = (LRAND() / MAXRAND) * 0.3 + 0.1;
319                         if (MI_IS_VERBOSE(mi))
320                                 (void) fprintf(stdout, "ejk5 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
321                         break;
322                 case EJK6:
323 #ifdef XMARTIN
324                         hp->a = (LRAND() / MAXRAND) * 100.0 + 550.0;
325 #else
326                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
327 #endif
328                         hp->b = (LRAND() / MAXRAND) + 0.5;
329                         if (MI_IS_VERBOSE(mi))
330                                 (void) fprintf(stdout, "ejk6 a=%g, b=%g\n", hp->a, hp->b);
331                         break;
332                 case RR:
333 #ifdef XMARTIN
334                         hp->a = (LRAND() / MAXRAND) * 100.0;
335                         hp->b = (LRAND() / MAXRAND) * 20.0;
336                         hp->c = (LRAND() / MAXRAND) * 200.0;
337 #else
338                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 40.0;
339                         hp->b = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 200.0;
340                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
341 #endif
342                         hp->d = (LRAND() / MAXRAND) * 0.9;
343                         if (MI_IS_VERBOSE(mi))
344                                 (void) fprintf(stdout, "rr a=%g, b=%g, c=%g, d=%g\n",
345                                                hp->a, hp->b, hp->c, hp->d);
346                         break;
347                 case POPCORN:
348                         hp->a = 0.0;
349                         hp->b = 0.0;
350                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * 0.24 + 0.25;
351                         hp->inc = 100;
352                         if (MI_IS_VERBOSE(mi))
353                                 (void) fprintf(stdout, "popcorn a=%g, b=%g, c=%g, d=%g\n",
354                                                hp->a, hp->b, hp->c, hp->d);
355                         break;
356                 case JONG:
357                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
358                         hp->b = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
359                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
360                         hp->d = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
361                         if (MI_IS_VERBOSE(mi))
362                                 (void) fprintf(stdout, "jong a=%g, b=%g, c=%g, d=%g\n",
363                                                hp->a, hp->b, hp->c, hp->d);
364                         break;
365                 case SINE:      /* MARTIN2 */
366 #ifdef XMARTIN
367                         hp->a = M_PI + ((LRAND() / MAXRAND) * 2.0 - 1.0) * 0.07;
368 #else
369                         hp->a = M_PI + ((LRAND() / MAXRAND) * 2.0 - 1.0) * 0.7;
370 #endif
371                         if (MI_IS_VERBOSE(mi))
372                                 (void) fprintf(stdout, "sine a=%g\n", hp->a);
373                         break;
374         }
375         if (MI_NPIXELS(mi) > 2)
376                 hp->pix = NRAND(MI_NPIXELS(mi));
377         hp->bufsize = MI_COUNT(mi);
378
379         if (hp->pointBuffer == NULL) {
380                 if ((hp->pointBuffer = (XPoint *) malloc(hp->bufsize *
381                                 sizeof (XPoint))) == NULL)
382                         return;
383         }
384
385         MI_CLEARWINDOW(mi);
386
387         XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
388         hp->count = 0;
389 }
390
391
392 ENTRYPOINT void
393 draw_hop(ModeInfo * mi)
394 {
395         double      oldj, oldi;
396         XPoint     *xp;
397         int         k;
398         hopstruct  *hp;
399
400         if (hops == NULL)
401                 return;
402         hp = &hops[MI_SCREEN(mi)];
403
404
405         if (hp->pointBuffer == NULL)
406                 return;
407         xp = hp->pointBuffer;
408         k = hp->bufsize;
409
410         MI_IS_DRAWN(mi) = True;
411         hp->inc++;
412         if (MI_NPIXELS(mi) > 2) {
413                 XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, hp->pix));
414                 if (++hp->pix >= MI_NPIXELS(mi))
415                         hp->pix = 0;
416         }
417         while (k--) {
418                 oldj = hp->j;
419                 switch (hp->op) {
420                         case MARTIN:    /* SQRT, MARTIN1 */
421                                 oldi = hp->i + hp->inc;
422                                 hp->j = hp->a - hp->i;
423                                 hp->i = oldj + ((hp->i < 0)
424                                            ? sqrt(fabs(hp->b * oldi - hp->c))
425                                         : -sqrt(fabs(hp->b * oldi - hp->c)));
426                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
427                                 xp->y = hp->centery - (int) (hp->i - hp->j);
428                                 break;
429                         case EJK1:
430                                 oldi = hp->i + hp->inc;
431                                 hp->j = hp->a - hp->i;
432                                 hp->i = oldj - ((hp->i > 0) ? (hp->b * oldi - hp->c) :
433                                                 -(hp->b * oldi - hp->c));
434                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
435                                 xp->y = hp->centery - (int) (hp->i - hp->j);
436                                 break;
437                         case EJK2:
438                                 oldi = hp->i + hp->inc;
439                                 hp->j = hp->a - hp->i;
440                                 hp->i = oldj - ((hp->i < 0) ? log(fabs(hp->b * oldi - hp->c)) :
441                                            -log(fabs(hp->b * oldi - hp->c)));
442                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
443                                 xp->y = hp->centery - (int) (hp->i - hp->j);
444                                 break;
445                         case EJK3:
446                                 oldi = hp->i + hp->inc;
447                                 hp->j = hp->a - hp->i;
448                                 hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
449                                                 -sin(hp->b * oldi) - hp->c);
450                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
451                                 xp->y = hp->centery - (int) (hp->i - hp->j);
452                                 break;
453                         case EJK4:
454                                 oldi = hp->i + hp->inc;
455                                 hp->j = hp->a - hp->i;
456                                 hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
457                                           -sqrt(fabs(hp->b * oldi - hp->c)));
458                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
459                                 xp->y = hp->centery - (int) (hp->i - hp->j);
460                                 break;
461                         case EJK5:
462                                 oldi = hp->i + hp->inc;
463                                 hp->j = hp->a - hp->i;
464                                 hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
465                                                 -(hp->b * oldi - hp->c));
466                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
467                                 xp->y = hp->centery - (int) (hp->i - hp->j);
468                                 break;
469                         case EJK6:
470                                 oldi = hp->i + hp->inc;
471                                 hp->j = hp->a - hp->i;
472                                 hp->i = oldj - asin((hp->b * oldi) - (long) (hp->b * oldi));
473                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
474                                 xp->y = hp->centery - (int) (hp->i - hp->j);
475                                 break;
476                         case RR:        /* RR1 */
477                                 oldi = hp->i + hp->inc;
478                                 hp->j = hp->a - hp->i;
479                                 hp->i = oldj - ((hp->i < 0) ? -pow(fabs(hp->b * oldi - hp->c), hp->d) :
480                                      pow(fabs(hp->b * oldi - hp->c), hp->d));
481                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
482                                 xp->y = hp->centery - (int) (hp->i - hp->j);
483                                 break;
484                         case POPCORN:
485 #define HVAL 0.05
486 #define INCVAL 50
487                                 {
488                                         double      tempi, tempj;
489
490                                         if (hp->inc >= 100)
491                                                 hp->inc = 0;
492                                         if (hp->inc == 0) {
493                                                 if (hp->a++ >= INCVAL) {
494                                                         hp->a = 0;
495                                                         if (hp->b++ >= INCVAL)
496                                                                 hp->b = 0;
497                                                 }
498                                                 hp->i = (-hp->c * INCVAL / 2 + hp->c * hp->a) * M_PI / 180.0;
499                                                 hp->j = (-hp->c * INCVAL / 2 + hp->c * hp->b) * M_PI / 180.0;
500                                         }
501                                         tempi = hp->i - HVAL * sin(hp->j + tan(3.0 * hp->j));
502                                         tempj = hp->j - HVAL * sin(hp->i + tan(3.0 * hp->i));
503                                         xp->x = hp->centerx + (int) (MI_WIDTH(mi) / 40 * tempi);
504                                         xp->y = hp->centery + (int) (MI_HEIGHT(mi) / 40 * tempj);
505                                         hp->i = tempi;
506                                         hp->j = tempj;
507                                 }
508                                 break;
509                         case JONG:
510                                 if (hp->centerx > 0)
511                                         oldi = hp->i + 4 * hp->inc / hp->centerx;
512                                 else
513                                         oldi = hp->i;
514                                 hp->j = sin(hp->c * hp->i) - cos(hp->d * hp->j);
515                                 hp->i = sin(hp->a * oldj) - cos(hp->b * oldi);
516                                 xp->x = hp->centerx + (int) (hp->centerx * (hp->i + hp->j) / 4.0);
517                                 xp->y = hp->centery - (int) (hp->centery * (hp->i - hp->j) / 4.0);
518                                 break;
519                         case SINE:      /* MARTIN2 */
520                                 oldi = hp->i + hp->inc;
521                                 hp->j = hp->a - hp->i;
522                                 hp->i = oldj - sin(oldi);
523                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
524                                 xp->y = hp->centery - (int) (hp->i - hp->j);
525                                 break;
526                 }
527                 xp++;
528         }
529         XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi),
530                     hp->pointBuffer, hp->bufsize, CoordModeOrigin);
531         if (++hp->count > MI_CYCLES(mi)) {
532                 init_hop(mi);
533         }
534 }
535
536 ENTRYPOINT void
537 free_hop(ModeInfo * mi)
538 {
539         hopstruct  *hp = &hops[MI_SCREEN(mi)];
540
541         if (hp->pointBuffer != NULL)
542                 (void) free((void *) hp->pointBuffer);
543 }
544
545 #ifndef STANDALONE
546 ENTRYPOINT void
547 refresh_hop(ModeInfo * mi)
548 {
549         MI_CLEARWINDOW(mi);
550 }
551 #endif
552
553 XSCREENSAVER_MODULE_2 ("Hopalong", hopalong, hop)
554
555 #endif /* MODE_hop */