Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Color

Class representing a color.

A Color can be initialised in any of the following ways: See the ngx3js docs page for details.

Examples

misc / exporter / collada | webgl / camera / logarithmicdepthbuffer | webgl / clipping / advanced | webgl / framebuffer / texture | webgl / geometry / colors

Code Example

// empty constructor - will default white
const color1 = new THREE.Color();
// Hexadecimal color (recommended)
const color2 = new THREE.Color( 0xff0000 );
// RGB string
const color3 = new THREE.Color("rgb(255, 0, 0)");
const color4 = new THREE.Color("rgb(100%, 0%, 0%)");
// X11 color name - all 140 color names are supported.
// Note the lack of CamelCase in the name
const color5 = new THREE.Color( 'skyblue' );
// HSL string
const color6 = new THREE.Color("hsl(0, 100%, 50%)");
// Separate RGB values between 0 and 1
const color7 = new THREE.Color( 1, 0, 0 );
example

const color = new THREE.Color( 0xff0000 );

Hierarchy

  • Color

Index

Constructors

constructor

  • Note that standard method of specifying color in three.js is with a hexadecimal triplet, and that method is used throughout the rest of the documentation. When all arguments are defined then r is the red component, g is the green component and b is the blue component of the color. When only r is defined:

    It can be a hexadecimal triplet representing the color (recommended). It can be an another Color instance. It can be a CSS-style string. For example:

    'rgb(250, 0,0)', 'rgb(100%,0%,0%)', 'hsl(0, 100%, 50%)', '#ff0000', '#f00', 'red'

    Parameters

    • Optional r: I3JS.ColorRepresentation

      If arguments g and b are defined, the red component of the color. If they are not defined, it can be a hexadecimal triplet (recommended), a CSS-style string, or another Color instance.

    • Optional g: number

      If it is defined, the green component of the color.

    • Optional b: number

      If it is defined, the blue component of the color.

    Returns I3JS.Color

Properties

NAMES

NAMES: Record<string, number>

List of X11 color names.

b

b: number

Blue channel value between 0 and 1. Default is 1.

g

g: number

Green channel value between 0 and 1. Default is 1.

Readonly isColor

isColor: true

r

r: number

Red channel value between 0 and 1. Default is 1.

Methods

add

addColors

addScalar

clone

convertGammaToLinear

  • convertGammaToLinear(gammaFactor?: number): I3JS.Color

convertLinearToGamma

  • convertLinearToGamma(gammaFactor?: number): I3JS.Color

convertLinearToSRGB

convertSRGBToLinear

copy

copyGammaToLinear

copyLinearToGamma

copyLinearToSRGB

copySRGBToLinear

equals

fromArray

  • fromArray(array: ArrayLike<number> | number[], offset?: number): I3JS.Color
  • Sets this color's components based on an array formatted like [ r, g, b ].

    Parameters

    • array: ArrayLike<number> | number[]

      Array of floats in the form [ r, g, b ].

    • Optional offset: number

      An optional offset into the array.

    Returns I3JS.Color

fromBufferAttribute

getHSL

  • Convert this Color's .r, .g and .b values to HSL format and returns an object of the form: { h: 0, s: 0, l: 0 }

    Parameters

    • target: HSL

      The result will be copied into this Object. Adds h, s and l keys to the object (if not already present).

    Returns HSL

getHex

  • getHex(): number

getHexString

  • getHexString(): string

getStyle

  • getStyle(): string

lerp

  • Linearly interpolates this color's RGB values toward the RGB values of the passed argument. The alpha argument can be thought of as the ratio between the two colors, where 0.0 is this color and 1.0 is the first argument.

    Parameters

    • color: I3JS.Color

      color to converge on.

    • alpha: number

    Returns I3JS.Color

lerpColors

lerpHSL

  • Linearly interpolates this color's HSL values toward the HSL values of the passed argument. It differs from the classic .lerp by not interpolating straight from one color to the other, but instead going through all the hues in between those two colors. The alpha argument can be thought of as the ratio between the two colors, where 0.0 is this color and 1.0 is the first argument.

    Parameters

    • color: I3JS.Color

      color to converge on.

    • alpha: number

    Returns I3JS.Color

multiply

multiplyScalar

offsetHSL

  • offsetHSL(h: number, s: number, l: number): I3JS.Color

set

setColorName

  • Sets this color from a color name. Faster than .setStyle method if you don't need the other CSS-style formats. For convenience, the list of names is exposed in Color.NAMES as a hash: Color.NAMES.aliceblue // returns 0xF0F8FF

    Parameters

    Returns I3JS.Color

setHSL

  • setHSL(h: number, s: number, l: number): I3JS.Color

setHex

setRGB

  • setRGB(r: number, g: number, b: number): I3JS.Color
  • Sets this color from RGB values.

    Parameters

    • r: number

      Red channel value between 0.0 and 1.0.

    • g: number

      Green channel value between 0.0 and 1.0.

    • b: number

      Blue channel value between 0.0 and 1.0.

    Returns I3JS.Color

setScalar

setStyle

  • Sets this color from a CSS-style string. For example, "rgb(250, 0,0)", "rgb(100%, 0%, 0%)", "hsl(0, 100%, 50%)", "#ff0000", "#f00", or "red" ( or any X11 color name - all 140 color names are supported ). Translucent colors such as "rgba(255, 0, 0, 0.5)" and "hsla(0, 100%, 50%, 0.5)" are also accepted, but the alpha-channel coordinate will be discarded. Note that for X11 color names, multiple words such as Dark Orange become the string 'darkorange'.

    Parameters

    • style: string

      color as a CSS-style string.

    Returns I3JS.Color

sub

toArray

  • toArray(array?: ArrayLike<number> | number[], offset?: number): number[]
  • Returns an array [red, green, blue], or copies red, green and blue into the provided array.

    Parameters

    • Optional array: ArrayLike<number> | number[]

      An optional array to store the color to.

    • Optional offset: number

      An optional offset into the array.

    Returns number[]

    Returns an array of the form [ r, g, b ].

Generated using TypeDoc