Struct palette::gradient::Gradient

source ·
pub struct Gradient<C: Mix + Clone>(/* private fields */);
Expand description

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§

source§

impl<C: Mix + Clone> Gradient<C>

source

pub fn new<I: IntoIterator<Item = C>>(colors: I) -> Gradient<C>

Create a gradient of evenly spaced colors with the domain [0.0, 1.0]. There must be at least one color.

source

pub fn with_domain(colors: Vec<(C::Scalar, C)>) -> Gradient<C>

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.

source

pub fn get(&self, i: C::Scalar) -> C

Get a color from the gradient. The color of the closest control point will be returned if i is outside the domain.

source

pub fn take(&self, n: usize) -> Take<'_, C>

Take n evenly spaced colors from the gradient, as an iterator.

source

pub fn slice<R: Into<Range<C::Scalar>>>(&self, range: R) -> Slice<'_, C>

Slice this gradient to limit its domain.

source

pub fn domain(&self) -> (C::Scalar, C::Scalar)

Get the limits of this gradient’s domain.

Trait Implementations§

source§

impl<C: Clone + Mix + Clone> Clone for Gradient<C>
where C::Scalar: Clone,

source§

fn clone(&self) -> Gradient<C>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<C: Debug + Mix + Clone> Debug for Gradient<C>
where C::Scalar: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C> RefUnwindSafe for Gradient<C>

§

impl<C> Send for Gradient<C>
where C: Send, <C as Mix>::Scalar: Send,

§

impl<C> Sync for Gradient<C>
where C: Sync, <C as Mix>::Scalar: Sync,

§

impl<C> Unpin for Gradient<C>
where C: Unpin, <C as Mix>::Scalar: Unpin,

§

impl<C> UnwindSafe for Gradient<C>
where C: UnwindSafe, <C as Mix>::Scalar: UnwindSafe,

Blanket Implementations§

source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Component + Float, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<Swp, Dwp, T>,

Convert the source color to the destination color using the specified method
source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> ConvertInto<U> for T
where U: ConvertFrom<T>,

source§

fn convert_into(self) -> U

Convert into T with values clamped to the color defined bounds Read more
source§

fn convert_unclamped_into(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
source§

fn try_convert_into(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.