The Well-Tempered Palette (Part 3)

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 a and b is

F(a,b) \propto \alpha \frac{b-a}{\| b-a\|^2}.

where a and b are n-dimensional positions/vectors.

The magic constant \alpha must be finely tune to account for scale, repulsion force, and other tweaks. The total motion of a molecule a_i is therefore the sum of the repulsion with its neighbors:

F(a) = \sum_{j\neq{i}} \alpha \frac{a_j-a_i}{\| a_j-a_i\|^2}.

then we modify a using a'=a+\beta{}F(a), where \beta 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 \alpha and \beta. 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: