Hi, thanks for the table.
As you say there are clashes and so I reworked it.
Sorted / renamed those often conflicting names using your luminance infos into descending order regarding brightness.
![image](https://user-images.githubusercontent.com/9989548/45810506-013da400-bccb-11e8-8ba6-fc50f75a205c.png)
Btw: How did you calculate those hsl values, sometimes they look a bit off, visually...
Anyway, source for the fix:
colors = <paste your json table here>
if __name__ == "__main__":
# first remove all numbers from the names, they don't fit:
names = {}
for m in colors:
n = m["name"]
while n[-1].isdigit():
n = n[:-1]
m["name"] = n
names.setdefault(n, []).append(m)
# we nave now in names:
# {'Red': [{'name': 'Red', id: 9, ..., hsl: }, {'name': 'Red', id:196, ...}..
# first Red is not red:
red = names["Red"].pop(0)
red["name"] = "Salmon"
names["Salmon"].append(red)
# now sort the lists per luminance and set the numbers from high to low lum.:
nn = {}
for n, ms in names.items():
if len(ms) > 1:
ms = sorted(
ms,
key=lambda k: 10000
- float("%s.%s" % (k["hsl"]["l"], int(k["hsl"]["h"]))),
)
# first greys are actually darker whites, so:
if n == "Grey":
ws, ms = ms[:3], ms[3:]
i = 1
for w in ws:
wn = "White%s" % i
nn[wn] = w
i += 1
i = ""
for m in ms:
# DarkOlive makes no sense, superbright first - and there is no Olive:
na = (m["name"] + str(i)).replace("DarkOlive", "Olive")
m["name"] = na
i = 1 if not i else i + 1
nn[na] = m
names = nn
table = {}
for n, m in names.items():
table[m["colorId"]] = m
import sys, json
sys.argv.append("")
if sys.argv[1] == "table":
print(json.dumps(table, sort_keys=1))
elif sys.argv[1] == "names":
print(json.dumps(names, sort_keys=1))
else:
tm = "%(colorId)4s \x1b[38;5;%(colorId)sm%(name)s\x1b[0m"
for n, m in names.items():
print(tm % m)
Then save this as foo.py and run python3 foo.py [table|names]
If you say python3 foo.py names | jq .
you get
![image](https://user-images.githubusercontent.com/9989548/45810754-a8bad680-bccb-11e8-92a3-d491f3707acf.png)