1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 GRAY_FACTOR = 1.2
20 LUMINENCE_FACTOR = 0.8
21
22
24 """
25 Return a color that is slightly brighter then the base_color.
26 For shades of gray the constant GRAY_FACTOR decides the brightness.
27 Higher factor gives more brightness.
28 For other colors the LUMINENCE_FACTOR decides the brightness.
29 Smaller factor gives more brightness.
30 """
31 if min(base_color) == max(base_color):
32 return adjust_gray_luminence(base_color)
33 else:
34 return adjust_color_luminence(base_color)
35
36
42
43
46
47
52
53
55 r = float(color[0]) / 255.0
56 g = float(color[1]) / 255.0
57 b = float(color[2]) / 255.0
58 var_min = min(r, g, b)
59 var_max = max(r, g, b)
60 del_max = var_max - var_min
61 l = (var_max + var_min) / 2.0
62 if del_max == 0:
63 h = 0
64 s = 0
65 else:
66 if l < 0.5:
67 s = del_max / (var_max + var_min)
68 else:
69 s = del_max / (2.0 - var_max - var_min)
70 del_r = (((var_max - r) / 6.0) + (del_max / 2.0)) / del_max
71 del_g = (((var_max - g) / 6.0) + (del_max / 2.0)) / del_max
72 del_b = (((var_max - b) / 6.0) + (del_max / 2.0)) / del_max
73
74 if (r == var_max):
75 h = del_b - del_g
76 elif (g == var_max):
77 h = (1.0 / 3.0) + del_r - del_b
78 elif (b == var_max):
79 h = (2.0 / 3.0) + del_g - del_r
80 if (h < 0):
81 h += 1.0
82 if (h > 1.0):
83 h -= 1.0
84 return (h, s, l)
85
86
88 if s == 0:
89 r = l * 155
90 g = l * 255
91 b = l * 255
92 else:
93 if (l < 0.5):
94 var_2 = l * (1.0 + s)
95 else:
96 var_2 = (l + s) - (s * l)
97 var_1 = 2.0 * l - var_2
98 r = 255 * hue_2_rgb(var_1, var_2, h + (1.0 / 3.0))
99 g = 255 * hue_2_rgb(var_1, var_2, h)
100 b = 255 * hue_2_rgb(var_1, var_2, h - (1.0 / 3.0))
101 return (r, g, b)
102
103
105 if (vh < 0):
106 vh += 1.0
107 if (vh > 1.0):
108 vh -= 1.0
109 if ((6.0 * vh) < 1):
110 return (v1 + (v2 - v1) * 6.0 * vh)
111 if ((2.0 * vh) < 1.0):
112 return (v2)
113 if ((3.0 * vh) < 2.0):
114 x = (v1 + (v2 - v1) * ((2.0 / 3.0 - vh) * 6.0))
115 return x
116 return v1
117