#color-conversion #color #hex-color #conversion #convert #hsluv #hpluv

rust-hsluv

颜色转换。将颜色转换为各种颜色表示:十六进制、RGB、HSLuv、Hpluv、Lch 和 xyz。

4 个版本

使用旧的 Rust 2015

0.1.4 2020 年 6 月 2 日
0.1.3 2017 年 11 月 28 日
0.1.2 2017 年 11 月 16 日
0.1.1 2017 年 11 月 16 日

#251 in 图像

Download history 668/week @ 2024-04-06 485/week @ 2024-04-13 743/week @ 2024-04-20 1043/week @ 2024-04-27 911/week @ 2024-05-04 1334/week @ 2024-05-11 1145/week @ 2024-05-18 528/week @ 2024-05-25 945/week @ 2024-06-01 332/week @ 2024-06-08 533/week @ 2024-06-15 375/week @ 2024-06-22 430/week @ 2024-06-29 540/week @ 2024-07-06 349/week @ 2024-07-13 601/week @ 2024-07-20

1,968 每月下载量
用于 13 个crate(3 个直接使用)

MIT 许可证

1MB
294

HSLuv 的 Rust 实现。

演示

Demo

演示链接: http://www.hsluv.org/syntax/#006925

安装

将此行添加到您的应用 Cargo.toml 文件中

[dependencies]
hsluv = "0.1.2"

用法

  • hue 是介于 0 和 360 之间的 64 位浮点数
  • saturation 是介于 0 和 100 之间的 64 位浮点数
  • lightness 是介于 0 和 100 之间的 64 位浮点数
  • hex 是颜色的十六进制格式
  • red 是介于 0 和 1 之间的 64 位浮点数
  • green 是介于 0 和 1 之间的 64 位浮点数
  • blue 是介于 0 和 1 之间的 64 位浮点数
extern crate hsluv;

use hsluv::*;

fn main() {
  let hex = "#ab3912";
  let hsluv = hex_to_hsluv(hex);
  let rgb = hsluv_to_rgb(hsluv);

  println!("Convert HEX {:?} to HSLUV: {:?}", hex, hsluv);
  println!("Convert HSLUV {:?} to RGB: {:?}", hsluv, rgb);
  println!("Convert RGB {:?} to HEX: {:?}", rgb, rgb_to_hex(rgb));
}

所有 API 调用都接受并返回一个 64 位浮点数的 3 元组,除了 *_to_hex() 函数: hsluv_to_hex()hpluv_to_hex()rgb_to_hex(),它们返回 String

hsluv::hsluv_to_hex((hue, saturation, lightness)) -> 作为十六进制字符串的颜色

hsluv::hsluv_to_hex((12.177, 100.0, 53.23)) // => #ff0000

hsluv::hsluv_to_rgb((hue, saturation, lightness)) -> RGB 颜色

hsluv::hsluv_to_rgb(12.177, 100.0, 53.23) // => (0.9998643703868711, 0.00000000000006849859221502719, 0.000008791283550555612)

hsluv::hex_to_hsluv(hex) -> 如上所述的浮点数列表

hsluv::hex_to_hsluv("#ff0000") // => (12.177050630061776, 100.0000000000022, 53.23711559542933)

hsluv::rgb_to_hsluv(rgb) -> 如上定义的浮点数列表

hsluv::rgb_to_hsluv((0.99, 6.84e-14, 8.79e-16)) // => (12.17705063006216, 100.00000000000209, 52.711595266911985)

对于HPLuv(过去式变体),使用

  • hpluv_to_hex
  • hpluv_to_rgb
  • hex_to_hpluv
  • rgb_to_hpluv

测试

运行 cargo test.

贡献

  1. 分叉它 ( http://github.com/dvdplm/hsluv-rust )
  2. 创建你的功能分支 (git checkout -b my-new-feature)
  3. 提交你的更改 (git commit -am 'Add some feature')
  4. 推送到分支 (git push origin my-new-feature)
  5. 创建一个新的拉取请求

无运行时依赖