欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

chroma.js 和 color.js:你的 JavaScript 颜色需求的最佳选择

最编程 2024-08-03 19:14:28
...

 

原文链接: 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

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

 

效果还行

 

用这个可以比较距离

这个比较会准确一点

安装

yarn add chroma-js

两个库的数值范围不一致

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());
}

 

 

 

 

 

推荐阅读