From 717ac5652dc4487da2334b293e793de7cfe1caf4 Mon Sep 17 00:00:00 2001 From: Wim Pomp Date: Sat, 23 Aug 2025 22:28:29 +0200 Subject: [PATCH] short (single char) names for simple rgbcmykw --- Cargo.toml | 2 +- src/lib.rs | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c3a2d78..16921e2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "colorcet" -version = "0.2.0" +version = "0.2.1" edition = "2024" rust-version = "1.85.1" authors = ["Wim Pomp "] diff --git a/src/lib.rs b/src/lib.rs index 3b89c06..ea09556 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,7 +25,14 @@ pub enum ColorcetError { /// use colorcet::ColorMap; /// use colorgrad::{LinearGradient, Color}; /// +/// // get colormap by name, add _r to reverse the colormap /// let colormap: ColorMap = "glasbey".parse().unwrap(); +/// let colormap: ColorMap = "glasbey_r".parse().unwrap(); +/// let colormap: ColorMap = "red".parse().unwrap(); // black to red gradient +/// let colormap: ColorMap = "r".parse().unwrap(); // black to red gradient +/// let colormap: ColorMap = "r_r".parse().unwrap(); // red to black gradient +/// let colormap: ColorMap = "#5e6f7a".parse().unwrap(); +/// let colormap: ColorMap = "#5e6f7a_r".parse().unwrap(); /// let vec_color: Vec = colormap.clone().try_into().unwrap(); /// let vec_css: Vec = colormap.clone().try_into().unwrap(); /// let linear_gradient: LinearGradient = colormap.clone().try_into().unwrap(); @@ -105,7 +112,19 @@ impl FromStr for ColorMap { } Ok(ColorMap(cmap)) } else if let Ok(cmap) = GradientBuilder::new() - .html_colors(&["#000000", name0]) + .html_colors(&["#000000", { + match name0 { + "r" => "#ff0000", + "g" => "#008000", + "b" => "#0000ff", + "c" => "#00bfbf", + "m" => "#bf00bf", + "y" => "#bfbf00", + "k" => "#000000", + "w" => "#ffffff", + _ => name0, + } + }]) .build::() { let mut cmap: Vec<_> = cmap