js 颜色库 chroma 和 color

原文链接: js 颜色库 chroma 和 color

上一篇: 仿照vue-lit 打造一个现代的web计数器组件

下一篇: 在线 ocr 文字识别 和 图片色值选取

以后颜色相关的准备使用chroma 实现

https://gka.github.io/chroma.js/#quick-start

https://github.com/gka/chroma.js/

https://github.com/Marak/colors.js

不仅是色值转换, 还有混合和度量

up-816ecc460074641411d1bc5b2bfa7ff7599.png

up-40f82b28c1d51f7fdec467498cdebd9a1ea.png

up-60e8c1098fa279115f33e5705a7f210e07e.png

效果还行

up-e86e933150f66e10525be78c2831274932a.png

用这个可以比较距离

up-13dce0b981e7d624f482d34d2ce5b179390.png

这个比较会准确一点

up-20213208ee1fd63504b956877750a84b6f7.png

安装

yarn add chroma-js

两个库的数值范围不一致

up-1258c4b49e244be72530bdf159690ab4c19.png

const Color = require("color");
const Chroma = require("chroma-js");
const list = [
  [161, 127, 132],
  [211, 123, 121],
  [200, 146, 152],
  [185, 139, 139],
  [159, 126, 129],
  [178, 149, 157],
  [169, 143, 147],
  [154, 124, 132],
  [193, 132, 128],
  [208, 122, 116],
];
for (const i of list) {
  const [r, g, b] = i;
  const color = Color.rgb(r, g, b);
  const [h, s, v] = color.hsv().color;
  console.log("color:", h, s, v);
  console.log("chroma:", Chroma(r, g, b).hsv());
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值