On this page

Class Color

Color representation used by WebGL. Defined in sRGB color space and pre-blended with alpha.

Index

Constructors

Properties

Accessors

Methods

Constructors

  • Parameters

    • r: number

      Red component premultiplied by alpha 0..1

    • g: number

      Green component premultiplied by alpha 0..1

    • b: number

      Blue component premultiplied by alpha 0..1

    • Optionalalpha: number

      Alpha component 0..1

    • Optionalpremultiplied: boolean

      Whether the r, g and b values have already been multiplied by alpha. If true nothing happens if false then they will be multiplied automatically.

    Returns Color

Properties

a: number
b: number
g: number
r: number
black: Color
red: Color
transparent: Color
white: Color

Accessors

  • get hcl(): HCLColor

    Used in color interpolation.

    Returns HCLColor

    Gien color, with reversed alpha blending, in HCL color space.

  • get lab(): LABColor

    Used in color interpolation.

    Returns LABColor

    Gien color, with reversed alpha blending, in LAB color space.

  • get rgb(): RGBColor

    Used in color interpolation and by 'to-rgba' expression.

    Returns RGBColor

    Gien color, with reversed alpha blending, in sRGB color space.

Methods

  • Used by 'to-string' expression.

    Returns string

    Serialized color in format rgba(r,g,b,a) where r,g,b are numbers within 0..255 and alpha is number within 1..0

    var purple = new Color.parse('purple');
    purple.toString; // = "rgba(128,0,128,1)"
    var translucentGreen = new Color.parse('rgba(26, 207, 26, .73)');
    translucentGreen.toString(); // = "rgba(26,207,26,0.73)"
    
  • Parses CSS color strings and converts colors to sRGB color space if needed. Officially supported color formats:

    • keyword, e.g. 'aquamarine' or 'steelblue'
    • hex (with 3, 4, 6 or 8 digits), e.g. '#f0f' or '#e9bebea9'
    • rgb and rgba, e.g. 'rgb(0,240,120)' or 'rgba(0%,94%,47%,0.1)' or 'rgb(0 240 120 / .3)'
    • hsl and hsla, e.g. 'hsl(0,0%,83%)' or 'hsla(0,0%,83%,.5)' or 'hsl(0 0% 83% / 20%)'

    Parameters

    • input: string | Color | null | undefined

      CSS color string to parse.

    Returns Color | undefined

    A Color instance, or undefined if the input is not a valid color string.

Was this helpful?
SDK JS
Reference
Color