rgbas

class janim.components.rgbas.Cmpt_Rgbas(*args, **kwargs)

Bases: Component, Generic

Color component

copy() Self
become(other: Cmpt_Rgbas) Self
not_changed(other: Cmpt_Rgbas) bool
classmethod align_for_interpolate(cmpt1: Cmpt_Rgbas, cmpt2: Cmpt_Rgbas)
interpolate(cmpt1: Cmpt_Rgbas, cmpt2: Cmpt_Rgbas, alpha: float, *, path_func=None) None
is_transparent() None
get() ndarray
static format_rgbas(rgbas: RgbaArray) ndarray

Convert the passed value to a numeric array

static format_colors(colors: ColorArray) ndarray

Format ColorArray (each element may be a string or [r, g, b]) into a numeric array format where elements are only [r, g, b]

static format_color(color: JAnimColor) ndarray

Unify strings, [r, g, b], etc. into [r, g, b] numeric array format

static format_alphas(alphas: AlphaArray) ndarray

Convert the passed value to a numeric array

set_rgbas(rgbas: RgbaArray) Self

Directly set rgba data

set(color: JAnimColor | ColorArray | None = None, alpha: Alpha | AlphaArray | None = None, *, root_only: bool = False) Self
  • colors represents the RGB color data passed in, which can be a single color or a color array (for single data, supports formats like '#FF0000', 'red', [1, 0, 0.5])

  • alphas represents the transparency data passed in, which can be a single number or an array (for single data, 1 means opaque, 0 means fully transparent)

  • By default, all descendant items will also be set to the specified color; passing root_only=True will only set the root item’s color

Special parameter passing:

  • When colors is four-component RGBA color data, it represents both colors and alphas, so the alphas parameter cannot be passed separately

clear() Self

Reset color data to default value

reverse() Self
resize(length: int) Self
count() int
apart_alpha(n: int) Self

Apply apart_alpha() to each color data

fade(factor: float, *, root_only: bool = False) Self

Fade color, factor is a value from 0~1, for example 0 has no effect, 0.5 fades half, 1 completely fades (becomes invisible)

mix(color: JAnimColor, factor: float = 0.5, *, root_only: bool = False) Self

Mix colors, by default get the intermediate color mixed with color

mix_alpha(alpha: float, factor: float = 0.5, *, root_only: bool = False) Self

Mix transparency, by default get the intermediate color mixed with alpha

janim.components.rgbas.merge_alpha(alpha: float, n: int) float

Calculate the transparency after alpha is overlapped and mixed n times

janim.components.rgbas.apart_alpha(alpha: float, n: int, *, eps: float = 0.001) float

Separate transparency into n parts, so that when these n parts are mixed, they still appear as the original transparency

Enables better rendering of overlapping parts that occur during alignment