/* set up the initial arrays of blots */ static void setupBlots (struct state *st) { int which = RAND_FLOAT_01 * 11; freeBlots (st); switch (which) { case 0: setupBlotsCube (st); break; case 1: setupBlotsSphere (st); break; case 2: setupBlotsCylinder (st); break; case 3: setupBlotsSquiggle (st); break; case 4: setupBlotsCubeCorners (st); break; case 5: setupBlotsTetrahedron (st); break; case 6: setupBlotsSheet (st); break; case 7: setupBlotsSwirlyCone (st); break; case 8: case 9: case 10: setupBlotsDuo (st); break; } }
/* set up the blots to be two of the other choices, placed next to * each other */ static void setupBlotsDuo (struct nerverotstate *st) { int origRequest = st->requestedBlotCount; FLOAT tx, ty, tz, radius; Blot *blots1, *blots2; int count1, count2; int n; if (st->requestedBlotCount < 15) { /* special case bottom-out */ setupBlotsSphere (st); 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 */ st->requestedBlotCount = origRequest / 2; randomBlots (st); if (st->blotCount >= origRequest) { /* return immediately if this satisfies the original count request */ st->requestedBlotCount = origRequest; return; } blots1 = st->blots; count1 = st->blotCount; st->blots = NULL; st->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 */ st->requestedBlotCount = origRequest - count1; randomBlots (st); blots2 = st->blots; count2 = st->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 */ st->blotCount = count1 + count2; st->blots = (Blot*)calloc (sizeof (Blot), st->blotCount); memcpy (&st->blots[0], blots1, sizeof (Blot) * count1); memcpy (&st->blots[count1], blots2, sizeof (Blot) * count2); free (blots1); free (blots2); scaleBlotsToRadius1 (st); randomlyReorderBlots (st); /* restore the original requested count, for future iterations */ st->requestedBlotCount = origRequest; }