Skip to content

Commit c5cad01

Browse files
committed
Add Color.rgb property
1 parent c40333c commit c5cad01

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

arcade/types.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,26 @@ def b(self) -> int:
159159
def a(self) -> int:
160160
return self[3]
161161

162+
@property
163+
def rgb(self) -> Tuple[int, int, int]:
164+
"""Return only a color's RGB components.
165+
166+
This is syntactic sugar for slice indexing as below:
167+
168+
.. code-block:: python
169+
170+
>>> from arcade.color import WHITE
171+
>>> WHITE[:3]
172+
(255, 255, 255)
173+
# Equivalent but slower than the above
174+
>>> (WHITE.r, WHITE.g, WHITE.b)
175+
(255, 255, 255)
176+
177+
To reorder the channels as you retrieve them, see
178+
:meth:`.swizzle`.
179+
"""
180+
return self[:3]
181+
162182
@classmethod
163183
def from_iterable(cls, iterable: Iterable[int]) -> Self:
164184
"""

0 commit comments

Comments
 (0)