Add base -> colour support, and optimization in errors.py.

This commit is contained in:
privacy lulz
2021-09-01 19:36:37 +00:00
parent 6f5614373a
commit 10d8a03d71
2 changed files with 19 additions and 1 deletions

View File

@@ -83,6 +83,24 @@ class Colour:
raise TypeError(f'Expected int parameter, received {value.__class__.__name__} instead.')
self.value: int = value
@staticmethod
def from_hex(self, value: str, base:int = None):
"""
Initiate self.value from different base(hexidecimal, binary)
=======
value `str` :
value in different base, e.g. white in hexidecimal, 0xffffff
base `int` (optional) :
base of your value, if you don't supply this, you have to add a prefix to your number, e.g. 0x or 0b
"""
return Colour(value = int(value, base=base))
def _get_byte(self, byte: int) -> int:
return (self.value >> (8 * byte)) & 0xff