f97f54bd0d7d86d762999436593d96ac75db7231
[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 # define SMOOTH_COLORS
60 # define reshape_hop 0
61 # define hop_handle_event 0
62 # include "xlockmore.h"         /* in xscreensaver distribution */
63 # include "erase.h"
64 #else /* STANDALONE */
65 # include "xlock.h"             /* in xlockmore distribution */
66 #endif /* STANDALONE */
67
68 #ifdef MODE_hop
69
70 #define DEF_MARTIN "False"
71 #define DEF_POPCORN "False"
72 #define DEF_EJK1 "False"
73 #define DEF_EJK2 "False"
74 #define DEF_EJK3 "False"
75 #define DEF_EJK4 "False"
76 #define DEF_EJK5 "False"
77 #define DEF_EJK6 "False"
78 #define DEF_RR "False"
79 #define DEF_JONG "False"
80 #define DEF_SINE "False"
81
82 static Bool martin;
83 static Bool popcorn;
84 static Bool ejk1;
85 static Bool ejk2;
86 static Bool ejk3;
87 static Bool ejk4;
88 static Bool ejk5;
89 static Bool ejk6;
90 static Bool rr;
91 static Bool jong;
92 static Bool sine;
93
94 static XrmOptionDescRec opts[] =
95 {
96         {"-martin", ".hop.martin", XrmoptionNoArg, "on"},
97         {"+martin", ".hop.martin", XrmoptionNoArg, "off"},
98         {"-popcorn", ".hop.popcorn", XrmoptionNoArg, "on"},
99         {"+popcorn", ".hop.popcorn", XrmoptionNoArg, "off"},
100         {"-ejk1", ".hop.ejk1", XrmoptionNoArg, "on"},
101         {"+ejk1", ".hop.ejk1", XrmoptionNoArg, "off"},
102         {"-ejk2", ".hop.ejk2", XrmoptionNoArg, "on"},
103         {"+ejk2", ".hop.ejk2", XrmoptionNoArg, "off"},
104         {"-ejk3", ".hop.ejk3", XrmoptionNoArg, "on"},
105         {"+ejk3", ".hop.ejk3", XrmoptionNoArg, "off"},
106         {"-ejk4", ".hop.ejk4", XrmoptionNoArg, "on"},
107         {"+ejk4", ".hop.ejk4", XrmoptionNoArg, "off"},
108         {"-ejk5", ".hop.ejk5", XrmoptionNoArg, "on"},
109         {"+ejk5", ".hop.ejk5", XrmoptionNoArg, "off"},
110         {"-ejk6", ".hop.ejk6", XrmoptionNoArg, "on"},
111         {"+ejk6", ".hop.ejk6", XrmoptionNoArg, "off"},
112         {"-rr", ".hop.rr", XrmoptionNoArg, "on"},
113         {"+rr", ".hop.rr", XrmoptionNoArg, "off"},
114         {"-jong", ".hop.jong", XrmoptionNoArg, "on"},
115         {"+jong", ".hop.jong", XrmoptionNoArg, "off"},
116         {"-sine", ".hop.sine", XrmoptionNoArg, "on"},
117         {"+sine", ".hop.sine", XrmoptionNoArg, "off"}
118 };
119 static argtype vars[] =
120 {
121         {&martin,  "martin",  "Martin",  DEF_MARTIN,  t_Bool},
122         {&popcorn, "popcorn", "Popcorn", DEF_POPCORN, t_Bool},
123         {&ejk1, "ejk1", "EJK1", DEF_EJK1, t_Bool},
124         {&ejk2, "ejk2", "EJK2", DEF_EJK2, t_Bool},
125         {&ejk3, "ejk3", "EJK3", DEF_EJK3, t_Bool},
126         {&ejk4, "ejk4", "EJK4", DEF_EJK4, t_Bool},
127         {&ejk5, "ejk5", "EJK5", DEF_EJK5, t_Bool},
128         {&ejk6, "ejk6", "EJK6", DEF_EJK6, t_Bool},
129         {&rr,   "rr",   "RR",   DEF_RR,   t_Bool},
130         {&jong, "jong", "Jong", DEF_JONG, t_Bool},
131         {&sine, "sine", "Sine", DEF_SINE, t_Bool}
132 };
133 static OptionStruct desc[] =
134 {
135         {"-/+martin", "turn on/off sqrt format"},
136         {"-/+popcorn", "turn on/off Clifford A. Pickover's popcorn format"},
137         {"-/+ejk1", "turn on/off ejk1 format"},
138         {"-/+ejk2", "turn on/off ejk2 format"},
139         {"-/+ejk3", "turn on/off ejk3 format"},
140         {"-/+ejk4", "turn on/off ejk4 format"},
141         {"-/+ejk5", "turn on/off ejk5 format"},
142         {"-/+ejk6", "turn on/off ejk6 format"},
143         {"-/+rr",   "turn on/off rr format"},
144         {"-/+jong", "turn on/off jong format"},
145         {"-/+sine", "turn on/off sine format"}
146 };
147
148 ENTRYPOINT ModeSpecOpt hop_opts =
149 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
150
151 #ifdef USE_MODULES
152 ModStruct   hop_description =
153 {"hop", "init_hop", "draw_hop", "release_hop",
154  "refresh_hop", "init_hop", (char *) NULL, &hop_opts,
155  10000, 1000, 2500, 1, 64, 1.0, "",
156  "Shows real plane iterated fractals", 0, NULL};
157
158 #endif
159
160 #define MARTIN 0
161 #define POPCORN 7
162 #define SINE 8
163 #define EJK1 1
164 #define EJK2 2
165 #define EJK3 9
166 #define EJK4 3
167 #define EJK5 4
168 #define EJK6 10
169 #define RR 5
170 #define JONG 6
171 #ifdef OFFENDING
172 #define OPS 8                   /* 8, 9, 10 might be too close to a swastika for some... */
173 #else
174 #define OPS 11
175 #endif
176
177 typedef struct {
178         int         centerx, centery;   /* center of the screen */
179         double      a, b, c, d;
180         double      i, j;       /* hopalong parameters */
181         int         inc;
182         int         pix;
183         int         op;
184         int         count;
185         int         bufsize;
186         XPoint     *pointBuffer;        /* pointer for XDrawPoints */
187 #ifdef STANDALONE
188   eraser_state *eraser;
189 #endif
190 } hopstruct;
191
192 static hopstruct *hops = (hopstruct *) NULL;
193
194 ENTRYPOINT void
195 init_hop(ModeInfo * mi)
196 {
197         Display    *display = MI_DISPLAY(mi);
198         GC          gc = MI_GC(mi);
199         double      range;
200         hopstruct  *hp;
201
202         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 #ifndef STANDALONE
390         MI_CLEARWINDOW(mi);
391 #endif
392
393         XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
394         hp->count = 0;
395 }
396
397
398 ENTRYPOINT void
399 draw_hop(ModeInfo * mi)
400 {
401         double      oldj, oldi;
402         XPoint     *xp;
403         int         k;
404         hopstruct  *hp;
405
406         if (hops == NULL)
407                 return;
408         hp = &hops[MI_SCREEN(mi)];
409
410 #ifdef STANDALONE
411     if (hp->eraser) {
412       hp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), hp->eraser);
413       return;
414     }
415 #endif
416
417
418         if (hp->pointBuffer == NULL)
419                 return;
420         xp = hp->pointBuffer;
421         k = hp->bufsize;
422
423         MI_IS_DRAWN(mi) = True;
424         hp->inc++;
425         if (MI_NPIXELS(mi) > 2) {
426                 XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, hp->pix));
427                 if (++hp->pix >= MI_NPIXELS(mi))
428                         hp->pix = 0;
429         }
430         while (k--) {
431                 oldj = hp->j;
432                 switch (hp->op) {
433                         case MARTIN:    /* SQRT, MARTIN1 */
434                                 oldi = hp->i + hp->inc;
435                                 hp->j = hp->a - hp->i;
436                                 hp->i = oldj + ((hp->i < 0)
437                                            ? sqrt(fabs(hp->b * oldi - hp->c))
438                                         : -sqrt(fabs(hp->b * oldi - hp->c)));
439                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
440                                 xp->y = hp->centery - (int) (hp->i - hp->j);
441                                 break;
442                         case EJK1:
443                                 oldi = hp->i + hp->inc;
444                                 hp->j = hp->a - hp->i;
445                                 hp->i = oldj - ((hp->i > 0) ? (hp->b * oldi - hp->c) :
446                                                 -(hp->b * oldi - hp->c));
447                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
448                                 xp->y = hp->centery - (int) (hp->i - hp->j);
449                                 break;
450                         case EJK2:
451                                 oldi = hp->i + hp->inc;
452                                 hp->j = hp->a - hp->i;
453                                 hp->i = oldj - ((hp->i < 0) ? log(fabs(hp->b * oldi - hp->c)) :
454                                            -log(fabs(hp->b * oldi - hp->c)));
455                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
456                                 xp->y = hp->centery - (int) (hp->i - hp->j);
457                                 break;
458                         case EJK3:
459                                 oldi = hp->i + hp->inc;
460                                 hp->j = hp->a - hp->i;
461                                 hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
462                                                 -sin(hp->b * oldi) - hp->c);
463                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
464                                 xp->y = hp->centery - (int) (hp->i - hp->j);
465                                 break;
466                         case EJK4:
467                                 oldi = hp->i + hp->inc;
468                                 hp->j = hp->a - hp->i;
469                                 hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
470                                           -sqrt(fabs(hp->b * oldi - hp->c)));
471                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
472                                 xp->y = hp->centery - (int) (hp->i - hp->j);
473                                 break;
474                         case EJK5:
475                                 oldi = hp->i + hp->inc;
476                                 hp->j = hp->a - hp->i;
477                                 hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
478                                                 -(hp->b * oldi - hp->c));
479                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
480                                 xp->y = hp->centery - (int) (hp->i - hp->j);
481                                 break;
482                         case EJK6:
483                                 oldi = hp->i + hp->inc;
484                                 hp->j = hp->a - hp->i;
485                                 hp->i = oldj - asin((hp->b * oldi) - (long) (hp->b * oldi));
486                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
487                                 xp->y = hp->centery - (int) (hp->i - hp->j);
488                                 break;
489                         case RR:        /* RR1 */
490                                 oldi = hp->i + hp->inc;
491                                 hp->j = hp->a - hp->i;
492                                 hp->i = oldj - ((hp->i < 0) ? -pow(fabs(hp->b * oldi - hp->c), hp->d) :
493                                      pow(fabs(hp->b * oldi - hp->c), hp->d));
494                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
495                                 xp->y = hp->centery - (int) (hp->i - hp->j);
496                                 break;
497                         case POPCORN:
498 #define HVAL 0.05
499 #define INCVAL 50
500                                 {
501                                         double      tempi, tempj;
502
503                                         if (hp->inc >= 100)
504                                                 hp->inc = 0;
505                                         if (hp->inc == 0) {
506                                                 if (hp->a++ >= INCVAL) {
507                                                         hp->a = 0;
508                                                         if (hp->b++ >= INCVAL)
509                                                                 hp->b = 0;
510                                                 }
511                                                 hp->i = (-hp->c * INCVAL / 2 + hp->c * hp->a) * M_PI / 180.0;
512                                                 hp->j = (-hp->c * INCVAL / 2 + hp->c * hp->b) * M_PI / 180.0;
513                                         }
514                                         tempi = hp->i - HVAL * sin(hp->j + tan(3.0 * hp->j));
515                                         tempj = hp->j - HVAL * sin(hp->i + tan(3.0 * hp->i));
516                                         xp->x = hp->centerx + (int) (MI_WIDTH(mi) / 40 * tempi);
517                                         xp->y = hp->centery + (int) (MI_HEIGHT(mi) / 40 * tempj);
518                                         hp->i = tempi;
519                                         hp->j = tempj;
520                                 }
521                                 break;
522                         case JONG:
523                                 if (hp->centerx > 0)
524                                         oldi = hp->i + 4 * hp->inc / hp->centerx;
525                                 else
526                                         oldi = hp->i;
527                                 hp->j = sin(hp->c * hp->i) - cos(hp->d * hp->j);
528                                 hp->i = sin(hp->a * oldj) - cos(hp->b * oldi);
529                                 xp->x = hp->centerx + (int) (hp->centerx * (hp->i + hp->j) / 4.0);
530                                 xp->y = hp->centery - (int) (hp->centery * (hp->i - hp->j) / 4.0);
531                                 break;
532                         case SINE:      /* MARTIN2 */
533                                 oldi = hp->i + hp->inc;
534                                 hp->j = hp->a - hp->i;
535                                 hp->i = oldj - sin(oldi);
536                                 xp->x = hp->centerx + (int) (hp->i + hp->j);
537                                 xp->y = hp->centery - (int) (hp->i - hp->j);
538                                 break;
539                 }
540                 xp++;
541         }
542         XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi),
543                     hp->pointBuffer, hp->bufsize, CoordModeOrigin);
544         if (++hp->count > MI_CYCLES(mi)) {
545 #ifdef STANDALONE
546       hp->eraser = erase_window (MI_DISPLAY(mi), MI_WINDOW(mi), hp->eraser);
547 #endif /* STANDALONE */
548                 init_hop(mi);
549         }
550 }
551
552 ENTRYPOINT void
553 release_hop(ModeInfo * mi)
554 {
555         if (hops != NULL) {
556                 int         screen;
557
558                 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
559                         hopstruct  *hp = &hops[screen];
560
561                         if (hp->pointBuffer != NULL)
562                                 (void) free((void *) hp->pointBuffer);
563                 }
564                 (void) free((void *) hops);
565                 hops = (hopstruct *) NULL;
566         }
567 }
568
569 ENTRYPOINT void
570 refresh_hop(ModeInfo * mi)
571 {
572         MI_CLEARWINDOW(mi);
573 }
574
575 XSCREENSAVER_MODULE_2 ("Hopalong", hopalong, hop)
576
577 #endif /* MODE_hop */