Struct palette::gradient::Gradient [−][src]
pub struct Gradient<C, T = Vec<(<C as Mix>::Scalar, C)>>(_, _)
where
C: Mix + Clone,
T: AsRef<[(C::Scalar, C)]>;
A linear interpolation between colors.
It’s used to smoothly transition between a series of colors, that can be
either evenly spaced or have customized positions. The gradient is
continuous between the control points, but it’s possible to iterate over a
number of evenly spaced points using the take
method. Any point outside
the domain of the gradient will have the same color as the closest control
point.
Implementations
impl<C, T> Gradient<C, T> where
C: Mix + Clone,
T: AsRef<[(C::Scalar, C)]>,
[src]
impl<C, T> Gradient<C, T> where
C: Mix + Clone,
T: AsRef<[(C::Scalar, C)]>,
[src]pub fn get(&self, i: C::Scalar) -> C
[src]
Get a color from the gradient. The color of the closest control point
will be returned if i
is outside the domain.
pub fn with_domain(colors: T) -> Gradient<C, T>
[src]
Create a gradient of colors with custom spacing and domain. There must be at least one color and they are expected to be ordered by their position value.
pub fn take(&self, n: usize) -> Take<'_, C, T>ⓘ
[src]
Take n
evenly spaced colors from the gradient, as an iterator. The
iterator includes both ends of the gradient, for n > 1
, or just
the lower end of the gradient for n = 0
.
For example, take(5)
will include point 0.0 of the gradient, three
intermediate colors, and point 1.0 spaced apart at 1/4 the distance
between colors 0.0 and 1.0 on the gradient.
use approx::assert_relative_eq; use palette::{Gradient, LinSrgb}; let gradient = Gradient::new(vec![ LinSrgb::new(1.0, 1.0, 0.0), LinSrgb::new(0.0, 0.0, 1.0), ]); let taken_colors: Vec<_> = gradient.take(5).collect(); let colors = vec![ LinSrgb::new(1.0, 1.0, 0.0), LinSrgb::new(0.75, 0.75, 0.25), LinSrgb::new(0.5, 0.5, 0.5), LinSrgb::new(0.25, 0.25, 0.75), LinSrgb::new(0.0, 0.0, 1.0), ]; for (c1, c2) in taken_colors.iter().zip(colors.iter()) { assert_relative_eq!(c1, c2); }
pub fn slice<R: Into<Range<C::Scalar>>>(&self, range: R) -> Slice<'_, C, T>
[src]
Slice this gradient to limit its domain.
pub fn domain(&self) -> (C::Scalar, C::Scalar)
[src]
Get the limits of this gradient’s domain.
impl<C: Mix + Clone> Gradient<C>
[src]
impl<C: Mix + Clone> Gradient<C>
[src]Trait Implementations
impl<C: Clone, T: Clone> Clone for Gradient<C, T> where
C: Mix + Clone,
T: AsRef<[(C::Scalar, C)]>,
[src]
impl<C: Clone, T: Clone> Clone for Gradient<C, T> where
C: Mix + Clone,
T: AsRef<[(C::Scalar, C)]>,
[src]Auto Trait Implementations
impl<C, T> RefUnwindSafe for Gradient<C, T> where
C: RefUnwindSafe,
T: RefUnwindSafe,
C: RefUnwindSafe,
T: RefUnwindSafe,
impl<C, T> Send for Gradient<C, T> where
C: Send,
T: Send,
C: Send,
T: Send,
impl<C, T> Sync for Gradient<C, T> where
C: Sync,
T: Sync,
C: Sync,
T: Sync,
impl<C, T> Unpin for Gradient<C, T> where
C: Unpin,
T: Unpin,
C: Unpin,
T: Unpin,
impl<C, T> UnwindSafe for Gradient<C, T> where
C: UnwindSafe,
T: UnwindSafe,
C: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
T: FloatComponent,
Swp: WhitePoint,
Dwp: WhitePoint,
D: AdaptFrom<S, Swp, Dwp, T>,
[src]
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
T: FloatComponent,
Swp: WhitePoint,
Dwp: WhitePoint,
D: AdaptFrom<S, Swp, Dwp, T>,
[src]pub fn adapt_into_using<M>(Self, M) -> D where
M: TransformMatrix<Swp, Dwp, T>,
[src]
M: TransformMatrix<Swp, Dwp, T>,
fn adapt_into(self) -> D
[src]
impl<T, U> IntoColor<U> for T where
U: FromColor<T>,
[src]
impl<T, U> IntoColor<U> for T where
U: FromColor<T>,
[src]pub fn into_color(Self) -> U
[src]
impl<T, U> IntoColorUnclamped<U> for T where
U: FromColorUnclamped<T>,
[src]
impl<T, U> IntoColorUnclamped<U> for T where
U: FromColorUnclamped<T>,
[src]pub fn into_color_unclamped(Self) -> U
[src]
impl<T, U> TryIntoColor<U> for T where
U: TryFromColor<T>,
[src]
impl<T, U> TryIntoColor<U> for T where
U: TryFromColor<T>,
[src]