跳转至

maliang.color.rgb

字数 117 个   代码 26 行   阅读时间 1 分钟   访问量

源代码:maliang/color/rgb.py

Some functions about RGB codes.

🔵blend

function public

1
2
3
4
def blend(
    *values: tuple[int, int, int],
    weights: list[float] | None = None,
) -> tuple[int, int, int]: ...
Mix colors by weight.

  • values: RGB codes
  • weights: weight list, default value indicates the same weights

🔵contrast

function public

1
2
3
4
5
6
def contrast(
    value: tuple[int, int, int],
    /,
    *,
    channels: tuple[bool, bool, bool] = (True, True, True),
) -> tuple[int, int, int]: ...
Get the contrasting color of a RGB code.

  • value: a RGB code
  • channels: three color channels

🔵gradient

function public

1
2
3
4
5
6
7
8
9
def gradient(
    first: tuple[int, int, int],
    second: tuple[int, int, int],
    count: int,
    rate: float = 1,
    *,
    channels: tuple[bool, bool, bool] = (True, True, True),
    contoller: collections.abc.Callable[[float], float] = linear,
) -> list[tuple[int, int, int]]: ...
Get a list of color gradients from one color to another proportionally.

  • first: the first RGB code
  • second: the second RGB code
  • count: the number of gradients
  • rate: transition rate
  • channels: three color channels
  • controller: control function

🔵transition

function public

1
2
3
4
5
6
7
def transition(
    first: tuple[int, int, int],
    second: tuple[int, int, int],
    rate: float,
    *,
    channels: tuple[bool, bool, bool] = (True, True, True),
) -> tuple[int, int, int]: ...
Transition one color to another proportionally.

  • first: the first RGB code
  • second: the second RGB code
  • rate: transition rate
  • channels: three color channels