Created
August 1, 2017 02:12
-
-
Save arkarkark/b5d0c92d643454ea9e66de94641197fe to your computer and use it in GitHub Desktop.
closest color to a list of colors in json format
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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