Skip to content

Commit c0c5977

Browse files
committed
Add Color.rgb property
1 parent 9a8350e commit c0c5977

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
@@ -154,6 +154,26 @@ def b(self) -> int:
154154
def a(self) -> int:
155155
return self[3]
156156

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

0 commit comments

Comments
 (0)