aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbmintz <[email protected]>2018-07-22 20:01:31 -0500
committerRapptz <[email protected]>2018-08-22 21:06:09 -0400
commitbb8b3bf2aa6fab11dbe2bd780a1c11883d19c2bb (patch)
tree0e92f892fd668a72e2d4d0c4d1b0822fd5f64f64
parentAdd support for splash(_url) to invites (diff)
downloaddiscord.py-bb8b3bf2aa6fab11dbe2bd780a1c11883d19c2bb.tar.xz
discord.py-bb8b3bf2aa6fab11dbe2bd780a1c11883d19c2bb.zip
Add Colour.from_hsv
HSV is an easier to use colour format, and its inclusion in the colour module will hopefully encourage its use.
-rw-r--r--discord/colour.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/discord/colour.py b/discord/colour.py
index 8f042687..d91aa2a1 100644
--- a/discord/colour.py
+++ b/discord/colour.py
@@ -24,6 +24,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
+import colorsys
+
class Colour:
"""Represents a Discord role colour. This class is similar
to an (red, green, blue) :class:`tuple`.
@@ -105,6 +107,12 @@ class Colour:
return cls((r << 16) + (g << 8) + b)
@classmethod
+ def from_hsv(cls, h, s, v):
+ """Constructs a :class:`Colour` from an HSV tuple."""
+ rgb = colorsys.hsv_to_rgb(h, s, v)
+ return cls.from_rgb(*(int(x * 255) for x in rgb))
+
+ @classmethod
def default(cls):
"""A factory method that returns a :class:`Colour` with a value of 0."""
return cls(0)