1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
use colorgrad::{
BasisGradient, BlendMode, CatmullRomGradient, Color, Gradient, GradientBuilder, LinearGradient,
};
macro_rules! preset {
($name:ident) => {
(Box::new(colorgrad::preset::$name()), stringify!($name))
};
}
pub fn preset() -> Vec<(Box<dyn Gradient>, &'static str)> {
vec![
preset!(sinebow),
preset!(turbo),
preset!(cividis),
preset!(rainbow),
preset!(cubehelix_default),
preset!(warm),
preset!(cool),
preset!(viridis),
preset!(inferno),
preset!(magma),
preset!(plasma),
preset!(bu_gn),
preset!(bu_pu),
preset!(gn_bu),
preset!(or_rd),
preset!(pu_bu_gn),
preset!(pu_bu),
preset!(pu_rd),
preset!(rd_pu),
preset!(yl_gn_bu),
preset!(yl_gn),
preset!(yl_or_br),
preset!(yl_or_rd),
preset!(br_bg),
preset!(pr_gn),
preset!(pi_yg),
preset!(pu_or),
preset!(rd_bu),
preset!(rd_gy),
preset!(rd_yl_bu),
preset!(rd_yl_gn),
preset!(spectral),
preset!(blues),
preset!(greens),
preset!(greys),
preset!(oranges),
preset!(purples),
preset!(reds),
]
}
pub fn blend_mode() -> Vec<(Box<dyn Gradient>, &'static str)> {
fn grad(mode: BlendMode) -> CatmullRomGradient {
GradientBuilder::new()
.html_colors(&["#fff", "#00f", "gold", "deeppink", "#000"])
.mode(mode)
.build::<CatmullRomGradient>()
.unwrap()
}
vec![
(Box::new(grad(BlendMode::Rgb)), "Rgb"),
(Box::new(grad(BlendMode::LinearRgb)), "LinearRgb"),
(Box::new(grad(BlendMode::Oklab)), "Oklab"),
(Box::new(grad(BlendMode::Lab)), "Lab"),
]
}
pub fn interpolation() -> Vec<(Box<dyn Gradient>, String)> {
let mut gradients: Vec<(Box<dyn Gradient>, String)> = Vec::new();
let colors = ["#C41189", "#00BFFF", "#FFD700"];
let modes = [
BlendMode::Rgb,
BlendMode::LinearRgb,
BlendMode::Oklab,
BlendMode::Lab,
];
for mode in modes.iter() {
let g = GradientBuilder::new()
.html_colors(&colors)
.mode(*mode)
.build::<LinearGradient>()
.unwrap();
gradients.push((Box::new(g), format!("Linear_{mode:?}")));
let g = GradientBuilder::new()
.html_colors(&colors)
.mode(*mode)
.build::<CatmullRomGradient>()
.unwrap();
gradients.push((Box::new(g), format!("CatmullRom_{mode:?}")));
let g = GradientBuilder::new()
.html_colors(&colors)
.mode(*mode)
.build::<BasisGradient>()
.unwrap();
gradients.push((Box::new(g), format!("Basis_{mode:?}")));
}
gradients
}
pub fn sharp() -> Vec<(Box<dyn Gradient>, String)> {
let mut gradients: Vec<(Box<dyn Gradient>, String)> = Vec::new();
let grad = colorgrad::preset::rainbow();
for i in 0..=10 {
let t = i as f32 / 10.0;
let g = grad.sharp(13, t);
gradients.push((Box::new(g), format!("sharp_{t}")));
}
gradients
}
|