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