Crates.io | rust-hsluv |
lib.rs | rust-hsluv |
version | 0.1.4 |
source | src |
created_at | 2017-11-16 11:31:31.079442 |
updated_at | 2020-06-02 08:08:41.428538 |
description | Color converstions. Convert to/from various color representations: hex, rgb, hsluv, hpluv, lch and xyz. |
homepage | |
repository | https://github.com/dvdplm/rust-hsluv |
max_upload_size | |
id | 39537 |
size | 4,068,629 |
A Rust implementation of HSLuv.
Demo link: http://www.hsluv.org/syntax/#006925
Add this line to your application's Cargo.toml:
[dependencies]
hsluv = "0.1.2"
hue
is a 64bit float between 0 and 360saturation
is a 64bit float between 0 and 100lightness
is a 64bit float between 0 and 100hex
is the hexadecimal format of the colorred
is a 64bit float between 0 and 1green
is a 64bit float between 0 and 1blue
is a 64bit float between 0 and 1extern 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));
}
All API calls take and return a 3-tuple of 64bit floats, (f64, f64, f64)
except the *_to_hex()
functions: hsluv_to_hex()
, hpluv_to_hex()
, rgb_to_hex()
which return String
.
hsluv::hsluv_to_hex((12.177, 100.0, 53.23)) // => #ff0000
hsluv::hsluv_to_rgb(12.177, 100.0, 53.23) // => (0.9998643703868711, 0.00000000000006849859221502719, 0.000008791283550555612)
hsluv::hex_to_hsluv("#ff0000") // => (12.177050630061776, 100.0000000000022, 53.23711559542933)
hsluv::rgb_to_hsluv((0.99, 6.84e-14, 8.79e-16)) // => (12.17705063006216, 100.00000000000209, 52.711595266911985)
For HPLuv (the pastel variant), use:
hpluv_to_hex
hpluv_to_rgb
hex_to_hpluv
rgb_to_hpluv
Run cargo test
.
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)