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