Skip to main content

Color

Struct Color 

Source
pub struct Color {
    pub r: f64,
    pub g: f64,
    pub b: f64,
}
Expand description

Port of three.js/src/math/Color.js’s Color class: an RGB color, stored in the working color space (linear-sRGB).

Fields§

§r: f64

The red channel.

§g: f64

The green channel.

§b: f64

The blue channel.

Implementations§

Source§

impl Color

Source

pub const fn new(r: f64, g: f64, b: f64) -> Self

new Color( r, g, b ) / setRGB( r, g, b ) with the working colour space, i.e. the components are stored as given.

Source

pub fn from_hex(hex: u32) -> Self

new Color( hex ) — setHex( hex, SRGBColorSpace ).

Source

pub fn set_scalar(&mut self, scalar: f64) -> &mut Self

Color.setScalar().

Source

pub fn set_hex(&mut self, hex: u32, color_space: ColorSpace) -> &mut Self

Color.setHex().

Source

pub fn set_rgb( &mut self, r: f64, g: f64, b: f64, color_space: ColorSpace, ) -> &mut Self

Color.setRGB().

Source

pub fn set_hsl( &mut self, h: f64, s: f64, l: f64, color_space: ColorSpace, ) -> &mut Self

Color.setHSL(). h, s and l are in 0..1.

Source

pub fn copy(&mut self, color: &Self) -> &mut Self

Color.copy().

Source

pub fn copy_srgb_to_linear(&mut self, color: &Self) -> &mut Self

Color.copySRGBToLinear().

Source

pub fn copy_linear_to_srgb(&mut self, color: &Self) -> &mut Self

Color.copyLinearToSRGB().

Source

pub fn convert_srgb_to_linear(&mut self) -> &mut Self

Color.convertSRGBToLinear().

Source

pub fn convert_linear_to_srgb(&mut self) -> &mut Self

Color.convertLinearToSRGB().

Source

pub fn get_hex(&self, color_space: ColorSpace) -> u32

Color.getHex().

Source

pub fn get_hex_string(&self, color_space: ColorSpace) -> String

Color.getHexString().

Source

pub fn get_hsl(&self, color_space: ColorSpace) -> Hsl

Color.getHSL().

Source

pub fn get_rgb(&self, color_space: ColorSpace) -> Self

Color.getRGB().

Source

pub fn get_style(&self) -> String

Color.getStyle(), SRGBColorSpace.

Source

pub fn offset_hsl(&mut self, h: f64, s: f64, l: f64) -> &mut Self

Color.offsetHSL().

Source

pub fn add(&mut self, color: &Self) -> &mut Self

Color.add().

Source

pub fn add_colors(&mut self, color1: &Self, color2: &Self) -> &mut Self

Color.addColors().

Source

pub fn add_scalar(&mut self, s: f64) -> &mut Self

Color.addScalar().

Source

pub fn sub(&mut self, color: &Self) -> &mut Self

Color.sub() — clamps at zero.

Source

pub fn multiply(&mut self, color: &Self) -> &mut Self

Color.multiply().

Source

pub fn multiply_scalar(&mut self, s: f64) -> &mut Self

Color.multiplyScalar().

Source

pub fn lerp(&mut self, color: &Self, alpha: f64) -> &mut Self

Color.lerp().

Source

pub fn lerp_colors( &mut self, color1: &Self, color2: &Self, alpha: f64, ) -> &mut Self

Color.lerpColors().

Source

pub fn lerp_hsl(&mut self, color: &Self, alpha: f64) -> &mut Self

Color.lerpHSL().

Source

pub fn set_from_vector3(&mut self, v: &Vector3) -> &mut Self

Color.setFromVector3().

Source

pub fn apply_matrix3(&mut self, m: &Matrix3) -> &mut Self

Color.applyMatrix3().

Source

pub fn equals(&self, c: &Self) -> bool

Color.equals().

Source

pub fn from_array(&mut self, array: &[f64], offset: usize) -> &mut Self

Color.fromArray().

Source

pub fn to_array(&self) -> [f64; 3]

Color.toArray().

Trait Implementations§

Source§

impl Clone for Color

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Color

Source§

impl Debug for Color

Source§

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

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

impl Default for Color

Source§

fn default() -> Self

new Color() — three.js’ constructor initialises to white before applying its arguments, so a no-argument Color is white.

Source§

impl From<Color> for NodeRef

Source§

fn from(c: Color) -> Self

Converts to this type from the input type.
Source§

impl From<Color> for RangeValue

Source§

fn from(v: Color) -> Self

Converts to this type from the input type.
Source§

impl From<Color> for Background

Source§

fn from(color: Color) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Color

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Color

Auto Trait Implementations§

§

impl Freeze for Color

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin for Color

§

impl UnsafeUnpin for Color

§

impl UnwindSafe for Color

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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