pub struct Interpolator { /* private fields */ }Expand description
An intermediate struct used for interpolating between colors.
This is the return value of DynamicColor::interpolate.
Implementations§
Source§impl Interpolator
impl Interpolator
Sourcepub fn eval(&self, t: f32) -> DynamicColor
pub fn eval(&self, t: f32) -> DynamicColor
Evaluate the color ramp at the given point.
Typically t ranges between 0 and 1, but that is not enforced,
so extrapolation is also possible.
Examples found in repository?
examples/interp.rs (line 36)
16fn main() {
17 let mut args = std::env::args().skip(1);
18 let c1_s = args.next().expect("give color as arg");
19 let c1 = color::parse_color(&c1_s).expect("error parsing color 1");
20 let c2_s = args.next().expect("give 2 colors as arg");
21 let c2 = color::parse_color(&c2_s).expect("error parsing color 2");
22 let cs_s_raw = args.next();
23 let cs_s = cs_s_raw.as_deref().unwrap_or("srgb");
24 let cs: ColorSpaceTag = cs_s.parse().expect("error parsing color space");
25 const N: usize = 20;
26 println!("<!DOCTYPE html>");
27 println!("<html>");
28 println!("<head>");
29 println!("<style>");
30 println!("div.g {{ height: 100px }}");
31 let pct = 100.0 / N as f64;
32 println!("span {{ width: {pct}%; display: inline-block; height: 100px; margin: 0 }}");
33 let interpolator = c1.interpolate(c2, cs, HueDirection::default());
34 for i in 0..=N {
35 let t = i as f32 / (N as f32);
36 let c = interpolator.eval(t);
37 if i == 0 || i == N {
38 println!("#s{i} {{ background: {c}; width: {}% }}", pct / 2.0);
39 } else {
40 println!("#s{i} {{ background: {c} }}");
41 }
42 }
43 println!("#basic {{ background: linear-gradient(to right in {cs_s}, {c1_s}, {c2_s}) }}");
44 println!("</style>");
45 println!("</head>");
46 println!("<body>");
47 println!("<div>{c1_s} {c2_s} {cs_s}</div>");
48 println!("<div class='g' id='basic'></div>");
49 println!("<div class='g'>");
50 for i in 0..=N {
51 print!("<span id='s{i}'></span>");
52 }
53 println!();
54 println!("</div>");
55 println!("</body>");
56 println!("</html>");
57}Trait Implementations§
Source§impl Clone for Interpolator
impl Clone for Interpolator
Source§fn clone(&self) -> Interpolator
fn clone(&self) -> Interpolator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for Interpolator
Auto Trait Implementations§
impl Freeze for Interpolator
impl RefUnwindSafe for Interpolator
impl Send for Interpolator
impl Sync for Interpolator
impl Unpin for Interpolator
impl UnsafeUnpin for Interpolator
impl UnwindSafe for Interpolator
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