Wrapper for the OCCT color object Quantity_ColorRGBA.
| 182 | |
| 183 | |
| 184 | class Color(object): |
| 185 | """ |
| 186 | Wrapper for the OCCT color object Quantity_ColorRGBA. |
| 187 | """ |
| 188 | |
| 189 | wrapped: Quantity_ColorRGBA |
| 190 | |
| 191 | @overload |
| 192 | def __init__(self, name: str): |
| 193 | """ |
| 194 | Construct a Color from a name. |
| 195 | |
| 196 | :param name: name of the color, e.g. green |
| 197 | """ |
| 198 | ... |
| 199 | |
| 200 | @overload |
| 201 | def __init__(self, r: float, g: float, b: float, a: float = 0, srgb: bool = True): |
| 202 | """ |
| 203 | Construct a Color from RGB(A) values. |
| 204 | |
| 205 | :param r: red value, 0-1 |
| 206 | :param g: green value, 0-1 |
| 207 | :param b: blue value, 0-1 |
| 208 | :param a: alpha value, 0-1 (default: 0) |
| 209 | :param srgb: srgb/linear rgb switch, bool (default: True) |
| 210 | """ |
| 211 | ... |
| 212 | |
| 213 | @overload |
| 214 | def __init__(self): |
| 215 | """ |
| 216 | Construct a Color with default value. |
| 217 | """ |
| 218 | ... |
| 219 | |
| 220 | def __init__(self, *args, **kwargs): |
| 221 | |
| 222 | if len(args) == 0: |
| 223 | self.wrapped = Quantity_ColorRGBA() |
| 224 | elif len(args) == 1: |
| 225 | self.wrapped = Quantity_ColorRGBA() |
| 226 | exists = Quantity_ColorRGBA.ColorFromName_s( |
| 227 | args[0], self.wrapped |
| 228 | ) or Quantity_ColorRGBA.ColorFromHex_s(args[0], self.wrapped) |
| 229 | if not exists: |
| 230 | raise ValueError(f"Unknown color name: {args[0]}") |
| 231 | elif len(args) == 3: |
| 232 | r, g, b = args |
| 233 | self.wrapped = Quantity_ColorRGBA( |
| 234 | Quantity_Color(r, g, b, Quantity_TOC_sRGB), 1 |
| 235 | ) |
| 236 | if kwargs.get("a"): |
| 237 | self.wrapped.SetAlpha(kwargs.get("a")) |
| 238 | elif len(args) == 4: |
| 239 | r, g, b, a = args |
| 240 | self.wrapped = Quantity_ColorRGBA( |
| 241 | Quantity_Color(r, g, b, Quantity_TOC_sRGB), a |
no outgoing calls