+/* set up the initial array of blots to be near the corners of a
+ * cube, distributed slightly */
+static void setupBlotsCubeCorners (void)
+{
+ int n;
+
+ blotCount = requestedBlotCount;
+ blots = calloc (sizeof (Blot), blotCount);
+
+ for (n = 0; n < blotCount; n++)
+ {
+ FLOAT x = rint (RAND_FLOAT_01) * 2 - 1;
+ FLOAT y = rint (RAND_FLOAT_01) * 2 - 1;
+ FLOAT z = rint (RAND_FLOAT_01) * 2 - 1;
+
+ x += RAND_FLOAT_PM1 * 0.3;
+ y += RAND_FLOAT_PM1 * 0.3;
+ z += RAND_FLOAT_PM1 * 0.3;
+
+ initBlot (&blots[n], x, y, z);
+ }
+
+ scaleBlotsToRadius1 ();
+ randomlyRotateBlots ();
+}
+
+/* set up the initial array of blots to be randomly distributed
+ * on the surface of a tetrahedron */
+static void setupBlotsTetrahedron (void)
+{
+ /* table of corners of the tetrahedron */
+ static FLOAT cor[4][3] = { { 0.0, 1.0, 0.0 },
+ { -0.75, -0.5, -0.433013 },
+ { 0.0, -0.5, 0.866025 },
+ { 0.75, -0.5, -0.433013 } };
+
+ int n, c;
+
+ /* derive blotsPerSurface from blotCount, but then do the reverse
+ * since roundoff may have changed blotCount */
+ int blotsPerSurface = requestedBlotCount / 4;
+
+ blotCount = blotsPerSurface * 4;
+ blots = calloc (sizeof (Blot), blotCount);
+
+ for (n = 0; n < blotCount; n += 4)
+ {
+ /* pick a random point on a unit right triangle */
+ FLOAT rawx = RAND_FLOAT_01;
+ FLOAT rawy = RAND_FLOAT_01;
+
+ if ((rawx + rawy) > 1)
+ {
+ /* swap coords into place */
+ FLOAT t = 1.0 - rawx;
+ rawx = 1.0 - rawy;
+ rawy = t;
+ }
+
+ /* translate the point to be on each of the surfaces */
+ for (c = 0; c < 4; c++)
+ {
+ FLOAT x, y, z;
+
+ int c1 = (c + 1) % 4;
+ int c2 = (c + 2) % 4;
+
+ x = (cor[c1][0] - cor[c][0]) * rawx +
+ (cor[c2][0] - cor[c][0]) * rawy +
+ cor[c][0];
+
+ y = (cor[c1][1] - cor[c][1]) * rawx +
+ (cor[c2][1] - cor[c][1]) * rawy +
+ cor[c][1];
+
+ z = (cor[c1][2] - cor[c][2]) * rawx +
+ (cor[c2][2] - cor[c][2]) * rawy +
+ cor[c][2];
+
+ initBlot (&blots[n + c], x, y, z);
+ }
+ }
+
+ randomlyRotateBlots ();
+}
+
+/* set up the initial array of blots to be an almost-evenly-distributed
+ * square sheet */
+static void setupBlotsSheet (void)
+{
+ int x, y;
+
+ int blotsPerDimension = floor (sqrt (requestedBlotCount));
+ FLOAT spaceBetween;
+
+ if (blotsPerDimension < 2)
+ {
+ blotsPerDimension = 2;
+ }
+
+ spaceBetween = 2.0 / (blotsPerDimension - 1);
+
+ blotCount = blotsPerDimension * blotsPerDimension;
+ blots = calloc (sizeof (Blot), blotCount);
+
+ for (x = 0; x < blotsPerDimension; x++)
+ {
+ for (y = 0; y < blotsPerDimension; y++)
+ {
+ FLOAT x1 = x * spaceBetween - 1.0;
+ FLOAT y1 = y * spaceBetween - 1.0;
+ FLOAT z1 = 0.0;
+
+ x1 += RAND_FLOAT_PM1 * spaceBetween / 3;
+ y1 += RAND_FLOAT_PM1 * spaceBetween / 3;
+ z1 += RAND_FLOAT_PM1 * spaceBetween / 2;
+
+ initBlot (&blots[x + y * blotsPerDimension], x1, y1, z1);
+ }
+ }
+
+ scaleBlotsToRadius1 ();
+ randomlyReorderBlots ();
+ randomlyRotateBlots ();
+}
+
+/* set up the initial array of blots to be a swirlycone */
+static void setupBlotsSwirlyCone (void)
+{
+ FLOAT radSpace = 1.0 / (requestedBlotCount - 1);
+ FLOAT zSpace = radSpace * 2;
+ FLOAT rotAmt = RAND_FLOAT_PM1 * M_PI / 10;
+
+ int n;
+ FLOAT rot = 0.0;
+
+ blotCount = requestedBlotCount;
+ blots = calloc (sizeof (Blot), blotCount);
+
+ for (n = 0; n < blotCount; n++)
+ {
+ FLOAT radius = n * radSpace;
+ FLOAT x = cos (rot) * radius;
+ FLOAT y = sin (rot) * radius;
+ FLOAT z = n * zSpace - 1.0;
+
+ rot += rotAmt;
+ initBlot (&blots[n], x, y, z);
+ }
+
+ scaleBlotsToRadius1 ();
+ randomlyReorderBlots ();
+ randomlyRotateBlots ();
+}
+
+/* forward declaration for recursive use immediately below */
+static void setupBlots (void);
+
+/* set up the blots to be two of the other choices, placed next to
+ * each other */
+static void setupBlotsDuo (void)
+{
+ int origRequest = requestedBlotCount;
+ FLOAT tx, ty, tz, radius;
+ Blot *blots1, *blots2;
+ int count1, count2;
+ int n;
+
+ if (requestedBlotCount < 15)
+ {
+ /* special case bottom-out */
+ setupBlotsSphere ();
+ return;
+ }
+
+ tx = RAND_FLOAT_PM1;
+ ty = RAND_FLOAT_PM1;
+ tz = RAND_FLOAT_PM1;
+ radius = sqrt (tx * tx + ty * ty + tz * tz);
+ tx /= radius;
+ ty /= radius;
+ tz /= radius;
+
+ /* recursive call to setup set 1 */
+ requestedBlotCount = origRequest / 2;
+ setupBlots ();
+
+ if (blotCount >= origRequest)
+ {
+ /* return immediately if this satisfies the original count request */
+ requestedBlotCount = origRequest;
+ return;
+ }
+
+ blots1 = blots;
+ count1 = blotCount;
+ blots = NULL;
+ blotCount = 0;
+
+ /* translate to new position */
+ for (n = 0; n < count1; n++)
+ {
+ blots1[n].x += tx;
+ blots1[n].y += ty;
+ blots1[n].z += tz;
+ }
+
+ /* recursive call to setup set 2 */
+ requestedBlotCount = origRequest - count1;
+ setupBlots ();
+ blots2 = blots;
+ count2 = blotCount;
+
+ /* translate to new position */
+ for (n = 0; n < count2; n++)
+ {
+ blots2[n].x -= tx;
+ blots2[n].y -= ty;
+ blots2[n].z -= tz;
+ }
+
+ /* combine the two arrays */
+ blotCount = count1 + count2;
+ blots = calloc (sizeof (Blot), blotCount);
+ memcpy (&blots[0], blots1, sizeof (Blot) * count1);
+ memcpy (&blots[count1], blots2, sizeof (Blot) * count2);
+ free (blots1);
+ free (blots2);
+
+ scaleBlotsToRadius1 ();
+ randomlyReorderBlots ();
+
+ /* restore the original requested count, for future iterations */
+ requestedBlotCount = origRequest;
+}
+