batgrl.colors.gradients#

Functions for blending colors and creating color gradients.

Functions

darken_only(a, b)

Return a color that is the minimum of each channel in a and b.

gradient(start, end, ncolors)

Return a gradient from start to end with ncolors (> 1) colors.

lerp_colors(a, b, p)

Linear interpolation from a to b with proportion p.

lighten_only(a, b)

Return a color that is the maximum of each channel in a and b.

rainbow_gradient(n, *[, alpha])

Return a rainbow gradient of n colors.

batgrl.colors.gradients.darken_only(a: Color, b: Color) Color#

Return a color that is the minimum of each channel in a and b.

Parameters:
aColor

A color.

bColor

A color.

Returns:
Color

A color with smallest components of a and b.

batgrl.colors.gradients.gradient(start: T, end: T, ncolors: int) list[T]#

Return a gradient from start to end with ncolors (> 1) colors.

Parameters:
start(Color, AColor, tuple[int, …])

Start color of gradient.

end(Color, AColor, tuple[int, …])

End color of gradient.

ncolorsint

Number of colors in gradient.

Returns:
list[(Color, AColor, tuple[int, …])]

A gradient of colors from start to end.

batgrl.colors.gradients.lerp_colors(a: T, b: T, p: float) T#

Linear interpolation from a to b with proportion p.

Parameters:
a(Color, AColor, tuple[int, …])

A color.

b(Color, AColor, tuple[int, …])

A color.

pfloat

Proportion from a to b.

Returns:
(Color, AColor, tuple[int, …])

The linear interpolation of a and b.

batgrl.colors.gradients.lighten_only(a: Color, b: Color) Color#

Return a color that is the maximum of each channel in a and b.

Parameters:
aColor

A color.

bColor

A color.

Returns:
Color

A color with largest components of a and b.

batgrl.colors.gradients.rainbow_gradient(n: int, *, alpha: int | None = None) list[Color | AColor]#

Return a rainbow gradient of n colors.

Parameters:
nint

Number of colors in gradient.

alphaint | None, default: None

If alpha is not given, gradient colors will have no alpha channel. Otherwise, the color’s alpha channel is given by alpha.

Returns:
list[Color | AColor]

A rainbow gradient of colors.