502c73dbeb2f04fa853f4bc4108be05ff62e0641
[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 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
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         {(char *) "-martin", (char *) ".hop.martin", XrmoptionNoArg, (caddr_t) "on"},
100         {(char *) "+martin", (char *) ".hop.martin", XrmoptionNoArg, (caddr_t) "off"},
101         {(char *) "-popcorn", (char *) ".hop.popcorn", XrmoptionNoArg, (caddr_t) "on"},
102         {(char *) "+popcorn", (char *) ".hop.popcorn", XrmoptionNoArg, (caddr_t) "off"},
103         {(char *) "-ejk1", (char *) ".hop.ejk1", XrmoptionNoArg, (caddr_t) "on"},
104         {(char *) "+ejk1", (char *) ".hop.ejk1", XrmoptionNoArg, (caddr_t) "off"},
105         {(char *) "-ejk2", (char *) ".hop.ejk2", XrmoptionNoArg, (caddr_t) "on"},
106         {(char *) "+ejk2", (char *) ".hop.ejk2", XrmoptionNoArg, (caddr_t) "off"},
107         {(char *) "-ejk3", (char *) ".hop.ejk3", XrmoptionNoArg, (caddr_t) "on"},
108         {(char *) "+ejk3", (char *) ".hop.ejk3", XrmoptionNoArg, (caddr_t) "off"},
109         {(char *) "-ejk4", (char *) ".hop.ejk4", XrmoptionNoArg, (caddr_t) "on"},
110         {(char *) "+ejk4", (char *) ".hop.ejk4", XrmoptionNoArg, (caddr_t) "off"},
111         {(char *) "-ejk5", (char *) ".hop.ejk5", XrmoptionNoArg, (caddr_t) "on"},
112         {(char *) "+ejk5", (char *) ".hop.ejk5", XrmoptionNoArg, (caddr_t) "off"},
113         {(char *) "-ejk6", (char *) ".hop.ejk6", XrmoptionNoArg, (caddr_t) "on"},
114         {(char *) "+ejk6", (char *) ".hop.ejk6", XrmoptionNoArg, (caddr_t) "off"},
115         {(char *) "-rr", (char *) ".hop.rr", XrmoptionNoArg, (caddr_t) "on"},
116         {(char *) "+rr", (char *) ".hop.rr", XrmoptionNoArg, (caddr_t) "off"},
117         {(char *) "-jong", (char *) ".hop.jong", XrmoptionNoArg, (caddr_t) "on"},
118         {(char *) "+jong", (char *) ".hop.jong", XrmoptionNoArg, (caddr_t) "off"},
119         {(char *) "-sine", (char *) ".hop.sine", XrmoptionNoArg, (caddr_t) "on"},
120         {(char *) "+sine", (char *) ".hop.sine", XrmoptionNoArg, (caddr_t) "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         {(char *) "-/+martin", (char *) "turn on/off sqrt format"},
139         {(char *) "-/+popcorn", (char *) "turn on/off Clifford A. Pickover's popcorn format"},
140         {(char *) "-/+ejk1", (char *) "turn on/off ejk1 format"},
141         {(char *) "-/+ejk2", (char *) "turn on/off ejk2 format"},
142         {(char *) "-/+ejk3", (char *) "turn on/off ejk3 format"},
143         {(char *) "-/+ejk4", (char *) "turn on/off ejk4 format"},
144         {(char *) "-/+ejk5", (char *) "turn on/off ejk5 format"},
145         {(char *) "-/+ejk6", (char *) "turn on/off ejk6 format"},
146         {(char *) "-/+rr", (char *) "turn on/off rr format"},
147         {(char *) "-/+jong", (char *) "turn on/off jong format"},
148         {(char *) "-/+sine", (char *) "turn on/off sine format"}
149 };
150
151 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", "release_hop",
157  "refresh_hop", "init_hop", (char *) NULL, &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 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         if (hops == NULL) {
203                 if ((hops = (hopstruct *) calloc(MI_NUM_SCREENS(mi),
204                                                  sizeof (hopstruct))) == NULL)
205                         return;
206         }
207         hp = &hops[MI_SCREEN(mi)];
208
209         hp->centerx = MI_WIDTH(mi) / 2;
210         hp->centery = MI_HEIGHT(mi) / 2;
211         /* Make the other operations less common since they are less interesting */
212         if (MI_IS_FULLRANDOM(mi)) {
213                 hp->op = NRAND(OPS);
214         } else {
215                 if (martin)
216                         hp->op = MARTIN;
217                 else if (popcorn)
218                         hp->op = POPCORN;
219                 else if (ejk1)
220                         hp->op = EJK1;
221                 else if (ejk2)
222                         hp->op = EJK2;
223                 else if (ejk3)
224                         hp->op = EJK3;
225                 else if (ejk4)
226                         hp->op = EJK4;
227                 else if (ejk5)
228                         hp->op = EJK5;
229                 else if (ejk6)
230                         hp->op = EJK6;
231                 else if (rr)
232                         hp->op = RR;
233                 else if (jong)
234                         hp->op = JONG;
235                 else if (sine)
236                         hp->op = SINE;
237                 else
238                         hp->op = NRAND(OPS);
239         }
240
241         range = sqrt((double) hp->centerx * hp->centerx +
242              (double) hp->centery * hp->centery) / (1.0 + LRAND() / MAXRAND);
243         hp->i = hp->j = 0.0;
244         hp->inc = (int) ((LRAND() / MAXRAND) * 200) - 100;
245 #undef XMARTIN
246         switch (hp->op) {
247                 case MARTIN:
248 #ifdef XMARTIN
249                         hp->a = (LRAND() / MAXRAND) * 1500.0 + 40.0;
250                         hp->b = (LRAND() / MAXRAND) * 17.0 + 3.0;
251                         hp->c = (LRAND() / MAXRAND) * 3000.0 + 100.0;
252 #else
253                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
254                         hp->b = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
255                         if (LRAND() & 1)
256                                 hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
257                         else
258                                 hp->c = 0.0;
259 #endif
260                         if (MI_IS_VERBOSE(mi))
261                                 (void) fprintf(stdout, "sqrt a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
262                         break;
263                 case EJK1:
264 #ifdef XMARTIN
265                         hp->a = (LRAND() / MAXRAND) * 500.0;
266                         hp->c = (LRAND() / MAXRAND) * 100.0 + 10.0;
267 #else
268                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
269                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 40.0;
270 #endif
271                         hp->b = (LRAND() / MAXRAND) * 0.4;
272                         if (MI_IS_VERBOSE(mi))
273                                 (void) fprintf(stdout, "ejk1 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
274                         break;
275                 case EJK2:
276 #ifdef XMARTIN
277                         hp->a = (LRAND() / MAXRAND) * 500.0;
278 #else
279                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
280 #endif
281                         hp->b = pow(10.0, 6.0 + (LRAND() / MAXRAND) * 24.0);
282                         if (LRAND() & 1)
283                                 hp->b = -hp->b;
284                         hp->c = pow(10.0, (LRAND() / MAXRAND) * 9.0);
285                         if (LRAND() & 1)
286                                 hp->c = -hp->c;
287                         if (MI_IS_VERBOSE(mi))
288                                 (void) fprintf(stdout, "ejk2 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
289                         break;
290                 case EJK3:
291 #ifdef XMARTIN
292                         hp->a = (LRAND() / MAXRAND) * 500.0;
293                         hp->c = (LRAND() / MAXRAND) * 80.0 + 30.0;
294 #else
295                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
296                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 70.0;
297 #endif
298                         hp->b = (LRAND() / MAXRAND) * 0.35 + 0.5;
299                         if (MI_IS_VERBOSE(mi))
300                                 (void) fprintf(stdout, "ejk3 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
301                         break;
302                 case EJK4:
303 #ifdef XMARTIN
304                         hp->a = (LRAND() / MAXRAND) * 1000.0;
305                         hp->c = (LRAND() / MAXRAND) * 40.0 + 30.0;
306 #else
307                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 2.0;
308                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 200.0;
309 #endif
310                         hp->b = (LRAND() / MAXRAND) * 9.0 + 1.0;
311                         if (MI_IS_VERBOSE(mi))
312                                 (void) fprintf(stdout, "ejk4 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
313                         break;
314                 case EJK5:
315 #ifdef XMARTIN
316                         hp->a = (LRAND() / MAXRAND) * 600.0;
317                         hp->c = (LRAND() / MAXRAND) * 90.0 + 20.0;
318 #else
319                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 2.0;
320                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 200.0;
321 #endif
322                         hp->b = (LRAND() / MAXRAND) * 0.3 + 0.1;
323                         if (MI_IS_VERBOSE(mi))
324                                 (void) fprintf(stdout, "ejk5 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
325                         break;
326                 case EJK6:
327 #ifdef XMARTIN
328                         hp->a = (LRAND() / MAXRAND) * 100.0 + 550.0;
329 #else
330                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
331 #endif
332                         hp->b = (LRAND() / MAXRAND) + 0.5;
333                         if (MI_IS_VERBOSE(mi))
334                                 (void) fprintf(stdout, "ejk6 a=%g, b=%g\n", hp->a, hp->b);
335                         break;
336                 case RR:
337 #ifdef XMARTIN
338                         hp->a = (LRAND() / MAXRAND) * 100.0;
339                         hp->b = (LRAND() / MAXRAND) * 20.0;
340                         hp->c = (LRAND() / MAXRAND) * 200.0;
341 #else
342                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 40.0;
343                         hp->b = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 200.0;
344                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
345 #endif
346                         hp->d = (LRAND() / MAXRAND) * 0.9;
347                         if (MI_IS_VERBOSE(mi))
348                                 (void) fprintf(stdout, "rr a=%g, b=%g, c=%g, d=%g\n",
349                                                hp->a, hp->b, hp->c, hp->d);
350                         break;
351                 case POPCORN:
352                         hp->a = 0.0;
353                         hp->b = 0.0;
354                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * 0.24 + 0.25;
355                         hp->inc = 100;
356                         if (MI_IS_VERBOSE(mi))
357                                 (void) fprintf(stdout, "popcorn a=%g, b=%g, c=%g, d=%g\n",
358                                                hp->a, hp->b, hp->c, hp->d);
359                         break;
360                 case JONG:
361                         hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
362                         hp->b = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
363                         hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
364                         hp->d = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
365                         if (MI_IS_VERBOSE(mi))
366                                 (void) fprintf(stdout, "jong a=%g, b=%g, c=%g, d=%g\n",
367                                                hp->a, hp->b, hp->c, hp->d);
368                         break;
369                 case SINE:      /* MARTIN2 */
370 #ifdef XMARTIN
371                         hp->a = M_PI + ((LRAND() / MAXRAND) * 2.0 - 1.0) * 0.07;
372 #else
373                         hp->a = M_PI + ((LRAND() / MAXRAND) * 2.0 - 1.0) * 0.7;
374 #endif
375                         if (MI_IS_VERBOSE(mi))
376                                 (void) fprintf(stdout, "sine a=%g\n", hp->a);
377                         break;
378         }
379         if (MI_NPIXELS(mi) > 2)
380                 hp->pix = NRAND(MI_NPIXELS(mi));
381         hp->bufsize = MI_COUNT(mi);
382
383         if (hp->pointBuffer == NULL) {
384                 if ((hp->pointBuffer = (XPoint *) malloc(hp->bufsize *
385                                 sizeof (XPoint))) == NULL)
386                         return;
387         }
388
389         MI_CLEARWINDOW(mi);
390
391         XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
392         hp->count = 0;
393 }
394
395
396 void
397 draw_hop(ModeInfo * mi)
398 {
399         double      oldj, oldi;
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;
411
412         MI_IS_DRAWN(mi) = True;
413         hp->inc++;
414         if (MI_NPIXELS(mi) > 2) {
415                 XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, hp->pix));
416                 if (++hp->pix >= MI_NPIXELS(mi))
417                         hp->pix = 0;
418         }
419         while (k--) {
420                 oldj = hp->j;
421                 switch (hp->op) {
422                         case MARTIN:    /* SQRT, MARTIN1 */
423                                 oldi = hp->i + hp->inc;
424                                 hp->j = hp->a - hp->i;
425                                 hp->i = oldj + ((hp->i < 0)
426                                            ? sqrt(fabs(hp->b * oldi - hp->c))
427                                         : -sqrt(fabs(hp->b * oldi - hp->c)));
428                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
429                                 xp->y = hp->centery - (int) (hp->i - hp->j);
430                                 break;
431                         case EJK1:
432                                 oldi = hp->i + hp->inc;
433                                 hp->j = hp->a - hp->i;
434                                 hp->i = oldj - ((hp->i > 0) ? (hp->b * oldi - hp->c) :
435                                                 -(hp->b * oldi - hp->c));
436                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
437                                 xp->y = hp->centery - (int) (hp->i - hp->j);
438                                 break;
439                         case EJK2:
440                                 oldi = hp->i + hp->inc;
441                                 hp->j = hp->a - hp->i;
442                                 hp->i = oldj - ((hp->i < 0) ? log(fabs(hp->b * oldi - hp->c)) :
443                                            -log(fabs(hp->b * oldi - hp->c)));
444                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
445                                 xp->y = hp->centery - (int) (hp->i - hp->j);
446                                 break;
447                         case EJK3:
448                                 oldi = hp->i + hp->inc;
449                                 hp->j = hp->a - hp->i;
450                                 hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
451                                                 -sin(hp->b * oldi) - hp->c);
452                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
453                                 xp->y = hp->centery - (int) (hp->i - hp->j);
454                                 break;
455                         case EJK4:
456                                 oldi = hp->i + hp->inc;
457                                 hp->j = hp->a - hp->i;
458                                 hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
459                                           -sqrt(fabs(hp->b * oldi - hp->c)));
460                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
461                                 xp->y = hp->centery - (int) (hp->i - hp->j);
462                                 break;
463                         case EJK5:
464                                 oldi = hp->i + hp->inc;
465                                 hp->j = hp->a - hp->i;
466                                 hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
467                                                 -(hp->b * oldi - hp->c));
468                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
469                                 xp->y = hp->centery - (int) (hp->i - hp->j);
470                                 break;
471                         case EJK6:
472                                 oldi = hp->i + hp->inc;
473                                 hp->j = hp->a - hp->i;
474                                 hp->i = oldj - asin((hp->b * oldi) - (long) (hp->b * oldi));
475                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
476                                 xp->y = hp->centery - (int) (hp->i - hp->j);
477                                 break;
478                         case RR:        /* RR1 */
479                                 oldi = hp->i + hp->inc;
480                                 hp->j = hp->a - hp->i;
481                                 hp->i = oldj - ((hp->i < 0) ? -pow(fabs(hp->b * oldi - hp->c), hp->d) :
482                                      pow(fabs(hp->b * oldi - hp->c), hp->d));
483                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
484                                 xp->y = hp->centery - (int) (hp->i - hp->j);
485                                 break;
486                         case POPCORN:
487 #define HVAL 0.05
488 #define INCVAL 50
489                                 {
490                                         double      tempi, tempj;
491
492                                         if (hp->inc >= 100)
493                                                 hp->inc = 0;
494                                         if (hp->inc == 0) {
495                                                 if (hp->a++ >= INCVAL) {
496                                                         hp->a = 0;
497                                                         if (hp->b++ >= INCVAL)
498                                                                 hp->b = 0;
499                                                 }
500                                                 hp->i = (-hp->c * INCVAL / 2 + hp->c * hp->a) * M_PI / 180.0;
501                                                 hp->j = (-hp->c * INCVAL / 2 + hp->c * hp->b) * M_PI / 180.0;
502                                         }
503                                         tempi = hp->i - HVAL * sin(hp->j + tan(3.0 * hp->j));
504                                         tempj = hp->j - HVAL * sin(hp->i + tan(3.0 * hp->i));
505                                         xp->x = hp->centerx + (int) (MI_WIDTH(mi) / 40 * tempi);
506                                         xp->y = hp->centery + (int) (MI_HEIGHT(mi) / 40 * tempj);
507                                         hp->i = tempi;
508                                         hp->j = tempj;
509                                 }
510                                 break;
511                         case JONG:
512                                 if (hp->centerx > 0)
513                                         oldi = hp->i + 4 * hp->inc / hp->centerx;
514                                 else
515                                         oldi = hp->i;
516                                 hp->j = sin(hp->c * hp->i) - cos(hp->d * hp->j);
517                                 hp->i = sin(hp->a * oldj) - cos(hp->b * oldi);
518                                 xp->x = hp->centerx + (int) (hp->centerx * (hp->i + hp->j) / 4.0);
519                                 xp->y = hp->centery - (int) (hp->centery * (hp->i - hp->j) / 4.0);
520                                 break;
521                         case SINE:      /* MARTIN2 */
522                                 oldi = hp->i + hp->inc;
523                                 hp->j = hp->a - hp->i;
524                                 hp->i = oldj - sin(oldi);
525                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
526                                 xp->y = hp->centery - (int) (hp->i - hp->j);
527                                 break;
528                 }
529                 xp++;
530         }
531         XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi),
532                     hp->pointBuffer, hp->bufsize, CoordModeOrigin);
533         if (++hp->count > MI_CYCLES(mi)) {
534 #ifdef STANDALONE
535             erase_full_window(MI_DISPLAY(mi), MI_WINDOW(mi));
536 #endif /* STANDALONE */
537                 init_hop(mi);
538         }
539 }
540
541 void
542 release_hop(ModeInfo * mi)
543 {
544         if (hops != NULL) {
545                 int         screen;
546
547                 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
548                         hopstruct  *hp = &hops[screen];
549
550                         if (hp->pointBuffer != NULL)
551                                 (void) free((void *) hp->pointBuffer);
552                 }
553                 (void) free((void *) hops);
554                 hops = (hopstruct *) NULL;
555         }
556 }
557
558 void
559 refresh_hop(ModeInfo * mi)
560 {
561         MI_CLEARWINDOW(mi);
562 }
563
564 #endif /* MODE_hop */