Struct glm_color::hsv::Hsv
[−]
[src]
pub struct Hsv { /* fields omitted */ }
The HSV color space.
See
Methods
impl Hsv
[src]
fn new(hue: f32, saturation: f32, brightness: f32) -> Hsv
Constructs an Hsv
value from given hue
, saturation
and
brightness
values.
Parameter hue
is clampped to the interval [0, 2π), and
saturation
and brightness
are clampped to interval [0, 1].
Example
use glm_color::*; let red = Hsv::new(7., 2., 1.); assert_eq!(red.hue(), 0.); assert_eq!(red.saturation(), 1.);
fn rand() -> Hsv
Constructs an Hsv
value by randomly choosing values for each of the
three HSV channels using the thread local RNG.
Note
As the Rgb::rand()
function, this function is not good for
generating the whole color palette.
fn from_hue(h: f32) -> Hsv
Constructs an Hsv
from hue value degree
, which is the angle on the
color wheel.
Both saturation and brightness of the returned value are set to 1.0
.
Example
use glm::*; use glm_color::*; let y = Hsv::from_hue(radians(60.)); assert_eq!(y.hue(), glm::radians(60.)); assert_eq!(y.saturation(), 1.); assert_eq!(y.brightness(), 1.);
fn hue(&self) -> f32
Returns the hue of self.
fn saturation(&self) -> f32
Returns the saturation of self.
fn brightness(&self) -> f32
Returns the brightness of self.
fn set_hue(&mut self, h: f32)
Changes self's hue value to h
.
The parameter h
is clampped to the range [0, 2π).
fn with_hue(&self, h: f32) -> Hsv
Returns a new Hsv
value with given hue value h
, and saturation and
brightness values from self.
fn set_saturation(&mut self, s: f32)
Changes self's saturation value to s
.
The parameter 's' is clampped to the rnage [0, 1];
fn with_saturation(&self, s: f32) -> Hsv
Returns a new Hsv
value with given saturation value s
, and hue and
brightness values from self.
fn set_brightness(&mut self, b: f32)
Changes self's brightness value to b
.
The parameter 'b' will be clampped to the rnage [0, 1];
fn with_brightness(&self, b: f32) -> Hsv
Returns a new Hsv
value with given brightness value b
, and hue and
saturation values from self.
fn as_vec3(&self) -> &Vec3
Re-interpret the reference of Hsv
to Vec3
.
fn complement(&self) -> Hsv
Returns the complementary color of self.
Example
use glm::*; use glm::ext::pi; use glm_color::*; let red = Hsv::from_hue(0.); let green = Hsv::from_hue(pi()); assert_eq!(red.complement(), green);
fn split_complement(&self) -> (Self, Self)
Returns a pair of colors that are splited from the complementary color of self,
The 2 colors have same distances to the complementary color on the
color wheel. In our implementation, this distance is fixed to 30
degrees.
fn double_complement(&self) -> ((Self, Self), (Self, Self))
Returns 2 pairs of complementary colors. The first colors of both pairs
are the result of split_complement
of self.
fn triad(&self) -> (Hsv, Hsv)
Returns other 2 colors of triad colors that includes self.
Example
use glm::*; use glm_color::*; let red = Hsv::from_rgb(RED); let (green, blue) = red.triad(); assert!(is_close_to(&green.hue(), &radians(120.), 0.000001)); assert!(is_close_to(&blue.hue(), &radians(240.), 0.000001));
fn analogs(&self, n: usize, span: f32) -> Vec<Hsv>
Returns n
colors that are analogous to the receiver.
fn color_wheel(n: usize) -> Vec<Hsv>
Returns n
colors distributed on the color wheel evenly.
The returned colors have full saturation and lightness. Red is the first color in the vector.
If n
is 0
, an empty vector is returned.
Example
use glm_color::*; let cs0 = Hsv::color_wheel(0); assert_eq!(cs0.len(), 0); let cs1 = Hsv::color_wheel(1); assert_eq!(cs1[0], Hsv::from_hue(0.)); let csn = Hsv::color_wheel(3); assert_eq!(csn.len(), 3);
fn tint(&self, amt: f32) -> Hsv
Produces a color by adding white to the receiver.
For Hsv
color model, adding white means increasing the lightness.
Parameter amt
specifies absolute lightness to be added.
Example
use glm_color::*; let red = Hsv::new(1., 0.5, 0.2); assert_eq!(red.tint(1.), Hsv::new(1., 0.5, 1.));
fn tints(&self, n: usize) -> Vec<Hsv>
Produces a vector of n
colors whose brightness increase monotonically
and evenly.
If n
is 0
, returns an empty vector.
Other wise, the receiver is the first element of the vector and a color with full brightness is the last.
Example
use glm_color::*; let red: Hsv = from_rgb(RED); let clrs = red.tints(3);
fn shade(&self, amt: f32) -> Hsv
Produces a color by adding black to the receiver.
fn shades(&self, n: usize) -> Vec<Hsv>
Producesn
colors whose brightness decrease monotonically and evenly.
fn tone(&self, amt: f32) -> Hsv
Produces a color by adding gray to the receiver.
fn tones(&self, n: usize) -> Vec<Hsv>
Produces n
colors whose saturation decrease monotonically and evenly.
Trait Implementations
impl Copy for Hsv
[src]
impl Clone for Hsv
[src]
fn clone(&self) -> Hsv
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl PartialEq for Hsv
[src]
fn eq(&self, __arg_0: &Hsv) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Hsv) -> bool
This method tests for !=
.
impl Debug for Hsv
[src]
impl Rand for Hsv
[src]
fn rand<R: Rng>(rng: &mut R) -> Hsv
Generates a random instance of this type using the specified source of randomness. Read more
impl Eq for Hsv
[src]
impl ApproxEq for Hsv
[src]
type BaseType = f32
fn is_close_to(&self, other: &Hsv, max_diff: f32) -> bool
Returns true
if the difference between x
and y
is less than max_diff
. Read more
fn is_approx_eq(&self, rhs: &Self) -> bool
Returns true
if the difference between x
and y
is less than machine epsilon. Read more