#color #rgb

color-code

A library to work with color

1 unstable release

0.1.0 Jan 16, 2021

#176 in Multimedia

MIT license

4KB
50 lines

This is a module for rust programing language,To work with color.

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

No runtime deps