This week, we’ll discuss a cool, but failed, experiment.
In the last few weeks (of posts, because in real time, I worked on that problem over a week-end) we’ve looked at how to generate well distributed, maximally different colors. The methods were to use well-distributed sequences or lattices to ensure that the colors are equidistant. What if we used physical analogies to push the colors around so that they are maximally apart?
That’s exactly what I tried, with mixed results. So the idea was to start with randomly distributed colors within the color cube, then have them to move around so that they maximize distance. The obvious analogy is a gas, where each molecule push against the others to fill the volume (assuming no gravity). The repulsion force (vector) between two molecule and is
where and are n-dimensional positions/vectors.
The magic constant must be finely tune to account for scale, repulsion force, and other tweaks. The total motion of a molecule is therefore the sum of the repulsion with its neighbors:
then we modify using , where is another magic constant that vaguely corresponds to viscosity (but numerically it serves to ensure molecules move relatively slowly).
Finally, all positions are constrained to a bounding box.
Launching the code on twenty points, we see that the colors push against each other somewhat as expected:
The colors distribute kind of evenly (unfortunately, the very pale colors, like white, do not show up well in the animation), but the solutions are sensitive to the initial conditions, the number of iterations, and the magic constants and . With a small number of colors, it works however well: at 8 colors, each finds its own corner of the cube.
But with a real gas filling a real container, the container itself exerts repulsion, so corners and surfaces aren’t “attractive”, and the molecules distribute themselves more evenly. Here, I haven’t implemented container repulsion, so colors just flee from the center of the cube!
It’s a very complicated way of distributing colors against the edges of the cube, and we have much better ways of doing this.