Last active
August 29, 2015 14:05
-
-
Save vetraskr/e39ac1062ab700933922 to your computer and use it in GitHub Desktop.
Functions to determine brightness of rgb/hex colours
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
# Base on http://zoltanb.co.uk/how-to-calculate-the-perceived-brightness-of-a-colour/ | |
import math, struct | |
def rgb_bright(r, g, b): | |
return math.sqrt(r*r*0.241 + g*g*0.691 + r*r*0.068) | |
def hex_bright(hex): | |
rgb_tuple = struct.unpack('BBB', hex.decode('hex')) | |
return rgb_bright(rgb_tuple[0], rgb_tuple[1], rgb_tuple[2]) | |
def check(hex_arr): | |
result = [] | |
for hex in hex_arr: | |
result.append(hex_bright(hex)) | |
print hex + ' -> ' + str(hex_bright(hex)) | |
return result | |
# these are the shades of green | |
# check(['64B21A', '7ABA40', '9DC974', 'B8D59F', 'D1E0C3']) | |
# these are ajiths colours | |
# check(['c0392b', '1abc9c', 'f1c40f', '3498db', '2ecc71']) | |
# these are amandas colours | |
# check(['EC008C', '009999', 'F7941D', '00AEEF', '0D9B39']) | |
# my revisions | |
# check(['E02F98', '2F9C9C', 'E5911B', '009ED9', '0D9E3A']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment