Struct glm_color::rgb::Rgb
[−]
[src]
#[repr(C)]pub struct Rgb { /* fields omitted */ }
The linear RGB color space.
Methods
impl Rgb
[src]
fn new(red: f32, green: f32, blue: f32) -> Rgb
Constructs a Rgb
color from given red
, green
and blue
values.
Parameter values are clamped into the interval [0, 1].
Example
use glm_color::*; let blue = Rgb::new(-10., 0., 1000.); assert_eq!(blue, BLUE);
fn red(&self) -> f32
fn green(&self) -> f32
Returns the value of green channel of self.
fn blue(&self) -> f32
Returns the value of blue channel of self.
fn with_red(&self, r: f32) -> Rgb
Returns a new Rgb
value that has given red valud r
and same
green and blue values as self.
Example
use glm_color::*; let clr = RED.with_red(0.75); assert_eq!(clr.red(), 0.75); assert_eq!(clr.green(), 0.); assert_eq!(clr.blue(), 0.)
fn set_red(&mut self, r: f32)
Changes the red value of self to r
.
Example
use glm_color::*; let mut clr = BLUE; clr.set_red(100.); assert_eq!(clr.red(), 1.);
fn with_green(&self, g: f32) -> Rgb
Returns a new Rgb
value that has given green valud g
and same
red and blue values as self.
fn set_green(&mut self, g: f32)
Changes the green value of self to g
.
fn with_blue(&self, b: f32) -> Rgb
Returns a new Rgb
value that has given blue valud b
and same
red and green values as self.
fn set_blue(&mut self, b: f32)
Changes the blue value of self to b
.
fn from_u8(r: u8, g: u8, b: u8) -> Rgb
Creates a Rgb
value by specifying red, green and blue values in
u8
type.
Example
use glm_color::*; let red = Rgb::from_u8(255, 0, 0); assert_eq!(red.red(), 1f32);
fn from_u32(clr: u32) -> Rgb
Constructs a Rgb
value from a 32-bit unsigned integer clr
.
The lower 24 bits of clr
are intepreted as 3 8-bit values,
from low to high, for B, G and R respectively.
Example
use glm_color::{ Rgb, CYAN }; let cyan = Rgb::from_u32(0x00FFFF); assert_eq!(cyan, CYAN); assert_eq!(cyan.red(), 0.);
fn hue(&self) -> f32
Returns the hue of self. It is a value in the interval [0, 2π).
Example
use glm::*; use glm_color::*; assert_eq!(RED.hue(), 0.); assert_eq!(GREEN.hue(), radians(120.)); assert_eq!(BLUE.hue(), radians(240.));
fn saturation(&self) -> f32
Returns the saturation of self. It is a value in the interval [0, 1].
Example
use glm_color::*; // gray colors have 0 saturation. assert_eq!(GRAY.saturation(), 0.); // pure color has full saturation. assert_eq!(RED.saturation(), 1.);
fn brightness(&self) -> f32
fn lunimance(&self) -> f32
Returns self's lunimance.
Luminance is calculated with the same parameters as YCbCr
color space's
from_rgb()
function.
Example
use glm_color::*; assert_eq!(WHITE.lunimance(), 1.); assert_eq!(BLACK.lunimance(), 0.);
fn as_vec3(&self) -> &Vec3
Re-interprets the reference of a Rgb
to a reference of Vec3
.
Example
use glm_color as color; let red = color::RED; assert_eq!(red.as_vec3().x, red.red());
fn rand() -> Rgb
Constructs an Rgb
value by randomly choosing values for each of the
three RGB channels using the thread local RNG.
Note
This function is used to generates a single seed color. Use other member methods to generates colors that have certain relationships with the seed.
Example
use glm_color::*; let seed = Rgb::rand(); // generating 10 colors based on `seed`. let clrs: Vec<Rgb> = (0..10).map(|_| -> Rgb { seed.rand_offset(0.3) }).collect();
fn rand_offset(&self, offset: f32) -> Rgb
Constructs an Rgb
value by adding a random offset
to all RGB channels.
offset
is clamped to the interval [0, 1].
Trait Implementations
impl Copy for Rgb
[src]
impl Clone for Rgb
[src]
fn clone(&self) -> Rgb
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 Rgb
[src]
fn eq(&self, __arg_0: &Rgb) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Rgb) -> bool
This method tests for !=
.
impl Debug for Rgb
[src]
impl ColorSpace for Rgb
[src]
fn from_rgb(rgb: Rgb) -> Rgb
Constructs from color value rgb
in RGB color space.
fn to_rgb(&self) -> Rgb
Converts self to a color value in RGB color space.
impl Eq for Rgb
[src]
impl Rand for Rgb
[src]
fn rand<R: Rng>(rng: &mut R) -> Rgb
Generates a random instance of this type using the specified source of randomness. Read more
impl ApproxEq for Rgb
[src]
type BaseType = f32
fn is_close_to(&self, other: &Rgb, 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
impl Add<Rgb> for Rgb
[src]
type Output = Rgb
The resulting type after applying the +
operator
fn add(self, rhs: Rgb) -> Rgb
The method for the +
operator
impl Sub<Rgb> for Rgb
[src]
type Output = Rgb
The resulting type after applying the -
operator
fn sub(self, rhs: Rgb) -> Rgb
The method for the -
operator
impl Mul<f32> for Rgb
[src]
type Output = Rgb
The resulting type after applying the *
operator
fn mul(self, rhs: f32) -> Rgb
The method for the *
operator