Color

Class representing a color.

Core Class

Class representing a color.

Constructors

  • Parameters

    • color_or_r: string | number | Color
    • g: number
    • b: number

    Returns Color

Properties

r: number

Red channel value between 0 and 1.

g: number

Green channel value between 0 and 1.

b: number

Blue channel value between 0 and 1.

isColor: boolean

Check the type whether it belongs to Color. This value should not be changed by user.

Accessors

  • get x(): number

    Returns number

  • get y(): number

    Returns number

  • get z(): number

    Returns number

Methods

  • 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 Color

  • Sets color from HSL values.

    Parameters

    • h: number

      hue value between 0.0 and 1.0.

    • s: number

      saturation value between 0.0 and 1.0.

    • l: number

      lightness value between 0.0 and 1.0.

    Returns Color

  • 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.

    Parameters

    • style: string

      color as a CSS-style string. 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 ).

    Returns Color

    that for X11 color names, multiple words such as Dark Orange become the string 'darkorange' (all lowercase).

  • See the Constructor above for full details of what Color_Hex_or_String| value can be. Delegates to .copy| .copy, .setStyle| .setStyle, or setHex depending on input type.

    Parameters

    • value: string | number | Color

      Value to set this color to.

    Returns Color

  • Sets all three color components to the value Float| scalar.

    Parameters

    • scalar: number

      a value between 0.0 and 1.0.

    Returns Color

  • Return a new Color with the same r, g and b values as this clone.

    Returns Color

  • Returns Readonly<
    Pick<
    ReadonlyMarked,
    | "_readonly_mark"
    | "cloneReadonly"
    | "clone"
    | "g"
    | "r"
    | "b"
    | "isColor"
    | "equals"
    | "getHex"
    | "getSerializeData",
    >,
    >

  • Copies the given color into this color, and then converts this color from gamma space to linear space by taking r, g and b to the power of Float| gammaFactor.

    Parameters

    • color: Color

      Color to copy.

    • gammaFactor: number

      (optional).

    Returns Color

  • Copies the given color into this color, and then converts this color from linear space to gamma space by taking r, g and b to the power of 1 / Float| gammaFactor.

    Parameters

    • color: Color

      Color to copy.

    • gammaFactor: number

      (optional).

    Returns Color

  • Converts this color from gamma space to linear space by taking .r| r, .g| g and .b| b to the power of Float| gammaFactor.

    Parameters

    • gammaFactor: number

      (optional).

    Returns Color

  • Converts this color from linear space to gamma space by taking .r| r, .g| g and .b| b to the power of 1 / Float| gammaFactor.

    Parameters

    • gammaFactor: number

      (optional).

    Returns Color

  • Copies the given color into this color, and then converts this color from sRGB space to linear space.

    Parameters

    • color: Color

      Color to copy.

    Returns Color

  • Copies the given color into this color, and then converts this color from linear space to sRGB space.

    Parameters

    • color: Color

      Color to copy.

    Returns Color

  • Converts this color from sRGB space to linear space.

    Returns Color

  • Converts this color from linear space to sRGB space.

    Returns Color

  • Returns the hexadecimal value of this color.

    Returns number

  • Returns the hexadecimal value of this color as a string (for example, 'FFFFFF').

    Returns string

  • Convert this Color's .r| r, .g| g and .b| 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

  • Returns the value of this color as a CSS style string. Example: rgb(255,0,0).

    Returns string

  • Sets this color's RGB values to the sum of the RGB values of color1 and color2.

    Parameters

    Returns Color

  • Adds Number| s to the RGB values of this color.

    Parameters

    • s: number

    Returns Color

  • Subtracts the RGB components of the given color from the RGB components of this color. If this results in a negative component, that component is set to zero.

    Parameters

    Returns Color

  • Multiplies this color's RGB values by the given color's RGB values.

    Parameters

    Returns Color

  • Multiplies this color's RGB values by s.

    Parameters

    • s: number

    Returns Color

  • 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: Color

      color to converge on.

    • alpha: number

      interpolation factor in the closed interval [0, 1].

    Returns Color

  • Compares the RGB values of color with those of this object. Returns true if they are the same, false otherwise.

    Parameters

    Returns boolean

  • Sets this color's components based on an array formatted like [ r, g, b ].

    Parameters

    • array: ArrayLike<number>

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

    • offset: number

      An optional offset into the array.

    Returns Color

  • r,g,b return 3

    Returns number

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

    Parameters

    • array: number[]

      An optional array to store the color to.

    • offset: number

      An optional offset into the array.

    Returns number[]

  • Adds the given h, s, and l to this color's values. Internally, this converts the color's r, g and b values to HSL, adds h,s,l, and then converts the color back to RGB.

    Parameters

    • h: number
    • s: number
    • l: number

    Returns Color

  • 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: Color
    • alpha: number

    Returns this

  • Converts a hexadecimal color number to a string. Color.hex2string(0xffffff); -hex - Number in hex (e.g., 0xffffff) -return The string color (e.g., "#ffffff").

    Parameters

    • hex: number

    Returns string

  • Converts a hexadecimal color number to an [R, G, B] array of normalized floats (numbers from 0.0 to 1.0). Color.hex2rgb(0xffffff); // returns [1, 1, 1] -hex The hexadecimal number to convert -out If supplied, this array will be used rather than returning a new one -return An array representing the [R, G, B] of the color where all values are floats.

    Parameters

    • hex: number
    • out: number[] | Float32Array<ArrayBufferLike>

    Returns number[] | Float32Array<ArrayBufferLike>

  • Converts a color as an [R, G, B] array to a hex number

    Parameters

    • rgb: number[] | Float32Array<ArrayBufferLike>

    Returns number

  • Converts a hexadecimal string to a hexadecimal color number. Color.string2hex("#ffffff"); // returns 0xffffff -string - The string color (e.g., "#ffffff") -return Number in hexadecimal.

    Parameters

    • string: string

    Returns number