color¶
Color representation and Algan’s named color palette.
Algan stores color in five channels – red, green, blue, glow, alpha – so
that emissive strength travels with a color the way opacity does. RGB and alpha
are in [0, 1]; glow is an additive brightness fed to the bloom accumulator.
Color accepts the forms you would expect – a hex string such as
"#58C4DD", or an (r, g, b) tuple – with glow and opacity as
separate arguments. It subclasses torch.Tensor, so a color takes part
in ordinary tensor arithmetic and can carry batch dimensions.
Color.add_defaults() pads a bare RGB or RGBA tensor out to the five-channel
layout, which is how the API accepts the shorter forms wherever a color array is
expected.
The module then defines the palette exported by from algan import *:
BLACK, WHITE, the greys, and the BLUE/RED/GREEN/YELLOW
families with their _A (lightest) through _E (darkest) shades. Both
British and American spellings of grey are provided. Two special values are worth
knowing: TRANSPARENT (invisible, and the background color that produces an
alpha-channel video) and GLOW (black with full glow).
Classes
A color, as five channels: red, green, blue, glow and opacity. |
Functions
- to_color(value)[source]¶
Coerce a user-supplied color into something Algan can store.
The colors Algan hands out are
Colorconstants, but the ones users reach for first are the ones every other graphics library takes: a hex string, a CSS name, a hex int, an RGB triple. Materials have accepted all of those since they were written –MeshStandardMaterial(color= 0x8B5A2B)is how the shipped presets are spelled – whileSquare( color="#ff0000")raisedAttributeError: 'str' object has no attribute 'reshape'from deep inside the timeline. This is the one place that decides, so both spellings mean the same thing.Anything already tensor-shaped is returned untouched: a per-row color buffer is a legitimate value and must not be collapsed to one color.
- Parameters:
value – A
Color, a hex string ("#ff0000") or CSS name ("red"), a hex int (0xff0000), an RGB/RGBA/RGBA+glow sequence of floats in[0, 1], a tensor, orNone.- Return type:
Coloror the value unchanged- Raises:
InvalidColorError – If
valueis a string that names no color, or a bool.