| Crates.io | bigcolor |
| lib.rs | bigcolor |
| version | 1.2.1 |
| created_at | 2025-04-07 17:04:12.006665+00 |
| updated_at | 2025-09-15 17:44:19.900624+00 |
| description | A powerful Rust color library for parsing, converting, and manipulating colors across multiple formats |
| homepage | |
| repository | https://github.com/ducflair/bigcolor |
| max_upload_size | |
| id | 1624470 |
| size | 355,630 |
Rust Color Parser & Manipulation Library
A comprehensive Rust color manipulation library, inspired by TinyColor and Color.js. Designed to be intuitive, powerful, and fast for working with colors in various formats.
Extensive Color Support: Parse and manipulate colors in RGB, HSL, HSV, HSB, CMYK, LAB, LCH, OKLAB, OKLCH formats
Flexible Input Parsing: Accepts various input formats including hex, rgb(), rgba(), hsl(), hsla(), etc.
Color Modifications: Lighten, darken, saturate, desaturate, greyscale, spin
Color Schemes: Generate analogous, monochromatic, triad, tetrad, split complement, and complement colors
Contrast Calculation: Determine contrast ratios according to WCAG standards
Peniko Integration: Convert to/from the peniko Color library
Bulk Color Conversion: Convert between formats in large text blocks
use bigcolor::BigColor;
fn main() {
// Create colors from various formats
let hex_color = BigColor::new("#1a6ef5");
let rgb_color = BigColor::new("rgb(255, 0, 0)");
let hsl_color = BigColor::new("hsl(120, 100%, 50%)");
let rgba_color = BigColor::new("rgba(255, 0, 0, 0.5)");
// Convert to different formats
println!("As RGB: {}", hex_color.to_rgb_string());
println!("As HSL: {}", rgb_color.to_hsl_string());
println!("As HEX: {}", hsl_color.to_hex_string(false));
println!("As CMYK: {}", rgba_color.to_cmyk_string());
}
use bigcolor::BigColor;
fn main() {
let mut color = BigColor::new("#1a6ef5");
// Modify the color
color.lighten(Some(20.0)); // Lighten by 20%
println!("Lightened: {}", color.to_hex_string(false));
color = BigColor::new("#1a6ef5"); // Reset
color.darken(Some(20.0)); // Darken by 20%
println!("Darkened: {}", color.to_hex_string(false));
color = BigColor::new("#1a6ef5"); // Reset
color.saturate(Some(20.0)); // Saturate by 20%
println!("Saturated: {}", color.to_hex_string(false));
color = BigColor::new("#1a6ef5"); // Reset
color.desaturate(Some(20.0)); // Desaturate by 20%
println!("Desaturated: {}", color.to_hex_string(false));
color = BigColor::new("#1a6ef5"); // Reset
color.greyscale(); // Convert to greyscale
println!("Greyscale: {}", color.to_hex_string(false));
}
use bigcolor::BigColor;
fn main() {
let color = BigColor::new("#1a6ef5");
// Generate color schemes
let analogous = color.analogous(Some(5), Some(30));
let mono = color.monochromatic(Some(5));
let triad = color.triad();
let tetrad = color.tetrad();
let split = color.split_complement();
// Print the first color from each scheme
println!("Analogous: {}", analogous[0].to_hex_string(false));
println!("Monochromatic: {}", mono[0].to_hex_string(false));
println!("Triad: {}", triad[0].to_hex_string(false));
println!("Tetrad: {}", tetrad[0].to_hex_string(false));
println!("Split complement: {}", split[0].to_hex_string(false));
}
use bigcolor::BigColor;
fn main() {
let background = BigColor::new("#1a6ef5");
// Generate contrast colors with different intensities
let low_contrast = background.get_contrast_color(0.2);
let medium_contrast = background.get_contrast_color(0.5);
let high_contrast = background.get_contrast_color(1.0);
// Check contrast ratios (WCAG)
let ratio_low = background.get_contrast_ratio(&low_contrast);
let ratio_medium = background.get_contrast_ratio(&medium_contrast);
let ratio_high = background.get_contrast_ratio(&high_contrast);
println!("Background: {}", background.to_hex_string(false));
println!("Low contrast: {} (Ratio: {:.2}:1)", low_contrast.to_hex_string(false), ratio_low);
println!("Medium contrast: {} (Ratio: {:.2}:1)", medium_contrast.to_hex_string(false), ratio_medium);
println!("High contrast: {} (Ratio: {:.2}:1)", high_contrast.to_hex_string(false), ratio_high);
// Check if background is light or dark
println!("Is light color: {}", background.is_light());
}
use bigcolor::{BigColor, conversion};
use peniko::Color as PenikoColor;
fn main() {
// Convert from BigColor to peniko::Color
let big_color = BigColor::new("#1a6ef5");
let peniko_color = conversion::to_peniko_color(&big_color);
// Convert from peniko::Color to BigColor
let peniko_red = PenikoColor::from_rgb8(255, 0, 0);
let big_red = conversion::from_peniko_color(&peniko_red);
println!("Original: {}", big_color.to_hex_string(false));
println!("Converted back and forth: {}", big_red.to_hex_string(false));
}
#RGB, #RRGGBB, #RRGGBBAArgb(r, g, b), rgba(r, g, b, a), rgb(r%, g%, b%), rgba(r%, g%, b%, a)hsl(h, s%, l%), hsla(h, s%, l%, a), space-separated HSL valueshsv(h, s%, v%), hsva(h, s%, v%, a)cmyk(c%, m%, y%, k%)lab(l, a, b)lch(l, c, h)oklab(l%, a, b)oklch(l%, c, h)The project includes a web-based demo that showcases all of BigColor's capabilities:
cd demo
trunk serve
Then open your browser to http://localhost:8080
MIT
This library is partially a port of TinyColor by Brian Grinstead and inspired by Color.js.