Skip to content

引入

ts
import { rgb2hsv, hsv2rgb } from 't-comm';

// 不支持 tree-shaking 的项目
import { rgb2hsv, hsv2rgb} from 't-comm/lib/color/index';

// 只支持 ESM 的项目
import { rgb2hsv, hsv2rgb} from 't-comm/es/color/index';

rgb2hsv()

描述:Converts an RGB color value to HSV Assumes: r, g, and b are contained in the set [0, 255] or [0, 1]. Returns: { h, s, v } in [0,1]

参数

示例

ts
rgb2hsv(0, 0, 0);
// { h: 0, s: 0, v: 0 }

rgb2hsv(255, 255, 255);
// { h: 0, s: 0, v: 100 }

rgb2hsv(217, 236, 188);
// { h: 83.75, s: 20.34, v: 92.55 }

hsv2rgb()

描述:Converts an HSV color value to RGB. Assumes: h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]. Returns: { r, g, b } in the set [0, 255]

参数

示例

ts
hsv2rgb(0, 0, 0);
// { r: 0, g: 0, b: 0 }

hsv2rgb(0, 0, 100);
// { r: 255, g: 255, b: 255 }

hsv2rgb(83.75, 20.34, 92.55);
// { r: 217, g: 236, b: 188 }