Interlude

As with skiing, swimming, and life (and so much else),  computer graphics blends control and abandon. Our sphere of starbursts program positions a number of starbursts at random positions on an invisible sphere. The set of points where starbursts may be positioned is constrained — they must lie on this sphere — but otherwise, subject to this constraint, the points are chosen at random. If enough starbursts get placed at random and they are sufficiently small, we can make out the sphere. However, if there are too few starbursts, the sphere never emerges. Similarly, if there are too many large starbursts, we get a fuzzy ball — a tribble — but lose sight of the sphere. Things come together under suitable constrained randomness, the right blend of control and abandon.

Secondly, we often get unexpected results when programming graphics. And unexpected results are often interesting. Our sphere of starbursts program translates each starburst to the imaginary sphere like this:

let p = getRandomPositionOnSphere(rad);
obj.position.set(p.x, p.y, p.z);

In my first version of this program, I wrote this instead:

let p = getRandomPositionOnSphere(rad);
obj.position = p;

In non-strict mode, JavaScript doesn’t complain about assigning to obj.position. However, because the object’s position property isn’t writable, this assignment has no effect: The value of position is not changed. The result is that none of the starbursts are translated to the sphere, and they all remain coincident at the origin.

Coincident starbursts

The effect is neat but not what I was shooting for. We pay close attention to what’s right in front of us while remaining open to whatever happens next.