colors#

final class wyvern.colors.Color(value: int)[source]#

Class representing a color in the RGB color space. Alias name Colour exists for convenience.

value#

The value of the color. This is a 24-bit integer, where the first 8 bits are the red value, the next 8 bits are the green value, and the last 8 bits are the blue value.

Type:

int

classmethod aqua() Color[source]#

Creates a Color object from the aqua color. This is #00ffff. (Aqua)

property b: int#

The blue value of the color.

classmethod black() Color[source]#

Creates a Color object from the black color. This is 0x000000. (Black)

classmethod blue() Color[source]#

Creates a Color object from the blue color. This is 0x0000ff. (Blue)

classmethod brown() Color[source]#

Creates a Color object from the brown color. This is #a52a2a. (Brown)

classmethod cyan() Color[source]#

Creates a Color object from the cyan color. This is 0x00ffff. (Cyan)

classmethod default() Color[source]#

Creates a Color object from the default color. This is 0x000000. (Black)

Examples

>>> Color.default()
Color(0)
classmethod from_hex(hex_value: str) Color[source]#

Creates a Color object from a hex value.

Parameters:

hex_value (str) – The hex value to use.

Returns:

A Color object.

Return type:

Color

Examples

>>> Color.from_hex('#ff0000')
Color(16776960)
>>> Color.from_hex('#00ff00')
Color(255)
>>> Color.from_hex('#0000ff')
Color(0)
classmethod from_hsl(h: float, s: float, l: float) Color[source]#

Creates a Color object from HSL values.

Parameters:
  • h (float) – The hue value.

  • s (float) – The saturation value.

  • l (float) – The lightness value.

Returns:

A Color object.

Return type:

Color

Examples

>>> Color.from_hsl(0, 1, 0.5)
Color(16711680)
>>> Color.from_hsl(120, 1, 0.5)
Color(16711680)
>>> Color.from_hsl(240, 1, 0.5)
Color(16711680)
classmethod from_hsv(h: float, s: float, v: float) Color[source]#

Creates a Color object from HSV values.

Parameters:
  • h (float) – The hue value.

  • s (float) – The saturation value.

  • v (float) – The value in HSV color space.

Returns:

A Color object.

Return type:

Color

Examples

>>> Color.from_hsv(0, 1, 1)
Color(16711680)
>>> Color.from_hsv(120, 1, 1)
Color(16711680)
>>> Color.from_hsv(240, 1, 1)
Color(16711680)
classmethod from_random() Color[source]#

Creates a Color object from a random color. Randomly generates a color in the RGB color space.

Returns:

A Color object.

Return type:

Color

classmethod from_rgb(r: int, g: int, b: int) Color[source]#

Creates a Color object from RGB values.

Parameters:
  • r (int) – The red value.

  • g (int) – The green value.

  • b (int) – The blue value.

Returns:

A Color object.

Return type:

Color

Examples

>>> Color.from_rgb(255, 0, 0)
Color(16711680)
>>> Color.from_rgb(0, 255, 0)
Color(65280)
>>> Color.from_rgb(0, 0, 255)
Color(255)
classmethod from_string(string: str) Color[source]#

Creates a Color object from a string.

Parameters:

string (str) – The string to use.

Returns:

A Color object.

Return type:

Color

Examples

>>> Color.from_string('rgb(255, 0, 0)')
Color(16711680)
>>> Color.from_string('hsl(0, 100%, 50%)')
Color(-80727249750)
>>> Color.from_string('hsv(0, 100%, 100%)')
Color(1022371500)
>>> Color.from_string('#ff0000')
Color(16776960)
property g: int#

The green value of the color.

classmethod gray() Color[source]#

Creates a Color object from the gray color. This is 0x808080. (Gray)

classmethod green() Color[source]#

Creates a Color object from the green color. This is 0x00ff00. (Green)

classmethod grey() Color[source]#

Creates a Color object from the grey color. This is 0x808080. (Grey)

property hex: str#

The hex value of the color.

property hsl: tuple[float, float, float]#

The HSL values of the color.

property hsv: tuple[float, float, float]#

The HSV values of the color.

classmethod magenta() Color[source]#

Creates a Color object from the magenta color. This is 0xff00ff. (Magenta)

classmethod orange() Color[source]#

Creates a Color object from the orange color. This is 0xffa500. (Orange)

classmethod purple() Color[source]#

Creates a Color object from the purple color. This is #800080. (Purple)

property r: int#

The red value of the color.

classmethod red() Color[source]#

Creates a Color object from the red color. This is 0xff0000. (Red)

property rgb: tuple[int, int, int]#

The RGB values of the color.

classmethod silver() Color[source]#

Creates a Color object from the silver color. This is #c0c0c0. (Silver)

classmethod white() Color[source]#

Creates a Color object from the white color. This is 0xffffff. (White)

classmethod yellow() Color[source]#

Creates a Color object from the yellow color. This is 0xffff00. (Yellow)

wyvern.colors.Colour#

An alias for the Color class.