ProtoTwin API
    Preparing search index...

    Class Color

    Immutable RGB color.

    Index

    Constructors

    • Constructor.

      Parameters

      • r: number

        The red channel, in the range [0, 1].

      • g: number

        The green channel, in the range [0, 1].

      • b: number

        The blue channel, in the range [0, 1].

      Returns Color

    Properties

    b: number

    The blue channel, in the range [0, 1].

    g: number

    The green channel, in the range [0, 1].

    r: number

    The red channel, in the range [0, 1].

    Accessors

    Methods

    • Calculates the closest hexadecimal code.

      Returns string

      Hexadecimal code as a string in the HTML format.

      const code: string = Color.red.toHex(); // Returns "#FF0000"
      
    • Determines whether two colors are exactly equal.

      Parameters

      • lhs: Color

        The first color.

      • rhs: Color

        The second color.

      Returns boolean

      True if the colors are equal, false otherwise.

    • Creates a color from a hexadecimal code.

      Parameters

      • value: string

        The hexadecimal code.

      Returns Color

      The corresponding color.

      const color = Color.fromHex("#FF0000");
      
    • Decodes a 32-bit integer to a color.

      Parameters

      • value: number

        The encoded color.

      Returns Color

      The decoded color.

    • Creates a random color.

      Returns Color

      The random color.

    • Encodes a color to a 32-bit integer.

      Parameters

      • r: number

        The red channel [0, 1].

      • g: number

        The green channel [0, 1].

      • b: number

        The blue channel [0, 1].

      • a: number

        The alpha channel [0, 1].

      Returns number

      The encoded color.