In [1]:
from PySide.QtGui import *
from PySide.QtCore import *

%gui qt

the input should be something like:


In [2]:
#                values   | hue
test_values = [([0, 1, 2],  0),
               ([4, 5, 6],  120),
               ([1,10,11],  240)]

the result should be a qcolor palette with colors made from those three components mixed.

maybe even a weight distribution would be nice, to make specific values on each "scale" have more distance to their neighbouring colors)


In [3]:
def values_along_axis(hue, values):
    for idx, _ in enumerate(values):
        yield QColor.fromHsv(hue, 255, 255. * (float(idx) / (len(values) - 1))).convertTo(QColor.Rgb)

In [4]:
def mix_colors(colors):
    lenf = float(len(colors))
    red = sum(col.red() for col in colors)     / lenf
    green = sum(col.green() for col in colors) / lenf
    blue = sum(col.blue() for col in colors)   / lenf
    return QColor.fromRgb(red, green, blue)

In [5]:
from itertools import product
def generate_palette(values):
    indices = range(len(values))

    axisvalues = list(list(values_along_axis(values[axis][1], values[axis][0])) for axis in indices)
    values = list(values[axis][0] for axis in indices)

    palette = {}
    
    combinations = product(*values)
    for position in combinations:
        colors = []
        for axidx, ordinate in enumerate(position):
            colors.append(axisvalues[axidx][values[axidx].index(ordinate)])
        palette[position] = mix_colors(colors)
    
    return palette

In [6]:
pal = generate_palette(test_values)