Welcome to Python-flavored Magnum! Please note that, while already being rather stable, this functionality is still considered experimental and some APIs might get changed without preserving full backwards compatibility.

magnum.Color4 class

Color in linear RGBA color space

Static methods

def blue(blue: float = 1.0, alpha: float = 1.0) -> Color4
Blue color
def cyan(red: float = 0.0, alpha: float = 1.0) -> Color4
Cyan color
def from_hsv(hue: Deg, saturation: float, value: float, alpha: float = 1.0) -> Color4
Create RGB color from HSV representation
def from_linear_rgb_int(linear: int, a: float = 1.0) -> Color4
Create linear RGBA color from 24-bit linear RGB + alpha representation
def from_linear_rgba_int(linear: int) -> Color4
Create linear RGBA color from 32-bit linear representation
def from_srgb_alpha_int(srgb_alpha: int) -> Color4
Create linear RGBA color from 32-bit sRGB a alpha representation
def from_srgb_int(srgb: int, a: float = 1.0) -> Color4
Create linear RGBA color from 32-bit sRGB + alpha representation
def from_xyz(xyz: Vector3, a: float = 1.0) -> Color4
Create RGBA color from CIE XYZ representation
def green(green: float = 1.0, alpha: float = 1.0) -> Color4
Green color
def magenta(green: float = 0.0, alpha: float = 1.0) -> Color4
Magenta color
def red(red: float = 1.0, alpha: float = 1.0) -> Color4
Red color
def yellow(blue: float = 0.0, alpha: float = 1.0) -> Color4
Yellow color
def zero_init() -> Color4
Construct a zero vector
def zero_init() -> Color4
Construct a zero vector

Methods

def dot(self, /) -> float
Dot product of the vector
def flipped(self, /) -> Vector4
Flipped vector
def hue(self, /) -> Deg
Hue
def is_normalized(self, /) -> bool
Whether the vector is normalized
def is_zero(self, /) -> bool
Whether the vector is zero
def length(self, /) -> float
Vector length
def length_inverted(self, /) -> float
Inverse vector length
def max(self, /) -> float
Maximal value in the vector
def min(self, /) -> float
Minimal value in the vector
def minmax(self, /) -> typing.Tuple[float, float]
Minimal and maximal value in the vector
def normalized(self, /) -> Vector4
Normalized vector (of unit length)
def product(self, /) -> float
Product of values in the vector
def projected(self, line: Vector4) -> Vector4
Vector projected onto a line
def projected_onto_normalized(self, line: Vector4) -> Vector4
Vector projected onto a normalized line
def resized(self, length: float) -> Vector4
Resized vector
def saturation(self, /) -> float
Saturation
def sum(self, /) -> float
Sum of values in the vector
def to_hsv(self, /) -> typing.Tuple[Deg, float, float]
Convert to HSV representation
def to_linear_rgba_int(self, /) -> int
Convert to 32-bit integral linear RGBa representation
def to_srgb_alpha_int(self, /) -> int
Convert to 32-bit integral sRGB + linear alpha representation
def to_xyz(self, /) -> Vector3
Convert to CIE XYZ representation
def value(self, /) -> float
Value

Special methods

def __add__(self, arg0: Color4, /) -> Color4
Add a vector
def __eq__(self, arg0: Vector4, /) -> bool
Equality comparison
def __ge__(self, arg0: Vector4, /) -> BitVector4
Component-wise greater than or equal comparison
def __getattr__(self, arg0: str, /) -> object
Vector swizzle
def __getitem__(self, arg0: int, /) -> float
Value at given position
def __getstate__(self, /) -> bytes
Dumps the in-memory representation of vector components
def __gt__(self, arg0: Vector4, /) -> BitVector4
Component-wise greater than comparison
def __iadd__(self, arg0: Color4, /) -> Color4
Add and assign a vector
def __imul__(self, arg0: float, /) -> Color4
Multiply with a scalar and assign
def __imul__(self, arg0: Color4, /) -> Color4
Multiply a vector component-wise and assign
def __init__(self, rgb: Vector3, alpha: float = 1.0) -> None
Construct from a three-component color
def __init__(self, arg0: Vector4, /) -> None
Construct from a vector
def __init__(self, arg0: buffer, /) -> None
Construct from a buffer
def __init__(self, /) -> None
Default constructor
def __init__(self, /) -> None
Default constructor
def __init__(self, r: float, g: float, b: float, a: float = 1.0) -> None
Constructor
def __init__(self, rgb: float, alpha: float = 1.0) -> None
Construct with one value for all components
def __init__(self, arg0: typing.Tuple[float, float, float], /) -> None
Construct from a RGB tuple
def __init__(self, arg0: typing.Tuple[float, float, float, float], /) -> None
Construct from a RGBA tuple
def __isub__(self, arg0: Color4, /) -> Color4
Subtract and assign a vector
def __itruediv__(self, arg0: float, /) -> Color4
Divide with a scalar and assign
def __itruediv__(self, arg0: Color4, /) -> Color4
Divide a vector component-wise and assign
def __le__(self, arg0: Vector4, /) -> BitVector4
Component-wise less than or equal comparison
def __len__() -> int
Vector size. Returns 4.
def __lt__(self, arg0: Vector4, /) -> BitVector4
Component-wise less than comparison
def __mul__(self, arg0: float, /) -> Color4
Multiply with a scalar
def __mul__(self, arg0: Color4, /) -> Color4
Multiply a vector component-wise
def __ne__(self, arg0: Vector4, /) -> bool
Non-equality comparison
def __neg__(self, /) -> Color4
Negated vector
def __repr__(self, /) -> str
Object representation
def __rmul__(self, arg0: float, /) -> Color4
Multiply a scalar with a vector
def __rtruediv__(self, arg0: float, /) -> Color4
Divide a vector with a scalar and invert
def __setattr__(self, arg0: str, arg1: object, /) -> None
Vector swizzle
def __setitem__(self, arg0: int, arg1: float, /) -> None
Set a value at given position
def __setstate__(self, arg0: bytes, /) -> None
Treats the data as the in-memory representation of vector components
def __sub__(self, arg0: Color4, /) -> Color4
Subtract a vector
def __truediv__(self, arg0: float, /) -> Color4
Divide with a scalar
def __truediv__(self, arg0: Color4, /) -> Color4
Divide a vector component-wise

Properties

a: float get set
A component
b: float get set
B component
g: float get set
G component
r: float get set
R component
rgb: Color3 get set
RGB part of the vector
w: float get set
W component
x: float get set
X component
xy: Vector2 get set
XY part of the vector
xyz: Color3 get set
XYZ part of the vector
y: float get set
Y component
z: float get set
Z component

Method documentation

def magnum.Color4.__setstate__(self, arg0: bytes, /) -> None

Treats the data as the in-memory representation of vector components

Exceptions
ValueError If the data size doesn’t match type size