def recolor(tree, add):
""" Recursive part of recolor_strokes and recolor_background """
for child in tree:
if 'style' in child.attrib:
styles = { a : b
for (a, b) in (
x.split(":", 1)
for x in child.attrib['style'].split(';')
if ":" in x
)}
if "fill" in styles or "stroke" in styles:
for key in ("fill", "stroke"):
if key in styles:
# Convert color to HSV
r,g,b,a = html_to_rgb(styles[key])
h,s,v = colorsys.rgb_to_hsv(r,g,b)
# Shift hue
h += add
while h > 1.0 : h -= 1.0
# Convert it back
r,g,b = colorsys.hsv_to_rgb(h,s,v)
# Store
styles[key] = rgb_to_html(r,g,b)
child.attrib["style"] = ";".join(( ":".join((x,styles[x])) for x in styles ))
recolor(child, add)
# Generate different colors for controller icons
评论列表
文章目录