普贤教程 › 包参考
colorutil 包
颜色工具
| 项 | 值 |
|---|---|
| 包名 | colorutil |
| 版本 | 0.1.0 |
| 入口 | colorutil.px |
| 分类 | 图形与媒体 |
| 文件数 / 行数 | 1 / 324 |
安装与引入
bash
pxpkg init # 首次 pxpkg add colorutil@0.1.0 pxpkg install
px
import colorutil所属分类教程:图形与媒体
公开接口
| 函数 | 参数 |
|---|---|
co_hex_to_rgb | hex_str |
co_rgb_to_hex | r, g, b |
co_rgb_to_hsl | r, g, b |
co_hsl_to_rgb | h, s, l |
co_rgb_to_hsv | r, g, b |
co_hsv_to_rgb | h, s, v |
co_lighten | hex_str, amount |
co_darken | hex_str, amount |
co_saturate | hex_str, amount |
co_desaturate | hex_str, amount |
co_grayscale | hex_str |
co_invert | hex_str |
co_complement | hex_str |
co_mix | hex1, hex2, weight = 0.5 |
co_luminance | r, g, b |
co_contrast_ratio | hex1, hex2 |
co_is_light | hex_str |
co_is_dark | hex_str |
co_random | |
co_named | name |
其余 4 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
co_hex_pair | s |
co_hex_digit | c |
co_to_hex | n |
co_hue_to_rgb | p, q, t |
包内说明(源码头注释)
text
============================================================ 普贤生态库:registry/colorutil — 颜色工具 ------------------------------------------------------------ 纯函数库,双模式一致。 对齐 PHP color tools / Python colormath / Go color: co_hex_to_rgb(hex) → "#FF8800" → [255, 136, 0] co_rgb_to_hex(r, g, b) → [255,136,0] → "#FF8800" co_rgb_to_hsl(r, g, b) → RGB → HSL [h(0-360), s(0-1), l(0-1)] co_hsl_to_rgb(h, s, l) → HSL → RGB [r,g,b] co_rgb_to_hsv(r, g, b) → RGB → HSV co_hsv_to_rgb(h, s, v) → HSV → RGB co_lighten(hex, amount) → 颜色变亮 co_darken(hex, amount) → 颜色变暗 co_saturate(hex, amount) → 增加饱和度 co_desaturate(hex, amount)→ 降低饱和度 co_grayscale(hex) → 灰度化 co_invert(hex) → 反色 co_complement(hex) → 互补色 co_mix(hex1, hex2, weight)→ 混合两个颜色 co_luminance(r, g, b) → 相对亮度 co_contrast_ratio(c1, c2) → 对比度比 co_is_light(hex) → 是否浅色 co_is_dark(hex) → 是否深色 co_random() → 随机颜色 co_named(name) → 命名颜色查表 ============================================================