pub struct Gradient { /* private fields */ }Expand description
A color gradient defined by interpolation between color stops.
Gradients map normalized intensity values (0.0 to 1.0) to colors through linear interpolation between user-defined color stops. This is used to create the Look-Up Table (LUT) texture for intensity-to-color mapping in the renderer.
§Example
use phosphor::gradient::{Gradient, RgbColor};
// Create classic green oscilloscope gradient
let gradient = Gradient::new(vec![
(0.0, RgbColor::new(0.0, 0.0, 0.0)), // Black background
(0.3, RgbColor::new(0.0, 0.2, 0.0)), // Dark green
(0.7, RgbColor::new(0.0, 0.8, 0.0)), // Bright green
(1.0, RgbColor::new(0.8, 1.0, 0.8)), // Saturated green
]);Implementations§
Source§impl Gradient
impl Gradient
Sourcepub fn new(stops: impl IntoIterator<Item = (f32, impl Into<RgbColor>)>) -> Self
pub fn new(stops: impl IntoIterator<Item = (f32, impl Into<RgbColor>)>) -> Self
Creates a new gradient from color stops.
The stops define (position, color) pairs. The gradient will interpolate linearly between these stops. Stops are automatically sorted by position.
§Arguments
stops- Iterator of (position, color) pairs
§Example
use phosphor::gradient::{Gradient, RgbColor};
let gradient = Gradient::new([
(0.0, RgbColor::new(0.0, 0.0, 0.0)), // Arrays convert to RgbColor
(0.5, RgbColor::new(0.5, 0.0, 0.5)),
(1.0, RgbColor::WHITE),
]);Sourcepub fn linear_eval(&self, n: usize) -> Vec<RgbColor>
pub fn linear_eval(&self, n: usize) -> Vec<RgbColor>
Samples the gradient at evenly spaced points.
Returns a vector of colors sampled at n linearly spaced points between 0.0 and 1.0.
This is primarily used internally to generate LUT textures for the GPU.
§Arguments
n- Number of samples to generate (must be ≥ 2)
§Panics
Panics if n ≤ 1 or if the gradient has no stops.
§Example
use phosphor::gradient::{Gradient, RgbColor};
let gradient = Gradient::new([
(0.0, RgbColor::BLACK),
(1.0, RgbColor::WHITE),
]);
let samples = gradient.linear_eval(5); // [black, dark_gray, gray, light_gray, white]
assert_eq!(samples.len(), 5);Trait Implementations§
Source§impl IntoIterator for Gradient
impl IntoIterator for Gradient
Source§impl<'a> IntoIterator for &'a Gradient
impl<'a> IntoIterator for &'a Gradient
Auto Trait Implementations§
impl Freeze for Gradient
impl RefUnwindSafe for Gradient
impl Send for Gradient
impl Sync for Gradient
impl Unpin for Gradient
impl UnsafeUnpin for Gradient
impl UnwindSafe for Gradient
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