Skip to content

Instantly share code, notes, and snippets.

Created Oct 2, 2018
What would you like to do?
256 colors for Open Color according to CIEDE2000
from colormath.color_objects import sRGBColor, LabColor
from colormath.color_conversions import convert_color
from colormath.color_diff import delta_e_cie2000
def hex_to_rgb(h):
return sRGBColor(h / 0x10000, (h / 0x100) % 0x100, h % 0x100,
COLORS_256 = [0x000000, 0x800000, 0x008000, 0x808000, 0x000080,
0x800080, 0x008080, 0xc0c0c0, 0x808080, 0xff0000,
0x00ff00, 0xffff00, 0x0000ff, 0xff00ff, 0x00ffff,
0xffffff, 0x000000, 0x00005f, 0x000087, 0x0000af,
0x0000d7, 0x0000ff, 0x005f00, 0x005f5f, 0x005f87,
0x005faf, 0x005fd7, 0x005fff, 0x008700, 0x00875f,
0x008787, 0x0087af, 0x0087d7, 0x0087ff, 0x00af00,
0x00af5f, 0x00af87, 0x00afaf, 0x00afd7, 0x00afff,
0x00d700, 0x00d75f, 0x00d787, 0x00d7af, 0x00d7d7,
0x00d7ff, 0x00ff00, 0x00ff5f, 0x00ff87, 0x00ffaf,
0x00ffd7, 0x00ffff, 0x5f0000, 0x5f005f, 0x5f0087,
0x5f00af, 0x5f00d7, 0x5f00ff, 0x5f5f00, 0x5f5f5f,
0x5f5f87, 0x5f5faf, 0x5f5fd7, 0x5f5fff, 0x5f8700,
0x5f875f, 0x5f8787, 0x5f87af, 0x5f87d7, 0x5f87ff,
0x5faf00, 0x5faf5f, 0x5faf87, 0x5fafaf, 0x5fafd7,
0x5fafff, 0x5fd700, 0x5fd75f, 0x5fd787, 0x5fd7af,
0x5fd7d7, 0x5fd7ff, 0x5fff00, 0x5fff5f, 0x5fff87,
0x5fffaf, 0x5fffd7, 0x5fffff, 0x870000, 0x87005f,
0x870087, 0x8700af, 0x8700d7, 0x8700ff, 0x875f00,
0x875f5f, 0x875f87, 0x875faf, 0x875fd7, 0x875fff,
0x878700, 0x87875f, 0x878787, 0x8787af, 0x8787d7,
0x8787ff, 0x87af00, 0x87af5f, 0x87af87, 0x87afaf,
0x87afd7, 0x87afff, 0x87d700, 0x87d75f, 0x87d787,
0x87d7af, 0x87d7d7, 0x87d7ff, 0x87ff00, 0x87ff5f,
0x87ff87, 0x87ffaf, 0x87ffd7, 0x87ffff, 0xaf0000,
0xaf005f, 0xaf0087, 0xaf00af, 0xaf00d7, 0xaf00ff,
0xaf5f00, 0xaf5f5f, 0xaf5f87, 0xaf5faf, 0xaf5fd7,
0xaf5fff, 0xaf8700, 0xaf875f, 0xaf8787, 0xaf87af,
0xaf87d7, 0xaf87ff, 0xafaf00, 0xafaf5f, 0xafaf87,
0xafafaf, 0xafafd7, 0xafafff, 0xafd700, 0xafd75f,
0xafd787, 0xafd7af, 0xafd7d7, 0xafd7ff, 0xafff00,
0xafff5f, 0xafff87, 0xafffaf, 0xafffd7, 0xafffff,
0xd70000, 0xd7005f, 0xd70087, 0xd700af, 0xd700d7,
0xd700ff, 0xd75f00, 0xd75f5f, 0xd75f87, 0xd75faf,
0xd75fd7, 0xd75fff, 0xd78700, 0xd7875f, 0xd78787,
0xd787af, 0xd787d7, 0xd787ff, 0xd7af00, 0xd7af5f,
0xd7af87, 0xd7afaf, 0xd7afd7, 0xd7afff, 0xd7d700,
0xd7d75f, 0xd7d787, 0xd7d7af, 0xd7d7d7, 0xd7d7ff,
0xd7ff00, 0xd7ff5f, 0xd7ff87, 0xd7ffaf, 0xd7ffd7,
0xd7ffff, 0xff0000, 0xff005f, 0xff0087, 0xff00af,
0xff00d7, 0xff00ff, 0xff5f00, 0xff5f5f, 0xff5f87,
0xff5faf, 0xff5fd7, 0xff5fff, 0xff8700, 0xff875f,
0xff8787, 0xff87af, 0xff87d7, 0xff87ff, 0xffaf00,
0xffaf5f, 0xffaf87, 0xffafaf, 0xffafd7, 0xffafff,
0xffd700, 0xffd75f, 0xffd787, 0xffd7af, 0xffd7d7,
0xffd7ff, 0xffff00, 0xffff5f, 0xffff87, 0xffffaf,
0xffffd7, 0xffffff, 0x080808, 0x121212, 0x1c1c1c,
0x262626, 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e,
0x585858, 0x626262, 0x6c6c6c, 0x767676, 0x808080,
0x8a8a8a, 0x949494, 0x9e9e9e, 0xa8a8a8, 0xb2b2b2,
0xbcbcbc, 0xc6c6c6, 0xd0d0d0, 0xdadada, 0xe4e4e4,
lab_colors_256 = [convert_color(hex_to_rgb(x), LabColor) for x in COLORS_256]
OPEN_COLORS = {'gray': [0xf8f9fa, 0xf1f3f5, 0xe9ecef, 0xdee2e6, 0xced4da,
0xadb5bd, 0x868e96, 0x495057, 0x343a40, 0x212529],
'red': [0xfff5f5, 0xffe3e3, 0xffc9c9, 0xffa8a8, 0xff8787,
0xff6b6b, 0xfa5252, 0xf03e3e, 0xe03131, 0xc92a2a],
'pink': [0xfff0f6, 0xffdeeb, 0xfcc2d7, 0xfaa2c1, 0xf783ac,
0xf06595, 0xe64980, 0xd6336c, 0xc2255c, 0xa61e4d],
'grape': [0xf8f0fc, 0xf3d9fa, 0xeebefa, 0xe599f7, 0xda77f2,
0xcc5de8, 0xbe4bdb, 0xae3ec9, 0x9c36b5, 0x862e9c],
'violet': [0xf3f0ff, 0xe5dbff, 0xd0bfff, 0xb197fc, 0x9775fa,
0x845ef7, 0x7950f2, 0x7048e8, 0x6741d9, 0x5f3dc4],
'indigo': [0xedf2ff, 0xdbe4ff, 0xbac8ff, 0x91a7ff, 0x748ffc,
0x5c7cfa, 0x4c6ef5, 0x4263eb, 0x3b5bdb, 0x364fc7],
'blue': [0xe7f5ff, 0xd0ebff, 0xa5d8ff, 0x74c0fc, 0x4dabf7,
0x339af0, 0x228be6, 0x1c7ed6, 0x1971c2, 0x1864ab],
'cyan': [0xe3fafc, 0xc5f6fa, 0x99e9f2, 0x66d9e8, 0x3bc9db,
0x22b8cf, 0x15aabf, 0x1098ad, 0x0c8599, 0x0b7285],
'teal': [0xe6fcf5, 0xc3fae8, 0x96f2d7, 0x63e6be, 0x38d9a9,
0x20c997, 0x12b886, 0x0ca678, 0x099268, 0x087f5b],
'green': [0xebfbee, 0xd3f9d8, 0xb2f2bb, 0x8ce99a, 0x69db7c,
0x51cf66, 0x40c057, 0x37b24d, 0x2f9e44, 0x2b8a3e],
'lime': [0xf4fce3, 0xe9fac8, 0xd8f5a2, 0xc0eb75, 0xa9e34b,
0x94d82d, 0x82c91e, 0x74b816, 0x66a80f, 0x5c940d],
'yellow': [0xfff9db, 0xfff3bf, 0xffec99, 0xffe066, 0xffd43b,
0xfcc419, 0xfab005, 0xf59f00, 0xf08c00, 0xe67700],
'orange': [0xfff4e6, 0xffe8cc, 0xffd8a8, 0xffc078, 0xffa94d,
0xff922b, 0xfd7e14, 0xf76707, 0xe8590c, 0xd9480f]}
lab_open_colors = {}
for category, values in OPEN_COLORS.items():
lab_open_colors[category] = [convert_color(hex_to_rgb(x), LabColor)
for x in values]
open_colors_256 = {}
for category, values in lab_open_colors.items():
open_colors_256[category] = []
for rgb in values:
rgb_256 = min(lab_colors_256, key=lambda x: delta_e_cie2000(rgb, x))
for color in ['gray', 'red', 'pink', 'grape', 'violet',
'indigo', 'blue', 'cyan', 'teal', 'green',
'lime', 'yellow', 'orange']:
print('{}: {}'.format(color, open_colors_256[color]))
require 'color_difference'
def hex_to_rgb(hex)
rgb = hex.to_i(16)
{ r: rgb / 0x10000,
g: (rgb / 0x100) % 0x100,
b: rgb % 0x100 }
COLORS_256 = %w[000000 800000 008000 808000 000080 800080 008080 c0c0c0
808080 ff0000 00ff00 ffff00 0000ff ff00ff 00ffff ffffff
000000 00005f 000087 0000af 0000d7 0000ff 005f00 005f5f
005f87 005faf 005fd7 005fff 008700 00875f 008787 0087af
0087d7 0087ff 00af00 00af5f 00af87 00afaf 00afd7 00afff
00d700 00d75f 00d787 00d7af 00d7d7 00d7ff 00ff00 00ff5f
00ff87 00ffaf 00ffd7 00ffff 5f0000 5f005f 5f0087 5f00af
5f00d7 5f00ff 5f5f00 5f5f5f 5f5f87 5f5faf 5f5fd7 5f5fff
5f8700 5f875f 5f8787 5f87af 5f87d7 5f87ff 5faf00 5faf5f
5faf87 5fafaf 5fafd7 5fafff 5fd700 5fd75f 5fd787 5fd7af
5fd7d7 5fd7ff 5fff00 5fff5f 5fff87 5fffaf 5fffd7 5fffff
870000 87005f 870087 8700af 8700d7 8700ff 875f00 875f5f
875f87 875faf 875fd7 875fff 878700 87875f 878787 8787af
8787d7 8787ff 87af00 87af5f 87af87 87afaf 87afd7 87afff
87d700 87d75f 87d787 87d7af 87d7d7 87d7ff 87ff00 87ff5f
87ff87 87ffaf 87ffd7 87ffff af0000 af005f af0087 af00af
af00d7 af00ff af5f00 af5f5f af5f87 af5faf af5fd7 af5fff
af8700 af875f af8787 af87af af87d7 af87ff afaf00 afaf5f
afaf87 afafaf afafd7 afafff afd700 afd75f afd787 afd7af
afd7d7 afd7ff afff00 afff5f afff87 afffaf afffd7 afffff
d70000 d7005f d70087 d700af d700d7 d700ff d75f00 d75f5f
d75f87 d75faf d75fd7 d75fff d78700 d7875f d78787 d787af
d787d7 d787ff d7af00 d7af5f d7af87 d7afaf d7afd7 d7afff
d7d700 d7d75f d7d787 d7d7af d7d7d7 d7d7ff d7ff00 d7ff5f
d7ff87 d7ffaf d7ffd7 d7ffff ff0000 ff005f ff0087 ff00af
ff00d7 ff00ff ff5f00 ff5f5f ff5f87 ff5faf ff5fd7 ff5fff
ff8700 ff875f ff8787 ff87af ff87d7 ff87ff ffaf00 ffaf5f
ffaf87 ffafaf ffafd7 ffafff ffd700 ffd75f ffd787 ffd7af
ffd7d7 ffd7ff ffff00 ffff5f ffff87 ffffaf ffffd7 ffffff
080808 121212 1c1c1c 262626 303030 3a3a3a 444444 4e4e4e
585858 626262 6c6c6c 767676 808080 8a8a8a 949494 9e9e9e
a8a8a8 b2b2b2 bcbcbc c6c6c6 d0d0d0 dadada e4e4e4 eeeeee].freeze
rgb_colors_256 = { |hex| hex_to_rgb(hex) }.freeze
OPEN_COLORS = { gray: %w[f8f9fa f1f3f5 e9ecef dee2e6 ced4da
adb5bd 868e96 495057 343a40 212529],
red: %w[fff5f5 ffe3e3 ffc9c9 ffa8a8 ff8787
ff6b6b fa5252 f03e3e e03131 c92a2a],
pink: %w[fff0f6 ffdeeb fcc2d7 faa2c1 f783ac
f06595 e64980 d6336c c2255c a61e4d],
grape: %w[f8f0fc f3d9fa eebefa e599f7 da77f2
cc5de8 be4bdb ae3ec9 9c36b5 862e9c],
violet: %w[f3f0ff e5dbff d0bfff b197fc 9775fa
845ef7 7950f2 7048e8 6741d9 5f3dc4],
indigo: %w[edf2ff dbe4ff bac8ff 91a7ff 748ffc
5c7cfa 4c6ef5 4263eb 3b5bdb 364fc7],
blue: %w[e7f5ff d0ebff a5d8ff 74c0fc 4dabf7
339af0 228be6 1c7ed6 1971c2 1864ab],
cyan: %w[e3fafc c5f6fa 99e9f2 66d9e8 3bc9db
22b8cf 15aabf 1098ad 0c8599 0b7285],
teal: %w[e6fcf5 c3fae8 96f2d7 63e6be 38d9a9
20c997 12b886 0ca678 099268 087f5b],
green: %w[ebfbee d3f9d8 b2f2bb 8ce99a 69db7c
51cf66 40c057 37b24d 2f9e44 2b8a3e],
lime: %w[f4fce3 e9fac8 d8f5a2 c0eb75 a9e34b
94d82d 82c91e 74b816 66a80f 5c940d],
yellow: %w[fff9db fff3bf ffec99 ffe066 ffd43b
fcc419 fab005 f59f00 f08c00 e67700],
orange: %w[fff4e6 ffe8cc ffd8a8 ffc078 ffa94d
ff922b fd7e14 f76707 e8590c d9480f] }.freeze
rgb_open_colors = {}
OPEN_COLORS.each do |category, values|
rgb_open_colors[category] = { |hex| hex_to_rgb(hex) }
open_colors_256 = {}
rgb_open_colors.each do |category, values|
open_colors_256[category] = do |rgb|
rgb_256 = rgb_colors_256.min_by { |v| ColorDifference.cie2000(rgb, v) }
%i[gray red pink grape violet
indigo blue cyan teal green
lime yellow orange].each do |color|
puts "#{color}: #{open_colors_256[color]}"
gray: [15, 255, 255, 254, 252, 249, 245, 239, 237, 235]
red: [15, 224, 224, 217, 210, 203, 203, 167, 160, 160]
pink: [255, 224, 218, 218, 211, 204, 168, 161, 161, 125]
grape: [255, 225, 219, 213, 177, 171, 134, 128, 127, 91]
violet: [255, 189, 183, 141, 141, 99, 99, 62, 57, 56]
indigo: [255, 189, 147, 111, 69, 69, 27, 27, 27, 26]
blue: [255, 153, 153, 75, 75, 75, 32, 32, 25, 25]
cyan: [195, 195, 116, 80, 45, 38, 38, 31, 31, 6]
teal: [195, 158, 122, 79, 43, 43, 36, 36, 29, 29]
green: [195, 194, 157, 114, 78, 77, 71, 71, 35, 28]
lime: [230, 230, 193, 192, 149, 112, 112, 70, 70, 64]
yellow: [230, 230, 229, 221, 220, 220, 214, 214, 208, 208]
orange: [255, 223, 223, 215, 215, 208, 208, 202, 166, 166]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment