pub struct Gradient {
pub stops: Vec<(f32, Hsva)>,
pub interpolation_method: InterpolationMethod,
}
Expand description
A color gradient, that will be interpolated between a number of fixed points, a.k.a. stops.
Fields§
§stops: Vec<(f32, Hsva)>
§interpolation_method: InterpolationMethod
Implementations§
Source§impl Gradient
impl Gradient
Sourcepub fn new(
interpolation_method: InterpolationMethod,
stops: impl IntoIterator<Item = (f32, impl Into<Hsva>)>,
) -> Self
pub fn new( interpolation_method: InterpolationMethod, stops: impl IntoIterator<Item = (f32, impl Into<Hsva>)>, ) -> Self
Create a new gradient from an iterator over key colors.
Sourcepub fn interpolator(&self) -> ColorInterpolator
pub fn interpolator(&self) -> ColorInterpolator
Create a ColorInterpolator to evaluate the gradient at any point.
Sourcepub fn interpolator_opaque(&self) -> ColorInterpolator
pub fn interpolator_opaque(&self) -> ColorInterpolator
Create a ColorInterpolator that discards the alpha component of the color gradient and always produces an opaque color.
Sourcepub fn argsort(&self) -> Vec<usize>
pub fn argsort(&self) -> Vec<usize>
Produce a list of the indices of the gradient’s stops that would place them in order.
Use this to prepare for the upcoming reordering of the stops by sort().
Sourcepub fn linear_eval(&self, n: usize, opaque: bool) -> Vec<Color32>
pub fn linear_eval(&self, n: usize, opaque: bool) -> Vec<Color32>
Return a vector of the gradient’s color sampled on linearly spaced points between 0 and 1.
The first and last samples correspond to the gradient’s value at 0.0 and 1.0, respectively.
This is useful for generating a texture.
§Panics
Will panic if the provided size n
is smaller or equal to 1, or if the gradient is empty.