Add Colour.from_hsv
HSV is an easier to use colour format, and its inclusion in the colour module will hopefully encourage its use.
This commit is contained in:
parent
c84287c007
commit
bb8b3bf2aa
@ -24,6 +24,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import colorsys
|
||||||
|
|
||||||
class Colour:
|
class Colour:
|
||||||
"""Represents a Discord role colour. This class is similar
|
"""Represents a Discord role colour. This class is similar
|
||||||
to an (red, green, blue) :class:`tuple`.
|
to an (red, green, blue) :class:`tuple`.
|
||||||
@ -104,6 +106,12 @@ class Colour:
|
|||||||
"""Constructs a :class:`Colour` from an RGB tuple."""
|
"""Constructs a :class:`Colour` from an RGB tuple."""
|
||||||
return cls((r << 16) + (g << 8) + b)
|
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
|
@classmethod
|
||||||
def default(cls):
|
def default(cls):
|
||||||
"""A factory method that returns a :class:`Colour` with a value of 0."""
|
"""A factory method that returns a :class:`Colour` with a value of 0."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user