1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 from muntjac.addon.invient.paint import IPaint
16 from muntjac.addon.colorpicker.color import Color
17
18
20 """The Color interface represents RBG and RBGA colors.
21 Do not confuse with L{Color} class. This is a simplified
22 version of L{Color} for the purpose of InvientCharts
23
24 @author: Invient
25 @author: Richard Lincoln
26 """
27 pass
28
29
31 """Represents RBG color value.
32
33 @author: Invient
34 @author: Richard Lincoln
35 """
36
38 """Creates an RGB color with the specified red, green, and blue values.
39 The values must be in the range (0 - 255).
40
41 @param red:
42 the red component in a color
43 @param green:
44 the green component in a color
45 @param blue:
46 the blue component in a color
47 """
48 super(RGB, self).__init__()
49 errorCompString = ''
50 hasError = False
51 if (red < 0) or (red > 255):
52 hasError = True
53 errorCompString = ' Red '
54
55 if (green < 0) or (green > 255):
56 hasError = True
57 errorCompString += ' Green'
58
59 if (blue < 0) or (blue > 255):
60 hasError = True
61 errorCompString += ' Blue'
62
63 if hasError:
64 raise ValueError('Color parameter outside of expected range:'
65 + errorCompString)
66
67 self._red = red
68 self._green = green
69 self._blue = blue
70
71
73 """@return: Returns the red component in the range (0-255)."""
74 return self._red
75
76
78 """@return: Returns the green component in the range (0-255)."""
79 return self._green
80
81
83 """@return: Returns the blue component in the range (0-255)."""
84 return self._blue
85
86
88 """@return: Returns string representation of this RBG."""
89 return ('rgb(' + str(self._red) + ',' + str(self._green) + ','
90 + str(self._blue) + ')')
91
92
94 """@return: Returns string representation of this RBG."""
95 return ('RGB [red=' + str(self._red) + ', green=' + str(self._green)
96 + ', blue=' + str(self._blue) + ']')
97
98
100 """Represents RGBA color value.
101
102 @author Invient
103 @author: Richard Lincoln
104 """
105
106 - def __init__(self, red, green, blue, alpha):
107 """Creates an RGBA color with the specified red, green, blue and alpha
108 values. The red, green and blue values must be in the range (0 -
109 255). The alpha value must be in the range (0.0-1.0). The alpha value
110 deaults to 1.0
111
112 @param red:
113 the red component in a color
114 @param green:
115 the green component in a color
116 @param blue:
117 the blue component in a color
118 @param alpha:
119 the alpha component in a color
120 """
121 super(RGBA, self).__init__(red, green, blue)
122
123 if (alpha < 0.0) or (alpha > 1.0):
124 errorCompString = ' Alpha'
125 raise ValueError('Color parameter outside of expected range: '
126 + errorCompString)
127
128 self._alpha = alpha
129
130
132 """@return: Returns the alpha component in the range (0.0-1.0)."""
133 return self._alpha
134
135
137 """@return: Returns string representation of this RGBA"""
138 return ('rgba(' + str(self.getRed()) + ',' + str(self.getGreen())
139 + ',' + str(self.getBlue()) + ',' + str(self._alpha) + ')')
140
141
143 """@return: Returns string representation of this RGBA"""
144 return ('RGBA [alpha=' + str(self._alpha)
145 + ', red=' + str(self.getRed())
146 + ', green=' + str(self.getGreen())
147 + ', blue=' + str(self.getBlue())
148 + ']')
149