pygfx.utils.Color
- class pygfx.utils.Color(*args)
Bases:
object
A representation of color (in the sRGB colorspace).
Internally the color is stored using 4 32-bit floats (rgba). It can be instantiated in a variety of ways. E.g. by providing the color components as values between 0 and 1:
Color(r, g, b, a) providing rgba values.
Color(r, g, b) providing rgb, alpha is 1.
Color(gray, a) grayscale intensity and alpha.
Color(gray) grayscale intensity.
The above variations can also be supplied as a single tuple/list, or anything that:
Color((r, g, b)).
Named colors:
Color(“red”) base color names.
Color(“cornflowerblue”) CSS color names.
Color(“m”) Matlab color chars.
Hex colors:
Color(“#ff0000”) the common hex format.
Color(“#ff0000ff”) the hex format that includes alpha.
Color(“#ff0”) the short form hex format.
Color(“#ff0f”) the short form hex format that includes alpha.
CSS color functions:
Color(“rgb(255, 0, 0)”).
Color(“rgba(255, 0, 0, 1.0)”).
- Parameters:
args (tuple, int, str) – The color specification. Check the docstring of this function for details on available format options.
- property rgba
The RGBA tuple (values between 0 and 1).
- property rgb
The RGB tuple (values between 0 and 1).
- property r
The red value.
- property g
The green value.
- property b
The blue value.
- property a
The alpha (transparency) value, between 0 and 1.
- property gray
Return the grayscale intensity.
- property hex
The CSS hex string, e.g. “#00ff00”. The alpha channel is ignored. Values are clipped to 00 an ff.
- property hexa
The hex string including alpha, e.g. “#00ff00ff”. Values are clipped to 00 an ff.
- property css
The CSS color string, e.g. “rgba(0,255,0,0.5)”.
- clip()
Return a new Color with the values clipped between 0 and 1.
- classmethod from_physical(r, g, b, a=1)
Create a Color object from a color in the physical colorspace.
With the physical colorspace we mean what is sometimes called Linear-sRGB. It has the same gamut as sRGB, but where sRGB is linear w.r.t. human perception, Linear-sRGB is linear w.r.t. lumen and photon counts. Calculations on colors in pygfx’s shaders are done in the physical colorspace.
- to_physical()
Get the color represented in the physical colorspace, as 3 floats.
- classmethod from_hsv(hue, saturation, value)
Create a Color object from an a color in the HSV (a.k.a. HSB) colorspace.
HSV stands for hue, saturation, value (aka brightness). The hue component indicates the color tone. Values go from red (0) to green (0.333) to blue (0.666) and back to red (1). The satutation indicates vividness, with 0 meaning gray and 1 meaning the primary color. The value/brightness indicates goes from 0 (black) to 1 (white).
- to_hsv()
Get the color represented in the HSV colorspace, as 3 floats.
- classmethod from_hsl(hue, saturation, lightness)
Create a Color object from an a color in the HSL colorspace.
The HSL colorspace is similar to the HSV colorspace, except the “value” is replaced with “lightness”. This lightness scales the color differently, e.g. a lightness of 1 always represents full white.
- to_hsl()
Get the color represented in the HSL colorspace, as 3 floats.