Skip to content

Instantly share code, notes, and snippets.

@bebraw
Created January 31, 2010 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bebraw/290961 to your computer and use it in GitHub Desktop.
Save bebraw/290961 to your computer and use it in GitHub Desktop.
# not tested! the code should just give the general idea
import colorsys
# just some utility funcs to wrap colorsys and to offer support for list of colors
def rgb_to_yiq(colors):
return [colorsys.rgb_to_yiq(color) for color in colors]
def yiq_to_rgb(colors):
return [colorsys.yiq_to_rgb(color) for color in colors]
# get these from some source (histogram/whatever)
rgb_colors = [[0.9, 0.2, 0.7], [0.2, 0.5, 0.6], ]
yiq_colors = rgb_to_yiq(rgb_colors)
sorted_yiq = sorted(yiq_colors) # implement comparison func to sort based on I or Q. it uses cmp
# by default it sorts by Y
result_colors = yiq_to_rgb(sorted_yiq)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment