pub struct ColorMap {
pub name: String,
pub stops: Vec<ColorStop>,
}Expand description
A colormap with multiple color stops and smooth interpolation
Fields§
§name: StringName of the colormap
stops: Vec<ColorStop>Ordered list of color stops
Implementations§
Source§impl ColorMap
impl ColorMap
Sourcepub fn with_stops(name: impl Into<String>, stops: Vec<ColorStop>) -> Self
pub fn with_stops(name: impl Into<String>, stops: Vec<ColorStop>) -> Self
Create a colormap with initial stops
Sourcepub fn remove_stop(&mut self, index: usize)
pub fn remove_stop(&mut self, index: usize)
Remove a color stop by index (minimum 2 stops required)
Sourcepub fn get_color(&self, position: f64) -> Color
pub fn get_color(&self, position: f64) -> Color
Get color at a specific position (0.0 to 1.0) by interpolating between stops
Sourcepub fn reversed(&self) -> Self
pub fn reversed(&self) -> Self
Create a new colormap with all stops reversed
This reverses the gradient by flipping all stop positions: a stop at position 0.2 becomes 0.8, etc.
§Examples
use scala_chromatica::{ColorMap, ColorStop, Color};
let mut map = ColorMap::new("RedToBlue");
map.add_stop(ColorStop::new(0.0, Color::new(255, 0, 0)));
map.add_stop(ColorStop::new(1.0, Color::new(0, 0, 255)));
let reversed = map.reversed();
// Now starts with blue at 0.0 and ends with red at 1.0Sourcepub fn slice(&self, start: f64, end: f64) -> Self
pub fn slice(&self, start: f64, end: f64) -> Self
Extract a portion of the gradient between start and end positions
Creates a new colormap containing only the colors between the specified positions, remapped to span the full 0.0-1.0 range.
§Arguments
start- Starting position (0.0 to 1.0)end- Ending position (0.0 to 1.0), must be > start
§Examples
use scala_chromatica::{ColorMap, ColorStop, Color};
let mut map = ColorMap::new("Rainbow");
map.add_stop(ColorStop::new(0.0, Color::new(255, 0, 0))); // Red
map.add_stop(ColorStop::new(0.5, Color::new(0, 255, 0))); // Green
map.add_stop(ColorStop::new(1.0, Color::new(0, 0, 255))); // Blue
// Extract middle 50% (green region)
let middle = map.slice(0.25, 0.75);
// Now spans yellow-green-cyan, remapped to 0.0-1.0Sourcepub fn discretize(&self, n: usize) -> Self
pub fn discretize(&self, n: usize) -> Self
Create a posterized version with N discrete color bands
Instead of smooth gradients, this quantizes the colormap into distinct color levels, useful for categorical data visualization or artistic effects.
§Arguments
n- Number of discrete color bands (minimum 2)
§Examples
use scala_chromatica::{ColorMap, ColorStop, Color};
let mut map = ColorMap::new("Smooth");
map.add_stop(ColorStop::new(0.0, Color::black()));
map.add_stop(ColorStop::new(1.0, Color::white()));
// Create 5-level grayscale
let posterized = map.discretize(5);
// Now has 5 distinct gray levels instead of smooth gradientSourcepub fn default_scheme() -> Self
pub fn default_scheme() -> Self
Default HSV-based color scheme (smooth rainbow)
Sourcepub fn fire_scheme() -> Self
pub fn fire_scheme() -> Self
Fire color scheme (black -> red -> orange -> yellow -> white)
Sourcepub fn ocean_scheme() -> Self
pub fn ocean_scheme() -> Self
Ocean color scheme (black -> deep blue -> cyan -> white)
Sourcepub fn grayscale_scheme() -> Self
pub fn grayscale_scheme() -> Self
Grayscale color scheme (black -> gray -> white)
Sourcepub fn rainbow_scheme() -> Self
pub fn rainbow_scheme() -> Self
Rainbow color scheme (full spectrum)