Skip to content

Commit b79d7d7

Browse files
committed
Color.from_int(value: int) added.
1 parent 052cad2 commit b79d7d7

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

raylibpy/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1778,13 +1778,24 @@ def zero(cls) -> 'Color':
17781778
def one(cls) -> 'Color':
17791779
return cls(255, 255, 255, 255)
17801780

1781+
@classmethod
1782+
def from_int(cls, value: int) -> 'Color':
1783+
return get_color(max(0, value))
1784+
17811785
def __init__(self, *args) -> None:
17821786
"""Constructor."""
17831787
result = _flatten((int, float), *args, map_to=int)
17841788
if len(result) != 4:
17851789
raise ValueError("Too many or too few initializers ({} instead of 2).".format(len(result)))
17861790
super(Color, self).__init__(*result)
17871791

1792+
def __int__(self) -> int:
1793+
"""Packs the color into an integer."""
1794+
return color_to_int(self)
1795+
1796+
def __bytes__(self) -> bytes:
1797+
return bytes(bytearray(self))
1798+
17881799
def __str__(self) -> str:
17891800
return "({}, {}, {}, {})".format(self.r, self.g, self.b, self.a)
17901801

0 commit comments

Comments
 (0)