Skip to content

Instantly share code, notes, and snippets.

@Gummibeer
Last active February 7, 2017 10:46
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 Gummibeer/d457ab8df076fb28b77374d057a91402 to your computer and use it in GitHub Desktop.
Save Gummibeer/d457ab8df076fb28b77374d057a91402 to your computer and use it in GitHub Desktop.
Sort colors by HUE
import colorsys
def get_hsv(value):
if(not isinstance(value, str)):
value = value[1]
value = value.lstrip("#")
lv = len(value)
r, g, b = tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3))
return colorsys.rgb_to_hsv(r, g, b)
color_array = [
"#3B5998",
"#0976B4",
"#024b4d",
"#4183c4",
"#B31217",
"#3F729B",
"#799905",
"#25CB68",
"#6441A4",
"#A4C639"
]
color_array.sort(key=get_hsv)
print(str(color_array))
color_dict = {
"facebook": "#3B5998",
"linkedin": "#0976B4",
"xing": "#024b4d",
"github": "#4183c4",
"youtube": "#B31217",
"instagram": "#3F729B",
"steam": "#799905",
"kickstarter": "#25CB68",
"twitch": "#6441A4",
"android": "#A4C639",
"stackexchange": "#195398"
}
color_dict = sorted(color_dict.items(), key=get_hsv)
print(str(color_dict))
@Gummibeer
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment