MCPcopy
hub / github.com/Textualize/rich / ColorTriplet

Class ColorTriplet

rich/color_triplet.py:4–38  ·  view source on GitHub ↗

The red, green, and blue components of a color.

Source from the content-addressed store, hash-verified

2
3
4class ColorTriplet(NamedTuple):
5 """The red, green, and blue components of a color."""
6
7 red: int
8 """Red component in 0 to 255 range."""
9 green: int
10 """Green component in 0 to 255 range."""
11 blue: int
12 """Blue component in 0 to 255 range."""
13
14 @property
15 def hex(self) -> str:
16 """get the color triplet in CSS style."""
17 red, green, blue = self
18 return f"#{red:02x}{green:02x}{blue:02x}"
19
20 @property
21 def rgb(self) -> str:
22 """The color in RGB format.
23
24 Returns:
25 str: An rgb color, e.g. ``"rgb(100,23,255)"``.
26 """
27 red, green, blue = self
28 return f"rgb({red},{green},{blue})"
29
30 @property
31 def normalized(self) -> Tuple[float, float, float]:
32 """Convert components into floats between 0 and 1.
33
34 Returns:
35 Tuple[float, float, float]: A tuple of three normalized colour components.
36 """
37 red, green, blue = self
38 return red / 255.0, green / 255.0, blue / 255.0

Callers 15

test_hexFunction · 0.90
test_rgbFunction · 0.90
test_normalizedFunction · 0.90
test_truecolorFunction · 0.90
test_parse_successFunction · 0.90
test_from_tripletFunction · 0.90
test_from_rgbFunction · 0.90
test_parse_rgb_hexFunction · 0.90
test_blend_rgbFunction · 0.90
__init__Method · 0.85
_get_pulse_segmentsMethod · 0.85
from_rgbMethod · 0.85

Calls

no outgoing calls

Tested by 9

test_hexFunction · 0.72
test_rgbFunction · 0.72
test_normalizedFunction · 0.72
test_truecolorFunction · 0.72
test_parse_successFunction · 0.72
test_from_tripletFunction · 0.72
test_from_rgbFunction · 0.72
test_parse_rgb_hexFunction · 0.72
test_blend_rgbFunction · 0.72