7b252e87d77c0e2cb8e39830e3e952b68c1bf61c
[xscreensaver] / hacks / hopalong.c
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";
6 #endif
7
8 /* Copyright (c) 1988-91 by Patrick J. Naughton.
9  *
10  * Permission to use, copy, modify, and distribute this software and its
11  * documentation for any purpose and without fee is hereby granted,
12  * provided that the above copyright notice appear in all copies and that
13  * both that copyright notice and this permission notice appear in
14  * supporting documentation.
15  *
16  * This file is provided AS IS with no warranties of any kind.  The author
17  * shall have no liability with respect to the infringement of copyrights,
18  * trade secrets or any patents by this file or any part thereof.  In no
19  * event will the author be liable for any lost revenue or profits or
20  * other special, indirect and consequential damages.
21  *
22  * 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
27  *              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)
53  */
54
55 #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 */
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, (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"}
120 };
121 static argtype vars[] =
122 {
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}
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 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", 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 } hopstruct;
190
191 static hopstruct *hops = NULL;
192
193 void
194 init_hop(ModeInfo * mi)
195 {
196         Display    *display = MI_DISPLAY(mi);
197         GC          gc = MI_GC(mi);
198         hopstruct  *hp;
199         double      range;
200
201         if (hops == NULL) {
202                 if ((hops = (hopstruct *) calloc(MI_NUM_SCREENS(mi),
203                                                  sizeof (hopstruct))) == NULL)
204                         return;
205         }
206         hp = &hops[MI_SCREEN(mi)];
207
208         hp->centerx = MI_WIDTH(mi) / 2;
209         hp->centery = MI_HEIGHT(mi) / 2;
210         /* Make the other operations less common since they are less interesting */
211         if (MI_IS_FULLRANDOM(mi)) {
212                 hp->op = NRAND(OPS);
213         } else {
214                 if (martin)
215                         hp->op = MARTIN;
216                 else if (popcorn)
217                         hp->op = POPCORN;
218                 else if (ejk1)
219                         hp->op = EJK1;
220                 else if (ejk2)
221                         hp->op = EJK2;
222                 else if (ejk3)
223                         hp->op = EJK3;
224                 else if (ejk4)
225                         hp->op = EJK4;
226                 else if (ejk5)
227                         hp->op = EJK5;
228                 else if (ejk6)
229                         hp->op = EJK6;
230                 else if (rr)
231                         hp->op = RR;
232                 else if (jong)
233                         hp->op = JONG;
234                 else if (sine)
235                         hp->op = SINE;
236                 else
237                         hp->op = NRAND(OPS);
238         }
239
240         range = sqrt((double) hp->centerx * hp->centerx +
241              (double) hp->centery * hp->centery) / (1.0 + LRAND() / MAXRAND);
242         hp->i = hp->j = 0.0;
243         hp->inc = (int) ((LRAND() / MAXRAND) * 200) - 100;
244 #undef XMARTIN
245         switch (hp->op) {
246                 case MARTIN:
247 #ifdef XMARTIN
248                         hp->a = (LRAND() / MAXRAND) * 1500.0 + 40.0;
249                         hp->b = (LRAND() / MAXRAND) * 17.0 + 3.0;
250                         hp->c = (LRAND() / MAXRAND) * 3000.0 + 100.0;
251 #else
252                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
253                         hp->b = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
254                         if (LRAND() & 1)
255                                 hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
256                         else
257                                 hp->c = 0.0;
258 #endif
259                         if (MI_IS_VERBOSE(mi))
260                                 (void) fprintf(stdout, "sqrt a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
261                         break;
262                 case EJK1:
263 #ifdef XMARTIN
264                         hp->a = (LRAND() / MAXRAND) * 500.0;
265                         hp->c = (LRAND() / MAXRAND) * 100.0 + 10.0;
266 #else
267                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
268                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 40.0;
269 #endif
270                         hp->b = (LRAND() / MAXRAND) * 0.4;
271                         if (MI_IS_VERBOSE(mi))
272                                 (void) fprintf(stdout, "ejk1 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
273                         break;
274                 case EJK2:
275 #ifdef XMARTIN
276                         hp->a = (LRAND() / MAXRAND) * 500.0;
277 #else
278                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
279 #endif
280                         hp->b = pow(10.0, 6.0 + (LRAND() / MAXRAND) * 24.0);
281                         if (LRAND() & 1)
282                                 hp->b = -hp->b;
283                         hp->c = pow(10.0, (LRAND() / MAXRAND) * 9.0);
284                         if (LRAND() & 1)
285                                 hp->c = -hp->c;
286                         if (MI_IS_VERBOSE(mi))
287                                 (void) fprintf(stdout, "ejk2 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
288                         break;
289                 case EJK3:
290 #ifdef XMARTIN
291                         hp->a = (LRAND() / MAXRAND) * 500.0;
292                         hp->c = (LRAND() / MAXRAND) * 80.0 + 30.0;
293 #else
294                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
295                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 70.0;
296 #endif
297                         hp->b = (LRAND() / MAXRAND) * 0.35 + 0.5;
298                         if (MI_IS_VERBOSE(mi))
299                                 (void) fprintf(stdout, "ejk3 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
300                         break;
301                 case EJK4:
302 #ifdef XMARTIN
303                         hp->a = (LRAND() / MAXRAND) * 1000.0;
304                         hp->c = (LRAND() / MAXRAND) * 40.0 + 30.0;
305 #else
306                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 2.0;
307                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 200.0;
308 #endif
309                         hp->b = (LRAND() / MAXRAND) * 9.0 + 1.0;
310                         if (MI_IS_VERBOSE(mi))
311                                 (void) fprintf(stdout, "ejk4 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
312                         break;
313                 case EJK5:
314 #ifdef XMARTIN
315                         hp->a = (LRAND() / MAXRAND) * 600.0;
316                         hp->c = (LRAND() / MAXRAND) * 90.0 + 20.0;
317 #else
318                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 2.0;
319                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 200.0;
320 #endif
321                         hp->b = (LRAND() / MAXRAND) * 0.3 + 0.1;
322                         if (MI_IS_VERBOSE(mi))
323                                 (void) fprintf(stdout, "ejk5 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
324                         break;
325                 case EJK6:
326 #ifdef XMARTIN
327                         hp->a = (LRAND() / MAXRAND) * 100.0 + 550.0;
328 #else
329                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
330 #endif
331                         hp->b = (LRAND() / MAXRAND) + 0.5;
332                         if (MI_IS_VERBOSE(mi))
333                                 (void) fprintf(stdout, "ejk6 a=%g, b=%g\n", hp->a, hp->b);
334                         break;
335                 case RR:
336 #ifdef XMARTIN
337                         hp->a = (LRAND() / MAXRAND) * 100.0;
338                         hp->b = (LRAND() / MAXRAND) * 20.0;
339                         hp->c = (LRAND() / MAXRAND) * 200.0;
340 #else
341                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 40.0;
342                         hp->b = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 200.0;
343                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
344 #endif
345                         hp->d = (LRAND() / MAXRAND) * 0.9;
346                         if (MI_IS_VERBOSE(mi))
347                                 (void) fprintf(stdout, "rr a=%g, b=%g, c=%g, d=%g\n",
348                                                hp->a, hp->b, hp->c, hp->d);
349                         break;
350                 case POPCORN:
351                         hp->a = 0.0;
352                         hp->b = 0.0;
353                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * 0.24 + 0.25;
354                         hp->inc = 100;
355                         if (MI_IS_VERBOSE(mi))
356                                 (void) fprintf(stdout, "popcorn a=%g, b=%g, c=%g, d=%g\n",
357                                                hp->a, hp->b, hp->c, hp->d);
358                         break;
359                 case JONG:
360                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
361                         hp->b = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
362                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
363                         hp->d = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
364                         if (MI_IS_VERBOSE(mi))
365                                 (void) fprintf(stdout, "jong a=%g, b=%g, c=%g, d=%g\n",
366                                                hp->a, hp->b, hp->c, hp->d);
367                         break;
368                 case SINE:      /* MARTIN2 */
369 #ifdef XMARTIN
370                         hp->a = M_PI + ((LRAND() / MAXRAND) * 2.0 - 1.0) * 0.07;
371 #else
372                         hp->a = M_PI + ((LRAND() / MAXRAND) * 2.0 - 1.0) * 0.7;
373 #endif
374                         if (MI_IS_VERBOSE(mi))
375                                 (void) fprintf(stdout, "sine a=%g\n", hp->a);
376                         break;
377         }
378         if (MI_NPIXELS(mi) > 2)
379                 hp->pix = NRAND(MI_NPIXELS(mi));
380         hp->bufsize = MI_COUNT(mi);
381
382         if (!hp->pointBuffer)
383                 hp->pointBuffer = (XPoint *) malloc(hp->bufsize * sizeof (XPoint));
384
385         MI_CLEARWINDOW(mi);
386
387         XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
388         hp->count = 0;
389 }
390
391
392 void
393 draw_hop(ModeInfo * mi)
394 {
395         hopstruct  *hp = &hops[MI_SCREEN(mi)];
396         double      oldj, oldi;
397         XPoint     *xp = hp->pointBuffer;
398         int         k = hp->bufsize;
399
400         MI_IS_DRAWN(mi) = True;
401
402         hp->inc++;
403         if (MI_NPIXELS(mi) > 2) {
404                 XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, hp->pix));
405                 if (++hp->pix >= MI_NPIXELS(mi))
406                         hp->pix = 0;
407         }
408         while (k--) {
409                 oldj = hp->j;
410                 switch (hp->op) {
411                         case MARTIN:    /* SQRT, MARTIN1 */
412                                 oldi = hp->i + hp->inc;
413                                 hp->j = hp->a - hp->i;
414                                 hp->i = oldj + ((hp->i < 0)
415                                            ? sqrt(fabs(hp->b * oldi - hp->c))
416                                         : -sqrt(fabs(hp->b * oldi - hp->c)));
417                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
418                                 xp->y = hp->centery - (int) (hp->i - hp->j);
419                                 break;
420                         case EJK1:
421                                 oldi = hp->i + hp->inc;
422                                 hp->j = hp->a - hp->i;
423                                 hp->i = oldj - ((hp->i > 0) ? (hp->b * oldi - hp->c) :
424                                                 -(hp->b * oldi - hp->c));
425                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
426                                 xp->y = hp->centery - (int) (hp->i - hp->j);
427                                 break;
428                         case EJK2:
429                                 oldi = hp->i + hp->inc;
430                                 hp->j = hp->a - hp->i;
431                                 hp->i = oldj - ((hp->i < 0) ? log(fabs(hp->b * oldi - hp->c)) :
432                                            -log(fabs(hp->b * oldi - hp->c)));
433                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
434                                 xp->y = hp->centery - (int) (hp->i - hp->j);
435                                 break;
436                         case EJK3:
437                                 oldi = hp->i + hp->inc;
438                                 hp->j = hp->a - hp->i;
439                                 hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
440                                                 -sin(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 EJK4:
445                                 oldi = hp->i + hp->inc;
446                                 hp->j = hp->a - hp->i;
447                                 hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
448                                           -sqrt(fabs(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 EJK5:
453                                 oldi = hp->i + hp->inc;
454                                 hp->j = hp->a - hp->i;
455                                 hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
456                                                 -(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 EJK6:
461                                 oldi = hp->i + hp->inc;
462                                 hp->j = hp->a - hp->i;
463                                 hp->i = oldj - asin((hp->b * oldi) - (long) (hp->b * oldi));
464                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
465                                 xp->y = hp->centery - (int) (hp->i - hp->j);
466                                 break;
467                         case RR:        /* RR1 */
468                                 oldi = hp->i + hp->inc;
469                                 hp->j = hp->a - hp->i;
470                                 hp->i = oldj - ((hp->i < 0) ? -pow(fabs(hp->b * oldi - hp->c), hp->d) :
471                                      pow(fabs(hp->b * oldi - hp->c), hp->d));
472                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
473                                 xp->y = hp->centery - (int) (hp->i - hp->j);
474                                 break;
475                         case POPCORN:
476 #define HVAL 0.05
477 #define INCVAL 50
478                                 {
479                                         double      tempi, tempj;
480
481                                         if (hp->inc >= 100)
482                                                 hp->inc = 0;
483                                         if (hp->inc == 0) {
484                                                 if (hp->a++ >= INCVAL) {
485                                                         hp->a = 0;
486                                                         if (hp->b++ >= INCVAL)
487                                                                 hp->b = 0;
488                                                 }
489                                                 hp->i = (-hp->c * INCVAL / 2 + hp->c * hp->a) * M_PI / 180.0;
490                                                 hp->j = (-hp->c * INCVAL / 2 + hp->c * hp->b) * M_PI / 180.0;
491                                         }
492                                         tempi = hp->i - HVAL * sin(hp->j + tan(3.0 * hp->j));
493                                         tempj = hp->j - HVAL * sin(hp->i + tan(3.0 * hp->i));
494                                         xp->x = hp->centerx + (int) (MI_WIDTH(mi) / 40 * tempi);
495                                         xp->y = hp->centery + (int) (MI_HEIGHT(mi) / 40 * tempj);
496                                         hp->i = tempi;
497                                         hp->j = tempj;
498                                 }
499                                 break;
500                         case JONG:
501                                 if (hp->centerx > 0)
502                                         oldi = hp->i + 4 * hp->inc / hp->centerx;
503                                 else
504                                         oldi = hp->i;
505                                 hp->j = sin(hp->c * hp->i) - cos(hp->d * hp->j);
506                                 hp->i = sin(hp->a * oldj) - cos(hp->b * oldi);
507                                 xp->x = hp->centerx + (int) (hp->centerx * (hp->i + hp->j) / 4.0);
508                                 xp->y = hp->centery - (int) (hp->centery * (hp->i - hp->j) / 4.0);
509                                 break;
510                         case SINE:      /* MARTIN2 */
511                                 oldi = hp->i + hp->inc;
512                                 hp->j = hp->a - hp->i;
513                                 hp->i = oldj - sin(oldi);
514                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
515                                 xp->y = hp->centery - (int) (hp->i - hp->j);
516                                 break;
517                 }
518                 xp++;
519         }
520         XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi),
521                     hp->pointBuffer, hp->bufsize, CoordModeOrigin);
522         if (++hp->count > MI_CYCLES(mi)) {
523 #ifdef STANDALONE
524             erase_full_window(MI_DISPLAY(mi), MI_WINDOW(mi));
525 #endif /* STANDALONE */
526                 init_hop(mi);
527         }
528 }
529
530 void
531 release_hop(ModeInfo * mi)
532 {
533         if (hops != NULL) {
534                 int         screen;
535
536                 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
537                         hopstruct  *hp = &hops[screen];
538
539                         if (hp->pointBuffer)
540                                 (void) free((void *) hp->pointBuffer);
541                 }
542
543                 (void) free((void *) hops);
544                 hops = NULL;
545         }
546 }
547
548 void
549 refresh_hop(ModeInfo * mi)
550 {
551         MI_CLEARWINDOW(mi);
552 }