Trait bevy_color::prelude::Luminance
source · pub trait Luminance: Sized {
// Required methods
fn luminance(&self) -> f32;
fn with_luminance(&self, value: f32) -> Self;
fn darker(&self, amount: f32) -> Self;
fn lighter(&self, amount: f32) -> Self;
}
Expand description
Methods for changing the luminance of a color. Note that these methods are not guaranteed to produce consistent results across color spaces, but will be within a given space.
Required Methods§
sourcefn with_luminance(&self, value: f32) -> Self
fn with_luminance(&self, value: f32) -> Self
Return a new version of this color with the given luminance. The resulting color will be clamped to the valid range for the color space; for some color spaces, clamping may cause the hue or chroma to change.
sourcefn darker(&self, amount: f32) -> Self
fn darker(&self, amount: f32) -> Self
Return a darker version of this color. The amount
should be between 0.0 and 1.0.
The amount represents an absolute decrease in luminance, and is distributive:
color.darker(a).darker(b) == color.darker(a + b)
. Colors are clamped to black
if the amount would cause them to go below black.
For a relative decrease in luminance, you can simply mix()
with black.
sourcefn lighter(&self, amount: f32) -> Self
fn lighter(&self, amount: f32) -> Self
Return a lighter version of this color. The amount
should be between 0.0 and 1.0.
The amount represents an absolute increase in luminance, and is distributive:
color.lighter(a).lighter(b) == color.lighter(a + b)
. Colors are clamped to white
if the amount would cause them to go above white.
For a relative increase in luminance, you can simply mix()
with white.