#f0f0 and #ff00ff00 colors

This commit is contained in:
homm 2016-09-17 12:11:06 +03:00
parent 6e7553fb0f
commit 951143c936

View File

@ -45,21 +45,38 @@ def getrgb(color):
return rgb return rgb
colormap[color] = rgb = getrgb(rgb) colormap[color] = rgb = getrgb(rgb)
return rgb return rgb
# check for known string formats # check for known string formats
m = re.match("#\w\w\w$", color) if re.match('#[a-f0-9]{3}$', color, re.I):
if m:
return ( return (
int(color[1]*2, 16), int(color[1]*2, 16),
int(color[2]*2, 16), int(color[2]*2, 16),
int(color[3]*2, 16) int(color[3]*2, 16),
) )
m = re.match("#\w\w\w\w\w\w$", color)
if m: if re.match('#[a-f0-9]{4}$', color, re.I):
return (
int(color[1]*2, 16),
int(color[2]*2, 16),
int(color[3]*2, 16),
int(color[4]*2, 16),
)
if re.match('#[a-f0-9]{6}$', color, re.I):
return ( return (
int(color[1:3], 16), int(color[1:3], 16),
int(color[3:5], 16), int(color[3:5], 16),
int(color[5:7], 16) int(color[5:7], 16),
) )
if re.match('#[a-f0-9]{8}$', color, re.I):
return (
int(color[1:3], 16),
int(color[3:5], 16),
int(color[5:7], 16),
int(color[7:9], 16),
)
m = re.match("rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$", color) m = re.match("rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)$", color)
if m: if m:
return ( return (