px普贤教程PuXian
普贤教程 › 包参考

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_rgbhex_str
co_rgb_to_hexr, g, b
co_rgb_to_hslr, g, b
co_hsl_to_rgbh, s, l
co_rgb_to_hsvr, g, b
co_hsv_to_rgbh, s, v
co_lightenhex_str, amount
co_darkenhex_str, amount
co_saturatehex_str, amount
co_desaturatehex_str, amount
co_grayscalehex_str
co_inverthex_str
co_complementhex_str
co_mixhex1, hex2, weight = 0.5
co_luminancer, g, b
co_contrast_ratiohex1, hex2
co_is_lighthex_str
co_is_darkhex_str
co_random
co_namedname
其余 4 个 def(内部与辅助,可直接调用但不属稳定接口)
函数参数
co_hex_pairs
co_hex_digitc
co_to_hexn
co_hue_to_rgbp, 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)            → 命名颜色查表
============================================================