I'd like to map points in a RGB color cube to a one-dimensional list in Python, in a way that makes the list of colors look nice and continuous.
I believe using a 3D Hilbert space-filling curve would be a good way to do this, but I've searched and haven't found very helpful resources for this problem. Wikipedia in particular only provides example code for generating 2D curves.
I came across your question while trying to do the same thing in javascript. I figured it out on my own. Here is a recursive function that breaks a cube in 8 parts and rotates each part so that it traverses a hilbert curve in order. The arguments represent the size:s, location:xyz, and 3 vectors for the rotated axes of the cube. The example call uses a 256^3 cube and assumes red,green,blue arrays have length 256^3.
It should be easy to adapt this code to python or other procedural languages.
Adapted from pictures here: http://www.math.uwaterloo.ca/~wgilbert/Research/HilbertCurve/HilbertCurve.html
What's frequently used in engineering practice is not strictly Hilbert (Peano) curves - it's Morton code.
https://en.wikipedia.org/wiki/Z-order_curve
Much easier to compute.
This paper seems to have quite a discussion: An inventory of three-dimensional Hilbert space-filling curves.
Quoting from the abstract: