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 图像
1,968 每月下载量
用于 13 个crate(3 个直接使用)
1MB
294 行
HSLuv 的 Rust 实现。
演示
演示链接: 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
.
贡献
- 分叉它 ( http://github.com/dvdplm/hsluv-rust )
- 创建你的功能分支 (
git checkout -b my-new-feature
) - 提交你的更改 (
git commit -am 'Add some feature'
) - 推送到分支 (
git push origin my-new-feature
) - 创建一个新的拉取请求