gradpyent module
Generate color gradients from RGB, HTML, and KML color inputs.
- class gradpyent.Gradient(gradient_start: RGB | list[int] | tuple[int, int, int] | str | None = None, gradient_end: RGB | list[int] | tuple[int, int, int] | str | None = None, opacity: float | None = 1.0)[source]
Bases:
objectRepresents a color gradient between two points.
- generate(steps: int) list[RGB][source]
Generate a list of evenly spaced colors along the gradient.
- Parameters:
steps (int) – How many colors to generate (>=2).
- Returns:
List of RGB objects from start to end color.
- Return type:
List[RGB]
- Raises:
ValueError – If steps < 2.
- get_color_at(t: float) RGB[source]
Interpolate color at position t along the gradient.
- Parameters:
t (float) – Position between start and end, in [0.0, 1.0].
- Returns:
Interpolated color at position t.
- Return type:
- Raises:
ValueError – If t is not within [0.0, 1.0].
- get_gradient_series(series: Iterable[Any], fmt: str = 'rgb', opacity: float | None = None) list[RGB | tuple[int, int, int] | str][source]
Generate a gradient mapped to the values in a numeric series.
- Parameters:
- Returns:
List of colors in the requested format, one for each series value.
- Return type:
List
- Raises:
ValueError – If the series is empty or contains non-numeric values.
- class gradpyent.RGB(red: int, green: int, blue: int)[source]
Bases:
objectRepresents a color in RGB format.
- gradpyent.get_verified_color(arg: str | RGB | Sequence[int]) RGB[source]
- gradpyent.get_verified_color(arg: str) RGB
- gradpyent.get_verified_color(arg: RGB) RGB
- gradpyent.get_verified_color(arg: Sequence) RGB
Convert an input value to an RGB instance.
- Supported input types are:
str: named color, “rgb(r,g,b)” string, HTML hex (“#RRGGBB”), or KML hex (“AABBGGRR”)
RGB: color instance (returned as-is)
sequence of three integers: RGB tuple or list
- Parameters:
arg (Any) – Color value to convert.
- Returns:
The equivalent RGB color.
- Return type:
- Raises:
ValueError – If the input type or value is unrecognized.