Skip to content

Instantly share code, notes, and snippets.

@arkarkark
Created August 1, 2017 02:12
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 arkarkark/b5d0c92d643454ea9e66de94641197fe to your computer and use it in GitHub Desktop.
Save arkarkark/b5d0c92d643454ea9e66de94641197fe to your computer and use it in GitHub Desktop.
closest color to a list of colors in json format
#!/usr/bin/python
import json
target = "f6efe8"
# kelly more
# curl 'http://kellymoore.com/mycolorstudio-color-palette/data/colors.json' -o colors.json
# behr
# http://www.behr.com/consumer/colors/paint copy(JSON.stringify(window.colorData))
# pbpaste > colors.json
cols = json.load(open("colors.json"))
closest = None
lowest = 3000
def ComponentDiff(a, b):
return abs(int(a, 16) - int(b, 16))
def ColorDiff(col):
return (ComponentDiff(col[0:2], target[0:2]) +
ComponentDiff(col[2:4], target[2:4]) +
ComponentDiff(col[4:6], target[4:6]))
for col in cols:
# hex = col['hex'][1:] # kelly more
hex = col[14][1:] # behr
diff = ColorDiff(hex)
if diff < lowest:
lowest = diff
closest = col
print lowest, closest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment