Skip to content

Instantly share code, notes, and snippets.

@miou-gh
Created June 11, 2017 09:33
Show Gist options
  • Select an option

  • Save miou-gh/a10f6b28eba68b0ca97fa9160e50277c to your computer and use it in GitHub Desktop.

Select an option

Save miou-gh/a10f6b28eba68b0ca97fa9160e50277c to your computer and use it in GitHub Desktop.
class Color:
def __init__(self, r, g, b):
self.r = r
self.g = g
self.b = b
def to_rgb_color(argb:int, remove_alpha:bool = True) -> Color:
a = (argb >> 24) & 255
r = (argb >> 16) & 255
g = (argb >> 8) & 255
b = (argb >> 0) & 255
if remove_alpha:
a = 0xFF if a > 128 else 0
return Color(r, g, b)
def to_hex(r:int, g:int, b:int) -> str:
return '#%02x%02x%02x' % (color.r, color.g, color.b)
cf_h = open('colors_hex.txt', 'w+')
cf_h2 = open('colors_hex_no_leading_hash.txt', 'w+')
cf_r = open('colors_rgb.txt', 'w+')
cf_r2 = open('colors_rgb_no_parenthesis.txt', 'w+')
cf_css = open('colors_css.css', 'w+')
with open('colors.txt') as cf:
lines = cf.readlines()
lines = [x.strip() for x in lines]
for line in lines:
type, argb = line.split(' ')
color = to_rgb_color(int(argb))
color_hex = to_hex(color.r, color.g, color.b)
cf_h.write('{} {}\n'.format(type, color_hex))
cf_h2.write('{} {}\n'.format(type, color_hex.replace('#', '')))
cf_r.write('{} rgb({}, {}, {})\n'.format(type, color.r, color.g, color.b))
cf_r2.write('{} {} {} {}\n'.format(type, color.r, color.g, color.b))
cf_css.write('.b{} {{ color: {} }}\n'.format(type, color_hex))
print('{}: {} {} {} | {}'.format(type, color.r, color.g, color.b, color_hex))
print('Complete!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment