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 
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 DEFAULTS	"*delay: 10000 \n" \
57 			"*count: 1000 \n" \
58 			"*cycles: 2500 \n" \
59 			"*ncolors: 200 \n" \
60 			"*fullrandom: True \n" \
61 			"*verbose: False \n" \
62 
63 # define free_hop 0
64 # define reshape_hop 0
65 # define hop_handle_event 0
66 # define SMOOTH_COLORS
67 # include "xlockmore.h"		/* in xscreensaver distribution */
68 #else /* STANDALONE */
69 # include "xlock.h"		/* in xlockmore distribution */
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 	{(void *) & martin, (char *) "martin", (char *) "Martin", (char *) DEF_MARTIN, t_Bool},
126 	{(void *) & popcorn, (char *) "popcorn", (char *) "Popcorn", (char *) DEF_POPCORN, t_Bool},
127 	{(void *) & ejk1, (char *) "ejk1", (char *) "EJK1", (char *) DEF_EJK1, t_Bool},
128 	{(void *) & ejk2, (char *) "ejk2", (char *) "EJK2", (char *) DEF_EJK2, t_Bool},
129 	{(void *) & ejk3, (char *) "ejk3", (char *) "EJK3", (char *) DEF_EJK3, t_Bool},
130 	{(void *) & ejk4, (char *) "ejk4", (char *) "EJK4", (char *) DEF_EJK4, t_Bool},
131 	{(void *) & ejk5, (char *) "ejk5", (char *) "EJK5", (char *) DEF_EJK5, t_Bool},
132 	{(void *) & ejk6, (char *) "ejk6", (char *) "EJK6", (char *) DEF_EJK6, t_Bool},
133 	{(void *) & rr, (char *) "rr", (char *) "RR", (char *) DEF_RR, t_Bool},
134 	{(void *) & jong, (char *) "jong", (char *) "Jong", (char *) DEF_JONG, t_Bool},
135 	{(void *) & 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 ENTRYPOINT 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 static void
free_hop_screen(hopstruct * hp)196 free_hop_screen(hopstruct *hp)
197 {
198 	if (hp == NULL) {
199 		return;
200 	}
201 	if (hp->pointBuffer != NULL)
202 		free(hp->pointBuffer);
203 	hp = NULL;
204 }
205 
206 ENTRYPOINT void
init_hop(ModeInfo * mi)207 init_hop(ModeInfo * mi)
208 {
209 	Display    *display = MI_DISPLAY(mi);
210 	GC          gc = MI_GC(mi);
211 	double      range;
212 	hopstruct  *hp;
213 
214 	MI_INIT(mi, hops);
215 	hp = &hops[MI_SCREEN(mi)];
216 
217 	hp->centerx = MI_WIDTH(mi) / 2;
218 	hp->centery = MI_HEIGHT(mi) / 2;
219 	/* Make the other operations less common since they are less interesting */
220 	if (MI_IS_FULLRANDOM(mi)) {
221 		hp->op = NRAND(OPS);
222 	} else {
223 		if (martin)
224 			hp->op = MARTIN;
225 		else if (popcorn)
226 			hp->op = POPCORN;
227 		else if (ejk1)
228 			hp->op = EJK1;
229 		else if (ejk2)
230 			hp->op = EJK2;
231 		else if (ejk3)
232 			hp->op = EJK3;
233 		else if (ejk4)
234 			hp->op = EJK4;
235 		else if (ejk5)
236 			hp->op = EJK5;
237 		else if (ejk6)
238 			hp->op = EJK6;
239 		else if (rr)
240 			hp->op = RR;
241 		else if (jong)
242 			hp->op = JONG;
243 		else if (sine)
244 			hp->op = SINE;
245 		else
246 			hp->op = NRAND(OPS);
247 	}
248 
249 	range = sqrt((double) hp->centerx * hp->centerx +
250 	     (double) hp->centery * hp->centery) / (1.0 + LRAND() / MAXRAND);
251 	hp->i = hp->j = 0.0;
252 	hp->inc = (int) ((LRAND() / MAXRAND) * 200) - 100;
253 #undef XMARTIN
254 	switch (hp->op) {
255 		case MARTIN:
256 #ifdef XMARTIN
257 			hp->a = (LRAND() / MAXRAND) * 1500.0 + 40.0;
258 			hp->b = (LRAND() / MAXRAND) * 17.0 + 3.0;
259 			hp->c = (LRAND() / MAXRAND) * 3000.0 + 100.0;
260 #else
261 			hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
262 			hp->b = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
263 			if (LRAND() & 1)
264 				hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
265 			else
266 				hp->c = 0.0;
267 #endif
268 			if (MI_IS_VERBOSE(mi))
269 				(void) fprintf(stdout, "sqrt a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
270 			break;
271 		case EJK1:
272 #ifdef XMARTIN
273 			hp->a = (LRAND() / MAXRAND) * 500.0;
274 			hp->c = (LRAND() / MAXRAND) * 100.0 + 10.0;
275 #else
276 			hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
277 			hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 40.0;
278 #endif
279 			hp->b = (LRAND() / MAXRAND) * 0.4;
280 			if (MI_IS_VERBOSE(mi))
281 				(void) fprintf(stdout, "ejk1 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
282 			break;
283 		case EJK2:
284 #ifdef XMARTIN
285 			hp->a = (LRAND() / MAXRAND) * 500.0;
286 #else
287 			hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
288 #endif
289 			hp->b = pow(10.0, 6.0 + (LRAND() / MAXRAND) * 24.0);
290 			if (LRAND() & 1)
291 				hp->b = -hp->b;
292 			hp->c = pow(10.0, (LRAND() / MAXRAND) * 9.0);
293 			if (LRAND() & 1)
294 				hp->c = -hp->c;
295 			if (MI_IS_VERBOSE(mi))
296 				(void) fprintf(stdout, "ejk2 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
297 			break;
298 		case EJK3:
299 #ifdef XMARTIN
300 			hp->a = (LRAND() / MAXRAND) * 500.0;
301 			hp->c = (LRAND() / MAXRAND) * 80.0 + 30.0;
302 #else
303 			hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
304 			hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 70.0;
305 #endif
306 			hp->b = (LRAND() / MAXRAND) * 0.35 + 0.5;
307 			if (MI_IS_VERBOSE(mi))
308 				(void) fprintf(stdout, "ejk3 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
309 			break;
310 		case EJK4:
311 #ifdef XMARTIN
312 			hp->a = (LRAND() / MAXRAND) * 1000.0;
313 			hp->c = (LRAND() / MAXRAND) * 40.0 + 30.0;
314 #else
315 			hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 2.0;
316 			hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 200.0;
317 #endif
318 			hp->b = (LRAND() / MAXRAND) * 9.0 + 1.0;
319 			if (MI_IS_VERBOSE(mi))
320 				(void) fprintf(stdout, "ejk4 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
321 			break;
322 		case EJK5:
323 #ifdef XMARTIN
324 			hp->a = (LRAND() / MAXRAND) * 600.0;
325 			hp->c = (LRAND() / MAXRAND) * 90.0 + 20.0;
326 #else
327 			hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 2.0;
328 			hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 200.0;
329 #endif
330 			hp->b = (LRAND() / MAXRAND) * 0.3 + 0.1;
331 			if (MI_IS_VERBOSE(mi))
332 				(void) fprintf(stdout, "ejk5 a=%g, b=%g, c=%g\n", hp->a, hp->b, hp->c);
333 			break;
334 		case EJK6:
335 #ifdef XMARTIN
336 			hp->a = (LRAND() / MAXRAND) * 100.0 + 550.0;
337 #else
338 			hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 30.0;
339 #endif
340 			hp->b = (LRAND() / MAXRAND) + 0.5;
341 			if (MI_IS_VERBOSE(mi))
342 				(void) fprintf(stdout, "ejk6 a=%g, b=%g\n", hp->a, hp->b);
343 			break;
344 		case RR:
345 #ifdef XMARTIN
346 			hp->a = (LRAND() / MAXRAND) * 100.0;
347 			hp->b = (LRAND() / MAXRAND) * 20.0;
348 			hp->c = (LRAND() / MAXRAND) * 200.0;
349 #else
350 			hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 40.0;
351 			hp->b = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 200.0;
352 			hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * range / 20.0;
353 #endif
354 			hp->d = (LRAND() / MAXRAND) * 0.9;
355 			if (MI_IS_VERBOSE(mi))
356 				(void) fprintf(stdout, "rr a=%g, b=%g, c=%g, d=%g\n",
357 					       hp->a, hp->b, hp->c, hp->d);
358 			break;
359 		case POPCORN:
360 			hp->a = 0.0;
361 			hp->b = 0.0;
362 			hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * 0.24 + 0.25;
363 			hp->inc = 100;
364 			if (MI_IS_VERBOSE(mi))
365 				(void) fprintf(stdout, "popcorn a=%g, b=%g, c=%g, d=%g\n",
366 					       hp->a, hp->b, hp->c, hp->d);
367 			break;
368 		case JONG:
369 			hp->a = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
370 			hp->b = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
371 			hp->c = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
372 			hp->d = ((LRAND() / MAXRAND) * 2.0 - 1.0) * M_PI;
373 			if (MI_IS_VERBOSE(mi))
374 				(void) fprintf(stdout, "jong a=%g, b=%g, c=%g, d=%g\n",
375 					       hp->a, hp->b, hp->c, hp->d);
376 			break;
377 		case SINE:	/* MARTIN2 */
378 #ifdef XMARTIN
379 			hp->a = M_PI + ((LRAND() / MAXRAND) * 2.0 - 1.0) * 0.07;
380 #else
381 			hp->a = M_PI + ((LRAND() / MAXRAND) * 2.0 - 1.0) * 0.7;
382 #endif
383 			if (MI_IS_VERBOSE(mi))
384 				(void) fprintf(stdout, "sine a=%g\n", hp->a);
385 			break;
386 	}
387 	if (MI_NPIXELS(mi) > 2)
388 		hp->pix = NRAND(MI_NPIXELS(mi));
389 	hp->bufsize = MI_COUNT(mi);
390 	if (hp->bufsize < 1)
391 		hp->bufsize = 1;
392 	if (hp->pointBuffer == NULL) {
393 		if ((hp->pointBuffer = (XPoint *) malloc(hp->bufsize *
394 				sizeof (XPoint))) == NULL)
395 			return;
396 	}
397 
398 	MI_CLEARWINDOW(mi);
399 
400 	XSetForeground(display, gc, MI_WHITE_PIXEL(mi));
401 	hp->count = 0;
402 }
403 
404 
405 ENTRYPOINT void
draw_hop(ModeInfo * mi)406 draw_hop(ModeInfo * mi)
407 {
408 	double      oldj, oldi;
409 	XPoint     *xp;
410 	int         k;
411 	hopstruct  *hp;
412 
413 	if (hops == NULL)
414 		return;
415 	hp = &hops[MI_SCREEN(mi)];
416 	if (hp->pointBuffer == NULL)
417 		return;
418 	xp = hp->pointBuffer;
419 	k = hp->bufsize;
420 
421 	MI_IS_DRAWN(mi) = True;
422 	hp->inc++;
423 	if (MI_NPIXELS(mi) > 2) {
424 		XSetForeground(MI_DISPLAY(mi), MI_GC(mi), MI_PIXEL(mi, hp->pix));
425 		if (++hp->pix >= MI_NPIXELS(mi))
426 			hp->pix = 0;
427 	}
428 	while (k--) {
429 		oldj = hp->j;
430 		switch (hp->op) {
431 			case MARTIN:	/* SQRT, MARTIN1 */
432 				oldi = hp->i + hp->inc;
433 				hp->j = hp->a - hp->i;
434 				hp->i = oldj + ((hp->i < 0)
435 					   ? sqrt(fabs(hp->b * oldi - hp->c))
436 					: -sqrt(fabs(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 EJK1:
441 				oldi = hp->i + hp->inc;
442 				hp->j = hp->a - hp->i;
443 				hp->i = oldj - ((hp->i > 0) ? (hp->b * oldi - hp->c) :
444 						-(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 EJK2:
449 				oldi = hp->i + hp->inc;
450 				hp->j = hp->a - hp->i;
451 				hp->i = oldj - ((hp->i < 0) ? log(fabs(hp->b * oldi - hp->c)) :
452 					   -log(fabs(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 EJK3:
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 						-sin(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 EJK4:
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 					  -sqrt(fabs(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 EJK5:
473 				oldi = hp->i + hp->inc;
474 				hp->j = hp->a - hp->i;
475 				hp->i = oldj - ((hp->i > 0) ? sin(hp->b * oldi) - hp->c :
476 						-(hp->b * oldi - hp->c));
477 				xp->x = hp->centerx + (int) (hp->i + hp->j);
478 				xp->y = hp->centery - (int) (hp->i - hp->j);
479 				break;
480 			case EJK6:
481 				oldi = hp->i + hp->inc;
482 				hp->j = hp->a - hp->i;
483 				hp->i = oldj - asin((hp->b * oldi) - (long) (hp->b * oldi));
484 				xp->x = hp->centerx + (int) (hp->i + hp->j);
485 				xp->y = hp->centery - (int) (hp->i - hp->j);
486 				break;
487 			case RR:	/* RR1 */
488 				oldi = hp->i + hp->inc;
489 				hp->j = hp->a - hp->i;
490 				hp->i = oldj - ((hp->i < 0) ? -pow(fabs(hp->b * oldi - hp->c), hp->d) :
491 				     pow(fabs(hp->b * oldi - hp->c), hp->d));
492 				xp->x = hp->centerx + (int) (hp->i + hp->j);
493 				xp->y = hp->centery - (int) (hp->i - hp->j);
494 				break;
495 			case POPCORN:
496 #define HVAL 0.05
497 #define INCVAL 50
498 				{
499 					double      tempi, tempj;
500 
501 					if (hp->inc >= 100)
502 						hp->inc = 0;
503 					if (hp->inc == 0) {
504 						if (hp->a++ >= INCVAL) {
505 							hp->a = 0;
506 							if (hp->b++ >= INCVAL)
507 								hp->b = 0;
508 						}
509 						hp->i = (-hp->c * INCVAL / 2 + hp->c * hp->a) * M_PI / 180.0;
510 						hp->j = (-hp->c * INCVAL / 2 + hp->c * hp->b) * M_PI / 180.0;
511 					}
512 					tempi = hp->i - HVAL * sin(hp->j + tan(3.0 * hp->j));
513 					tempj = hp->j - HVAL * sin(hp->i + tan(3.0 * hp->i));
514 					xp->x = hp->centerx + (int) (MI_WIDTH(mi) / 40 * tempi);
515 					xp->y = hp->centery + (int) (MI_HEIGHT(mi) / 40 * tempj);
516 					hp->i = tempi;
517 					hp->j = tempj;
518 				}
519 				break;
520 			case JONG:
521 				if (hp->centerx > 0)
522 					oldi = hp->i + 4 * hp->inc / hp->centerx;
523 				else
524 					oldi = hp->i;
525 				hp->j = sin(hp->c * hp->i) - cos(hp->d * hp->j);
526 				hp->i = sin(hp->a * oldj) - cos(hp->b * oldi);
527 				xp->x = hp->centerx + (int) (hp->centerx * (hp->i + hp->j) / 4.0);
528 				xp->y = hp->centery - (int) (hp->centery * (hp->i - hp->j) / 4.0);
529 				break;
530 			case SINE:	/* MARTIN2 */
531 				oldi = hp->i + hp->inc;
532 				hp->j = hp->a - hp->i;
533 				hp->i = oldj - sin(oldi);
534 				xp->x = hp->centerx + (int) (hp->i + hp->j);
535 				xp->y = hp->centery - (int) (hp->i - hp->j);
536 				break;
537 		}
538 		xp++;
539 	}
540 	XDrawPoints(MI_DISPLAY(mi), MI_WINDOW(mi), MI_GC(mi),
541 		    hp->pointBuffer, hp->bufsize, CoordModeOrigin);
542 	if (++hp->count > MI_CYCLES(mi)) {
543 		init_hop(mi);
544 	}
545 }
546 
547 ENTRYPOINT void
release_hop(ModeInfo * mi)548 release_hop(ModeInfo * mi)
549 {
550 	if (hops != NULL) {
551 		int         screen;
552 
553 		for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
554 			free_hop_screen(&hops[screen]);
555 		}
556 		free(hops);
557 		hops = (hopstruct *) NULL;
558 	}
559 }
560 
561 #ifndef STANDALONE
562 ENTRYPOINT void
refresh_hop(ModeInfo * mi)563 refresh_hop(ModeInfo * mi)
564 {
565 	MI_CLEARWINDOW(mi);
566 }
567 #endif
568 
569 XSCREENSAVER_MODULE ("Hop", hop)
570 
571 #endif /* MODE_hop */
572