1 个不稳定版本
0.1.0 | 2021年1月16日 |
---|
#203 在 多媒体
4KB
50 行
这是一个 Rust 编程语言的模块,用于处理颜色。
API
// Importing module
extern crate Color;
// Get luminance from RGB
let lum = Color::luminance([255, 255, 255]);
assert_eq!(1.0, lum);
// Create RGB instance from hex value
let rgb = Color::RGB::from_hex("#00ff00").unwrap();
// Get RGB value.
assert_eq!([0, 255, 0], rgb.value());
// Create RGB instance
let mut rgb = Color::RGB([0, 0, 0]);
// Inverted rgb value
rgb.inverted();
assert_eq!([255, 255, 255], rgb.value());
// Convart rgb to hex value
let color_hex = rgb.to_hex();
assert_eq!("ffffff", color_hex);
// Get contrast ratio between two colors.
let contrast = rgb.contrast_ratio([0, 0, 0]);
assert_eq!(21.0, contrast);