[][src]Struct launchy::Color

pub struct Color {
    pub r: f32,
    pub g: f32,
    pub b: f32,
}

A simple float-based color struct. Each component should lie in 0..=1, but it can also be outside that range. If outside, it will be clipped for some operations

Fields

r: f32g: f32b: f32

Implementations

impl Color[src]

pub const BLACK: Color[src]

pub const WHITE: Color[src]

pub const RED: Color[src]

pub const GREEN: Color[src]

pub const BLUE: Color[src]

pub const CYAN: Color[src]

pub const MAGENTA: Color[src]

pub const YELLOW: Color[src]

pub fn new(r: f32, g: f32, b: f32) -> Self[src]

Create a new color from the given red, green, and blue components

Examples:

let lime = Color::new(0.75, 1.0, 0.0);
let beige = Color::new(0.96, 0.96, 0.86);

pub fn from_hue(hue: f32) -> Self[src]

Creates a color from a hue, starting at 0.0 (red) and ending at 1.0 (red). You can pass in any number though, because the cycle repeats (think the x in sin(x))

let red = Color::from_hue(0.0);
let orange = Color::from_hue(0.1);
let greenish_yellow = Color::from_hue(0.2);
let green = Color::from_hue(0.3);
let cyan = Color::from_hue(0.4);
let light_blue = Color::from_hue(0.5);
let blue = Color::from_hue(0.6);
let purple = Color::from_hue(0.7);
let light_pink = Color::from_hue(0.8);
let strong_pink = Color::from_hue(0.9);

pub fn red_green_color(hue: f32) -> Self[src]

Util function that smoothly interpolates between the following 'keyframes':

  • 0.00 => green
  • 0.25 => yellow
  • 0.50 => red
  • 0.75 => yellow
  • 1.00 => green

and then the cycle continues.

This function is useful to create a smooth cycling gradient of colors on non-RGB devices such as the Launchpad S.

pub fn quantize(self, range: u16) -> (u8, u8, u8)[src]

Return a tuple of color components scaled from 0..=1 to 0..range by doing (component * range).floor().min(range - 1).max(0) on every component.

This function is used by the Canvas implementation of the Launchpads to downscale the high-precision Colors to their respective color width. For example the Launchpad S only supports four levels of brightness for its red and green component, respectively. Therefore, the Launchpad S calls .quantize(4) on a given Color to derive how that color should be represented on the Launchpad S LEDs.

pub fn mix(self, other: Color, proportion_of_other: f32) -> Color[src]

Mix two colors together. The proportion of the second color is specified by proportion_of_other.

Examples:

let very_dark_red = Color::RED.mix(Color::BLACK, 0.9);
let orange = Color::RED.mix(Color::YELLOW, 0.5);
let dark_brown = Color::RED.mix(Color::YELLOW, 0.5).mix(Color::BLACK, 0.7);

Trait Implementations

impl Add<Color> for Color[src]

type Output = Self

The resulting type after applying the + operator.

impl Add<f32> for Color[src]

type Output = Self

The resulting type after applying the + operator.

impl Clone for Color[src]

impl Copy for Color[src]

impl Debug for Color[src]

impl Default for Color[src]

impl Div<f32> for Color[src]

type Output = Self

The resulting type after applying the / operator.

impl From<Color> for Rgb888[src]

impl From<Rgb888> for Color[src]

impl Mul<f32> for Color[src]

type Output = Self

The resulting type after applying the * operator.

impl Neg for Color[src]

type Output = Self

The resulting type after applying the - operator.

impl PartialEq<Color> for Color[src]

impl StructuralPartialEq for Color[src]

impl Sub<Color> for Color[src]

type Output = Self

The resulting type after applying the - operator.

impl Sub<f32> for Color[src]

type Output = Self

The resulting type after applying the - operator.

impl Sum<Color> for Color[src]

Auto Trait Implementations

impl RefUnwindSafe for Color

impl Send for Color

impl Sync for Color

impl Unpin for Color

impl UnwindSafe for Color

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.