Skip to main content

Gradient

Struct Gradient 

Source
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

Source

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),
]);
Source

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 Debug for Gradient

Source§

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

Formats the value using the given formatter. Read more
Source§

impl IntoIterator for Gradient

Source§

type Item = (f32, RgbColor)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<Gradient as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> IntoIterator for &'a Gradient

Source§

type Item = (f32, RgbColor)

The type of the elements being iterated over.
Source§

type IntoIter = Copied<Iter<'a, <&'a Gradient as IntoIterator>::Item>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

Blanket Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,