Pixel sorting has become a favoured technique in the creation of glitch art, with just a minor reordering of the pixels of an image able to produce surprisingly beautiful gradients. However, many tools for the creation of this work are limited by the unexpected complexity of the task. Sorting any number of colours requires a 3 dimensional path to be drawn through the RGB colour space, a problem equivalent to the travelling salesman problem.
There's a number of solutions to this problem, and TSPPixelSort explores a few of them. Each approach builds an intuition for the underlying algorithm: A genetic algorithm will produce short gradients, stymied by occasional poor evolutionary decisions; A naive nearest neighbour algorithm will attempt to produce a single large gradient before yielding a noisy mess.
TSPPixelSort is available as a desktop app for experimentation from GitHub.
An image being sorted with an increasing number of genetic iterations. Source.