1 /* nerverot, nervous rotation of random thingies, v1.3
2 * by Dan Bornstein, danfuzz@milk.com
3 * Copyright (c) 2000-2001 Dan Bornstein. All rights reserved.
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation. No representations are made about the suitability of this
10 * software for any purpose. It is provided "as is" without express or
13 * The goal of this screensaver is to be interesting and compelling to
14 * watch, yet induce a state of nervous edginess in the viewer.
16 * See the included man page for more details.
20 #include "screenhack.h"
24 /* random float in the range (-1..1) */
25 #define RAND_FLOAT_PM1 \
26 (((FLOAT) ((random() >> 8) & 0xffff)) / ((FLOAT) 0x10000) * 2 - 1)
28 /* random float in the range (0..1) */
29 #define RAND_FLOAT_01 \
30 (((FLOAT) ((random() >> 8) & 0xffff)) / ((FLOAT) 0x10000))
34 /* parameters that are user configurable */
37 static int requestedBlotCount;
39 /* delay (usec) between iterations */
42 /* max iterations per model */
45 /* variability of xoff/yoff per iteration (0..1) */
46 static FLOAT nervousness;
48 /* max nervousness radius (0..1) */
49 static FLOAT maxNerveRadius;
51 /* chance per iteration that an event will happen */
52 static FLOAT eventChance;
54 /* fraction (0..1) towards rotation target or scale target to move each
58 /* min and max scale for drawing, as fraction of baseScale */
59 static FLOAT minScale;
60 static FLOAT maxScale;
62 /* min and max radius of blot drawing */
66 /* the number of colors to use */
67 static int colorCount;
72 /* whether or not to do double-buffering */
73 static Bool doubleBuffer;
77 /* non-user-modifiable immutable definitions */
79 /* base scale factor for drawing, calculated as
80 * max(screenWidth,screenHeight) */
83 /* width and height of the window */
84 static int windowWidth;
85 static int windowHeight;
87 /* center position of the window */
91 static Display *display; /* the display to draw on */
92 static Window window; /* the window to draw on */
93 static Drawable drawable; /* the thing to directly draw on */
94 static GC *gcs; /* array of gcs, one per color used */
98 /* structure of the model */
100 /* each point-like thingy to draw is represented as a blot */
101 typedef struct blot_s
103 FLOAT x; /* 3d x position (-1..1) */
104 FLOAT y; /* 3d y position (-1..1) */
105 FLOAT z; /* 3d z position (-1..1) */
106 FLOAT xoff[3][3]; /* display x offset per drawn point (-1..1) */
107 FLOAT yoff[3][3]; /* display x offset per drawn point (-1..1) */
110 /* each drawn line is represented as a LineSegment */
111 typedef struct linesegment_s
120 /* array of the blots in the model */
121 static Blot *blots = NULL;
122 static int blotCount;
124 /* each blot draws as a simple 2d shape with each coordinate as an int
125 * in the range (-1..1); this is the base shape */
126 static XPoint blotShape[] = { { 0, 0}, { 1, 0}, { 1, 1},
127 { 0, 1}, {-1, 1}, {-1, 0},
128 {-1,-1}, { 0,-1}, { 1,-1} };
129 static int blotShapeCount = sizeof (blotShape) / sizeof (XPoint);
131 /* two arrays of line segments; one for the ones to erase, and one for the
134 static LineSegment *segsToDraw = NULL;
135 static LineSegment *segsToErase = NULL;
137 /* current rotation values per axis, scale factor, and light position */
141 static FLOAT curScale;
146 /* target rotation values per axis, scale factor, and light position */
147 static FLOAT xRotTarget;
148 static FLOAT yRotTarget;
149 static FLOAT zRotTarget;
150 static FLOAT scaleTarget;
151 static FLOAT lightXTarget;
152 static FLOAT lightYTarget;
153 static FLOAT lightZTarget;
155 /* current absolute offsets from the center */
156 static int centerXOff = 0;
157 static int centerYOff = 0;
159 /* iterations until the model changes */
160 static int itersTillNext;
168 /* initialize a blot with the given coordinates and random display offsets */
169 static void initBlot (Blot *b, FLOAT x, FLOAT y, FLOAT z)
177 for (i = 0; i < 3; i++)
179 for (j = 0; j < 3; j++)
181 b->xoff[i][j] = RAND_FLOAT_PM1;
182 b->yoff[i][j] = RAND_FLOAT_PM1;
187 /* scale the blots to have a max distance of 1 from the center */
188 static void scaleBlotsToRadius1 (void)
193 for (n = 0; n < blotCount; n++)
196 blots[n].x * blots[n].x +
197 blots[n].y * blots[n].y +
198 blots[n].z * blots[n].z;
199 if (distSquare > max)
212 for (n = 0; n < blotCount; n++)
220 /* randomly reorder the blots */
221 static void randomlyReorderBlots (void)
225 for (n = 0; n < blotCount; n++)
227 int m = RAND_FLOAT_01 * (blotCount - n) + n;
228 Blot tmpBlot = blots[n];
234 /* set up the initial array of blots to be a at the edge of a sphere */
235 static void setupBlotsSphere (void)
239 blotCount = requestedBlotCount;
240 blots = calloc (sizeof (Blot), blotCount);
242 for (n = 0; n < blotCount; n++)
244 /* pick a spot, but reject if its radius is < 0.2 or > 1 to
245 * avoid scaling problems */
246 FLOAT x, y, z, radius;
254 radius = sqrt (x * x + y * y + z * z);
255 if ((radius >= 0.2) && (radius <= 1.0))
265 initBlot (&blots[n], x, y, z);
271 /* set up the initial array of blots to be a simple cube */
272 static void setupBlotsCube (void)
276 /* derive blotsPerEdge from blotCount, but then do the reverse
277 * since roundoff may have changed blotCount */
278 int blotsPerEdge = ((requestedBlotCount - 8) / 12) + 2;
281 if (blotsPerEdge < 2)
286 distBetween = 2.0 / (blotsPerEdge - 1.0);
288 blotCount = 8 + (blotsPerEdge - 2) * 12;
289 blots = calloc (sizeof (Blot), blotCount);
292 /* define the corners */
293 for (i = -1; i < 2; i += 2)
295 for (j = -1; j < 2; j += 2)
297 for (k = -1; k < 2; k += 2)
299 initBlot (&blots[n], i, j, k);
305 /* define the edges */
306 for (i = 1; i < (blotsPerEdge - 1); i++)
308 FLOAT varEdge = distBetween * i - 1;
309 initBlot (&blots[n++], varEdge, -1, -1);
310 initBlot (&blots[n++], varEdge, 1, -1);
311 initBlot (&blots[n++], varEdge, -1, 1);
312 initBlot (&blots[n++], varEdge, 1, 1);
313 initBlot (&blots[n++], -1, varEdge, -1);
314 initBlot (&blots[n++], 1, varEdge, -1);
315 initBlot (&blots[n++], -1, varEdge, 1);
316 initBlot (&blots[n++], 1, varEdge, 1);
317 initBlot (&blots[n++], -1, -1, varEdge);
318 initBlot (&blots[n++], 1, -1, varEdge);
319 initBlot (&blots[n++], -1, 1, varEdge);
320 initBlot (&blots[n++], 1, 1, varEdge);
323 scaleBlotsToRadius1 ();
324 randomlyReorderBlots ();
329 /* set up the initial array of blots to be a cylinder */
330 static void setupBlotsCylinder (void)
334 /* derive blotsPerEdge from blotCount, but then do the reverse
335 * since roundoff may have changed blotCount */
336 int blotsPerEdge = requestedBlotCount / 32;
339 if (blotsPerEdge < 2)
344 distBetween = 2.0 / (blotsPerEdge - 1);
346 blotCount = blotsPerEdge * 32;
347 blots = calloc (sizeof (Blot), blotCount);
350 /* define the edges */
351 for (i = 0; i < 32; i++)
353 FLOAT x = sin (2 * M_PI / 32 * i);
354 FLOAT y = cos (2 * M_PI / 32 * i);
355 for (j = 0; j < blotsPerEdge; j++)
357 initBlot (&blots[n], x, y, j * distBetween - 1);
362 scaleBlotsToRadius1 ();
363 randomlyReorderBlots ();
368 /* set up the initial array of blots to be a squiggle */
369 static void setupBlotsSquiggle (void)
371 FLOAT x, y, z, xv, yv, zv, len;
372 int minCoor, maxCoor;
375 blotCount = requestedBlotCount;
376 blots = calloc (sizeof (Blot), blotCount);
378 maxCoor = (int) (RAND_FLOAT_01 * 5) + 1;
388 len = sqrt (xv * xv + yv * yv + zv * zv);
393 for (n = 0; n < blotCount; n++)
395 FLOAT newx, newy, newz;
396 initBlot (&blots[n], x, y, z);
400 xv += RAND_FLOAT_PM1 * 0.1;
401 yv += RAND_FLOAT_PM1 * 0.1;
402 zv += RAND_FLOAT_PM1 * 0.1;
403 len = sqrt (xv * xv + yv * yv + zv * zv);
412 if ( (newx >= minCoor) && (newx <= maxCoor)
413 && (newy >= minCoor) && (newy <= maxCoor)
414 && (newz >= minCoor) && (newz <= maxCoor))
425 scaleBlotsToRadius1 ();
426 randomlyReorderBlots ();
431 /* set up the initial array of blots to be near the corners of a
432 * cube, distributed slightly */
433 static void setupBlotsCubeCorners (void)
437 blotCount = requestedBlotCount;
438 blots = calloc (sizeof (Blot), blotCount);
440 for (n = 0; n < blotCount; n++)
442 FLOAT x = rint (RAND_FLOAT_01) * 2 - 1;
443 FLOAT y = rint (RAND_FLOAT_01) * 2 - 1;
444 FLOAT z = rint (RAND_FLOAT_01) * 2 - 1;
446 x += RAND_FLOAT_PM1 * 0.3;
447 y += RAND_FLOAT_PM1 * 0.3;
448 z += RAND_FLOAT_PM1 * 0.3;
450 initBlot (&blots[n], x, y, z);
453 scaleBlotsToRadius1 ();
458 /* set up the initial array of blots to be randomly distributed
459 * on the surface of a tetrahedron */
460 static void setupBlotsTetrahedron (void)
462 /* table of corners of the tetrahedron */
463 static FLOAT cor[4][3] = { { 0.0, 1.0, 0.0 },
464 { -0.75, -0.5, -0.433013 },
465 { 0.0, -0.5, 0.866025 },
466 { 0.75, -0.5, -0.433013 } };
470 /* derive blotsPerSurface from blotCount, but then do the reverse
471 * since roundoff may have changed blotCount */
472 int blotsPerSurface = requestedBlotCount / 4;
474 blotCount = blotsPerSurface * 4;
475 blots = calloc (sizeof (Blot), blotCount);
477 for (n = 0; n < blotCount; n += 4)
479 /* pick a random point on a unit right triangle */
480 FLOAT rawx = RAND_FLOAT_01;
481 FLOAT rawy = RAND_FLOAT_01;
483 if ((rawx + rawy) > 1)
485 /* swap coords into place */
486 FLOAT t = 1.0 - rawx;
491 /* translate the point to be on each of the surfaces */
492 for (c = 0; c < 4; c++)
496 int c1 = (c + 1) % 4;
497 int c2 = (c + 2) % 4;
499 x = (cor[c1][0] - cor[c][0]) * rawx +
500 (cor[c2][0] - cor[c][0]) * rawy +
503 y = (cor[c1][1] - cor[c][1]) * rawx +
504 (cor[c2][1] - cor[c][1]) * rawy +
507 z = (cor[c1][2] - cor[c][2]) * rawx +
508 (cor[c2][2] - cor[c][2]) * rawy +
511 initBlot (&blots[n + c], x, y, z);
518 /* forward declaration for recursive use immediately below */
519 static void setupBlots (void);
521 /* set up the blots to be two of the other choices, placed next to
523 static void setupBlotsDuo (void)
525 int origRequest = requestedBlotCount;
526 FLOAT tx, ty, tz, radius;
527 Blot *blots1, *blots2;
531 if (requestedBlotCount < 15)
533 /* special case bottom-out */
541 radius = sqrt (tx * tx + ty * ty + tz * tz);
546 /* recursive call to setup set 1 */
547 requestedBlotCount = origRequest / 2;
550 if (blotCount >= origRequest)
552 /* return immediately if this satisfies the original count request */
553 requestedBlotCount = origRequest;
562 /* translate to new position */
563 for (n = 0; n < count1; n++)
570 /* recursive call to setup set 2 */
571 requestedBlotCount = origRequest - count1;
576 /* translate to new position */
577 for (n = 0; n < count2; n++)
584 /* combine the two arrays */
585 blotCount = count1 + count2;
586 blots = calloc (sizeof (Blot), blotCount);
587 memcpy (&blots[0], blots1, sizeof (Blot) * count1);
588 memcpy (&blots[count1], blots2, sizeof (Blot) * count2);
592 scaleBlotsToRadius1 ();
593 randomlyReorderBlots ();
595 /* restore the original requested count, for future iterations */
596 requestedBlotCount = origRequest;
601 /* free the blots, in preparation for a new shape */
602 static void freeBlots (void)
610 if (segsToErase != NULL)
616 if (segsToDraw != NULL)
625 /* set up the initial arrays of blots */
626 static void setupBlots (void)
628 int which = RAND_FLOAT_01 * 8;
641 setupBlotsCylinder ();
644 setupBlotsSquiggle ();
647 setupBlotsCubeCorners ();
650 setupBlotsTetrahedron ();
661 /* set up the segments arrays */
662 static void setupSegs (void)
664 /* there are blotShapeCount - 1 line segments per blot */
665 segCount = blotCount * (blotShapeCount - 1);
666 segsToErase = calloc (sizeof (LineSegment), segCount);
667 segsToDraw = calloc (sizeof (LineSegment), segCount);
669 /* erase the world */
670 XFillRectangle (display, drawable, gcs[0], 0, 0,
671 windowWidth, windowHeight);
680 /* set up the colormap */
681 static void setupColormap (XWindowAttributes *xgwa)
685 XColor *colors = (XColor *) calloc (sizeof (XColor), colorCount + 1);
687 unsigned short r, g, b;
689 double s1, s2, v1, v2;
691 r = RAND_FLOAT_01 * 0x10000;
692 g = RAND_FLOAT_01 * 0x10000;
693 b = RAND_FLOAT_01 * 0x10000;
694 rgb_to_hsv (r, g, b, &h1, &s1, &v1);
698 r = RAND_FLOAT_01 * 0x10000;
699 g = RAND_FLOAT_01 * 0x10000;
700 b = RAND_FLOAT_01 * 0x10000;
701 rgb_to_hsv (r, g, b, &h2, &s2, &v2);
705 colors[0].pixel = get_pixel_resource ("background", "Background",
706 display, xgwa->colormap);
708 make_color_ramp (display, xgwa->colormap, h1, s1, v1, h2, s2, v2,
709 colors + 1, &colorCount, False, True, False);
713 fprintf (stderr, "%s: couldn't allocate any colors\n", progname);
717 gcs = (GC *) calloc (sizeof (GC), colorCount + 1);
719 for (n = 0; n <= colorCount; n++)
721 gcv.foreground = colors[n].pixel;
722 gcv.line_width = lineWidth;
723 gcs[n] = XCreateGC (display, window, GCForeground | GCLineWidth, &gcv);
732 * overall setup stuff
735 /* set up the system */
736 static void setup (void)
738 XWindowAttributes xgwa;
740 XGetWindowAttributes (display, window, &xgwa);
742 windowWidth = xgwa.width;
743 windowHeight = xgwa.height;
744 centerX = windowWidth / 2;
745 centerY = windowHeight / 2;
746 baseScale = (xgwa.height < xgwa.width) ? xgwa.height : xgwa.width;
750 drawable = XCreatePixmap (display, window, xgwa.width, xgwa.height,
758 setupColormap (&xgwa);
762 /* set up the initial rotation, scale, and light values as random, but
763 * with the targets equal to where it is */
764 xRot = xRotTarget = RAND_FLOAT_01 * M_PI;
765 yRot = yRotTarget = RAND_FLOAT_01 * M_PI;
766 zRot = zRotTarget = RAND_FLOAT_01 * M_PI;
767 curScale = scaleTarget = RAND_FLOAT_01 * (maxScale - minScale) + minScale;
768 lightX = lightXTarget = RAND_FLOAT_PM1;
769 lightY = lightYTarget = RAND_FLOAT_PM1;
770 lightZ = lightZTarget = RAND_FLOAT_PM1;
772 itersTillNext = RAND_FLOAT_01 * maxIters;
781 /* "render" the blots into segsToDraw, with the current rotation factors */
782 static void renderSegs (void)
787 /* rotation factors */
788 FLOAT sinX = sin (xRot);
789 FLOAT cosX = cos (xRot);
790 FLOAT sinY = sin (yRot);
791 FLOAT cosY = cos (yRot);
792 FLOAT sinZ = sin (zRot);
793 FLOAT cosZ = cos (zRot);
795 for (n = 0; n < blotCount; n++)
805 FLOAT x1 = blots[n].x;
806 FLOAT y1 = blots[n].y;
807 FLOAT z1 = blots[n].z;
810 /* rotate on z axis */
811 x2 = x1 * cosZ - y1 * sinZ;
812 y2 = x1 * sinZ + y1 * cosZ;
815 /* rotate on x axis */
816 y1 = y2 * cosX - z2 * sinX;
817 z1 = y2 * sinX + z2 * cosX;
820 /* rotate on y axis */
821 z2 = z1 * cosY - x1 * sinY;
822 x2 = z1 * sinY + x1 * cosY;
825 /* the color to draw is based on the distance from the light of
826 * the post-rotation blot */
830 color = 1 + (x1 * x1 + y1 * y1 + z1 * z1) / 4 * colorCount;
831 if (color > colorCount)
836 /* set up the base screen coordinates for drawing */
837 baseX = x2 / 2 * baseScale * curScale + centerX + centerXOff;
838 baseY = y2 / 2 * baseScale * curScale + centerY + centerYOff;
840 radius = (z2 + 1) / 2 * (maxRadius - minRadius) + minRadius;
842 for (i = 0; i < 3; i++)
844 for (j = 0; j < 3; j++)
847 ((i - 1) + (b->xoff[i][j] * maxNerveRadius)) * radius;
849 ((j - 1) + (b->yoff[i][j] * maxNerveRadius)) * radius;
853 for (i = 1; i < blotShapeCount; i++)
855 segsToDraw[m].gc = gcs[color];
856 segsToDraw[m].x1 = x[blotShape[i-1].x + 1][blotShape[i-1].y + 1];
857 segsToDraw[m].y1 = y[blotShape[i-1].x + 1][blotShape[i-1].y + 1];
858 segsToDraw[m].x2 = x[blotShape[i].x + 1][blotShape[i].y + 1];
859 segsToDraw[m].y2 = y[blotShape[i].x + 1][blotShape[i].y + 1];
865 /* update blots, adjusting the offsets and rotation factors. */
866 static void updateWithFeeling (void)
870 /* pick a new model if the time is right */
872 if (itersTillNext < 0)
874 itersTillNext = RAND_FLOAT_01 * maxIters;
880 /* update the rotation factors by moving them a bit toward the targets */
881 xRot = xRot + (xRotTarget - xRot) * iterAmt;
882 yRot = yRot + (yRotTarget - yRot) * iterAmt;
883 zRot = zRot + (zRotTarget - zRot) * iterAmt;
885 /* similarly the scale factor */
886 curScale = curScale + (scaleTarget - curScale) * iterAmt;
888 /* and similarly the light position */
889 lightX = lightX + (lightXTarget - lightX) * iterAmt;
890 lightY = lightY + (lightYTarget - lightY) * iterAmt;
891 lightZ = lightZ + (lightZTarget - lightZ) * iterAmt;
893 /* for each blot... */
894 for (n = 0; n < blotCount; n++)
896 /* add a bit of random jitter to xoff/yoff */
897 for (i = 0; i < 3; i++)
899 for (j = 0; j < 3; j++)
903 newOff = blots[n].xoff[i][j] + RAND_FLOAT_PM1 * nervousness;
904 if (newOff < -1) newOff = -(newOff + 1) - 1;
905 else if (newOff > 1) newOff = -(newOff - 1) + 1;
906 blots[n].xoff[i][j] = newOff;
908 newOff = blots[n].yoff[i][j] + RAND_FLOAT_PM1 * nervousness;
909 if (newOff < -1) newOff = -(newOff + 1) - 1;
910 else if (newOff > 1) newOff = -(newOff - 1) + 1;
911 blots[n].yoff[i][j] = newOff;
916 /* depending on random chance, update one or more factors */
917 if (RAND_FLOAT_01 <= eventChance)
919 int which = RAND_FLOAT_01 * 14;
924 xRotTarget = RAND_FLOAT_PM1 * M_PI * 2;
929 yRotTarget = RAND_FLOAT_PM1 * M_PI * 2;
934 zRotTarget = RAND_FLOAT_PM1 * M_PI * 2;
939 xRotTarget = RAND_FLOAT_PM1 * M_PI * 2;
940 yRotTarget = RAND_FLOAT_PM1 * M_PI * 2;
945 xRotTarget = RAND_FLOAT_PM1 * M_PI * 2;
946 zRotTarget = RAND_FLOAT_PM1 * M_PI * 2;
951 yRotTarget = RAND_FLOAT_PM1 * M_PI * 2;
952 zRotTarget = RAND_FLOAT_PM1 * M_PI * 2;
957 xRotTarget = RAND_FLOAT_PM1 * M_PI * 2;
958 yRotTarget = RAND_FLOAT_PM1 * M_PI * 2;
959 zRotTarget = RAND_FLOAT_PM1 * M_PI * 2;
964 centerXOff = RAND_FLOAT_PM1 * maxRadius;
969 centerYOff = RAND_FLOAT_PM1 * maxRadius;
974 centerXOff = RAND_FLOAT_PM1 * maxRadius;
975 centerYOff = RAND_FLOAT_PM1 * maxRadius;
981 RAND_FLOAT_01 * (maxScale - minScale) + minScale;
987 RAND_FLOAT_01 * (maxScale - minScale) + minScale;
992 lightX = RAND_FLOAT_PM1;
993 lightY = RAND_FLOAT_PM1;
994 lightZ = RAND_FLOAT_PM1;
999 lightXTarget = RAND_FLOAT_PM1;
1000 lightYTarget = RAND_FLOAT_PM1;
1001 lightZTarget = RAND_FLOAT_PM1;
1008 /* erase segsToErase and draw segsToDraw */
1009 static void eraseAndDraw (void)
1013 for (n = 0; n < segCount; n++)
1015 LineSegment *seg = &segsToErase[n];
1016 XDrawLine (display, drawable, gcs[0],
1017 seg->x1, seg->y1, seg->x2, seg->y2);
1018 seg = &segsToDraw[n];
1019 XDrawLine (display, drawable, seg->gc,
1020 seg->x1, seg->y1, seg->x2, seg->y2);
1025 XCopyArea (display, drawable, window, gcs[0], 0, 0,
1026 windowWidth, windowHeight, 0, 0);
1030 /* do one iteration */
1031 static void oneIteration (void)
1033 /* switch segsToErase and segsToDraw */
1034 LineSegment *temp = segsToDraw;
1035 segsToDraw = segsToErase;
1038 /* update the model */
1039 updateWithFeeling ();
1041 /* render new segments */
1044 /* erase old segments and draw new ones */
1048 char *progclass = "NerveRot";
1050 char *defaults [] = {
1051 ".background: black",
1052 ".foreground: white",
1057 "*doubleBuffer: false",
1058 "*eventChance: 0.2",
1065 "*maxNerveRadius: 0.7",
1066 "*nervousness: 0.3",
1070 XrmOptionDescRec options [] = {
1071 { "-count", ".count", XrmoptionSepArg, 0 },
1072 { "-colors", ".colors", XrmoptionSepArg, 0 },
1073 { "-delay", ".delay", XrmoptionSepArg, 0 },
1074 { "-max-iters", ".maxIters", XrmoptionSepArg, 0 },
1075 { "-db", ".doubleBuffer", XrmoptionNoArg, "true" },
1076 { "-no-db", ".doubleBuffer", XrmoptionNoArg, "false" },
1077 { "-event-chance", ".eventChance", XrmoptionSepArg, 0 },
1078 { "-iter-amt", ".iterAmt", XrmoptionSepArg, 0 },
1079 { "-line-width", ".lineWidth", XrmoptionSepArg, 0 },
1080 { "-min-scale", ".minScale", XrmoptionSepArg, 0 },
1081 { "-max-scale", ".maxScale", XrmoptionSepArg, 0 },
1082 { "-min-radius", ".minRadius", XrmoptionSepArg, 0 },
1083 { "-max-radius", ".maxRadius", XrmoptionSepArg, 0 },
1084 { "-max-nerve-radius", ".maxNerveRadius", XrmoptionSepArg, 0 },
1085 { "-nervousness", ".nervousness", XrmoptionSepArg, 0 },
1089 /* initialize the user-specifiable params */
1090 static void initParams (void)
1094 delay = get_integer_resource ("delay", "Delay");
1097 fprintf (stderr, "error: delay must be at least 0\n");
1101 maxIters = get_integer_resource ("maxIters", "Integer");
1104 fprintf (stderr, "error: maxIters must be at least 0\n");
1108 doubleBuffer = get_boolean_resource ("doubleBuffer", "Boolean");
1110 requestedBlotCount = get_integer_resource ("count", "Count");
1111 if (requestedBlotCount <= 0)
1113 fprintf (stderr, "error: count must be at least 0\n");
1117 colorCount = get_integer_resource ("colors", "Colors");
1118 if (colorCount <= 0)
1120 fprintf (stderr, "error: colors must be at least 1\n");
1124 lineWidth = get_integer_resource ("lineWidth", "LineWidth");
1127 fprintf (stderr, "error: line width must be at least 0\n");
1131 nervousness = get_float_resource ("nervousness", "Float");
1132 if ((nervousness < 0) || (nervousness > 1))
1134 fprintf (stderr, "error: nervousness must be in the range 0..1\n");
1138 maxNerveRadius = get_float_resource ("maxNerveRadius", "Float");
1139 if ((maxNerveRadius < 0) || (maxNerveRadius > 1))
1141 fprintf (stderr, "error: maxNerveRadius must be in the range 0..1\n");
1145 eventChance = get_float_resource ("eventChance", "Float");
1146 if ((eventChance < 0) || (eventChance > 1))
1148 fprintf (stderr, "error: eventChance must be in the range 0..1\n");
1152 iterAmt = get_float_resource ("iterAmt", "Float");
1153 if ((iterAmt < 0) || (iterAmt > 1))
1155 fprintf (stderr, "error: iterAmt must be in the range 0..1\n");
1159 minScale = get_float_resource ("minScale", "Float");
1160 if ((minScale < 0) || (minScale > 10))
1162 fprintf (stderr, "error: minScale must be in the range 0..10\n");
1166 maxScale = get_float_resource ("maxScale", "Float");
1167 if ((maxScale < 0) || (maxScale > 10))
1169 fprintf (stderr, "error: maxScale must be in the range 0..10\n");
1173 if (maxScale < minScale)
1175 fprintf (stderr, "error: maxScale must be >= minScale\n");
1179 minRadius = get_integer_resource ("minRadius", "Integer");
1180 if ((minRadius < 1) || (minRadius > 100))
1182 fprintf (stderr, "error: minRadius must be in the range 1..100\n");
1186 maxRadius = get_integer_resource ("maxRadius", "Integer");
1187 if ((maxRadius < 1) || (maxRadius > 100))
1189 fprintf (stderr, "error: maxRadius must be in the range 1..100\n");
1193 if (maxRadius < minRadius)
1195 fprintf (stderr, "error: maxRadius must be >= minRadius\n");
1206 void screenhack (Display *dpy, Window win)
1214 /* make a valid set to erase at first */
1221 screenhack_handle_events (dpy);