pub struct Color {
pub r: u8,
pub g: u8,
pub b: u8,
}Expand description
RGB Color representation
Fields§
§r: u8§g: u8§b: u8Implementations§
Source§impl Color
impl Color
Sourcepub fn new(r: u8, g: u8, b: u8) -> Self
pub fn new(r: u8, g: u8, b: u8) -> Self
Create a new RGB color
Examples found in repository?
examples/basic_usage.rs (line 22)
5fn main() {
6 // Load built-in colormap
7 println!("Loading Fire colormap...");
8 let fire = scala_chromatica::io::load_builtin_colormap("Fire")
9 .expect("Failed to load Fire colormap");
10
11 // Sample colors at different positions
12 println!("\nFire gradient samples:");
13 for i in 0..=10 {
14 let position = i as f64 / 10.0;
15 let color = fire.get_color(position);
16 println!(" {:.1}: RGB({}, {}, {})", position, color.r, color.g, color.b);
17 }
18
19 // Create custom gradient
20 println!("\nCreating custom gradient...");
21 let mut custom = ColorMap::new("RedBlue");
22 custom.add_stop(ColorStop::new(0.0, Color::new(255, 0, 0)));
23 custom.add_stop(ColorStop::new(0.5, Color::new(255, 255, 255)));
24 custom.add_stop(ColorStop::new(1.0, Color::new(0, 0, 255)));
25
26 println!("\nCustom gradient samples:");
27 for i in 0..=10 {
28 let position = i as f64 / 10.0;
29 let color = custom.get_color(position);
30 println!(" {:.1}: RGB({}, {}, {})", position, color.r, color.g, color.b);
31 }
32
33 // List all available colormaps
34 println!("\nListing all available colormaps...");
35 match scala_chromatica::io::list_available_colormaps() {
36 Ok(colormaps) => {
37 println!("Found {} colormap(s):", colormaps.len());
38 for info in colormaps {
39 let type_str = if info.is_builtin {
40 "built-in"
41 } else {
42 "custom"
43 };
44 println!(" - {} ({})", info.name, type_str);
45 }
46 }
47 Err(e) => eprintln!("Error listing colormaps: {}", e),
48 }
49
50 // Demonstrate HSV color creation
51 println!("\nHSV color examples:");
52 let red = Color::from_hsv(0.0, 1.0, 1.0);
53 println!(" Red (H=0): RGB({}, {}, {})", red.r, red.g, red.b);
54
55 let green = Color::from_hsv(120.0, 1.0, 1.0);
56 println!(" Green (H=120): RGB({}, {}, {})", green.r, green.g, green.b);
57
58 let blue = Color::from_hsv(240.0, 1.0, 1.0);
59 println!(" Blue (H=240): RGB({}, {}, {})", blue.r, blue.g, blue.b);
60}Sourcepub fn from_hsv(h: f64, s: f64, v: f64) -> Self
pub fn from_hsv(h: f64, s: f64, v: f64) -> Self
Create a color from HSV values
§Arguments
h- Hue (0.0 - 360.0)s- Saturation (0.0 - 1.0)v- Value/Brightness (0.0 - 1.0)
Examples found in repository?
examples/basic_usage.rs (line 52)
5fn main() {
6 // Load built-in colormap
7 println!("Loading Fire colormap...");
8 let fire = scala_chromatica::io::load_builtin_colormap("Fire")
9 .expect("Failed to load Fire colormap");
10
11 // Sample colors at different positions
12 println!("\nFire gradient samples:");
13 for i in 0..=10 {
14 let position = i as f64 / 10.0;
15 let color = fire.get_color(position);
16 println!(" {:.1}: RGB({}, {}, {})", position, color.r, color.g, color.b);
17 }
18
19 // Create custom gradient
20 println!("\nCreating custom gradient...");
21 let mut custom = ColorMap::new("RedBlue");
22 custom.add_stop(ColorStop::new(0.0, Color::new(255, 0, 0)));
23 custom.add_stop(ColorStop::new(0.5, Color::new(255, 255, 255)));
24 custom.add_stop(ColorStop::new(1.0, Color::new(0, 0, 255)));
25
26 println!("\nCustom gradient samples:");
27 for i in 0..=10 {
28 let position = i as f64 / 10.0;
29 let color = custom.get_color(position);
30 println!(" {:.1}: RGB({}, {}, {})", position, color.r, color.g, color.b);
31 }
32
33 // List all available colormaps
34 println!("\nListing all available colormaps...");
35 match scala_chromatica::io::list_available_colormaps() {
36 Ok(colormaps) => {
37 println!("Found {} colormap(s):", colormaps.len());
38 for info in colormaps {
39 let type_str = if info.is_builtin {
40 "built-in"
41 } else {
42 "custom"
43 };
44 println!(" - {} ({})", info.name, type_str);
45 }
46 }
47 Err(e) => eprintln!("Error listing colormaps: {}", e),
48 }
49
50 // Demonstrate HSV color creation
51 println!("\nHSV color examples:");
52 let red = Color::from_hsv(0.0, 1.0, 1.0);
53 println!(" Red (H=0): RGB({}, {}, {})", red.r, red.g, red.b);
54
55 let green = Color::from_hsv(120.0, 1.0, 1.0);
56 println!(" Green (H=120): RGB({}, {}, {})", green.r, green.g, green.b);
57
58 let blue = Color::from_hsv(240.0, 1.0, 1.0);
59 println!(" Blue (H=240): RGB({}, {}, {})", blue.r, blue.g, blue.b);
60}Trait Implementations§
Source§impl<'de> Deserialize<'de> for Color
impl<'de> Deserialize<'de> for Color
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Copy for Color
impl StructuralPartialEq for Color
Auto Trait Implementations§
impl Freeze for Color
impl RefUnwindSafe for Color
impl Send for Color
impl Sync for Color
impl Unpin for Color
impl UnwindSafe for Color
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more