Class Color

A class representing a color.

Constructors

  • Creates a new instance of the Color class.

    Parameters

    • rOrHex: string | number = 255

      The red channel value or a hexadecimal color string.

    • g: number = 255

      The green channel value.

    • b: number = 255

      The blue channel value.

    • a: number = 1

      The alpha channel value.

    Returns Color

Properties

a: number = 1

The alpha channel value.

b: number = 255

The blue channel value.

g: number = 255

The green channel value.

r: number = 255

The red channel value.

Methods

  • Adds the values of another Color object to this Color object and returns a new Color object.

    Parameters

    • c: Color

      The Color object to be added.

    Returns Color

    A new Color object with the summed values.

  • Adjusts the brightness of the color by the specified amount.

    Parameters

    • amount: number

      The amount by which to adjust the brightness. Positive values make the color brighter, while negative values make it darker.

    Returns Color

    A new Color object with the adjusted brightness.

  • Converts the color to a 32-bit integer representation in RGBA format.

    Returns number

    The color as a 32-bit integer.

  • Sets the color values based on the given hexadecimal color code.

    Parameters

    • hex: string

      The hexadecimal color code (e.g., "#FF0000").

    Returns Color

    The Color instance with updated color values.

  • Returns the color as a hexadecimal string representation.

    Parameters

    • includeAlpha: boolean = true

      Whether to include the alpha channel in the string representation. Default is true.

    Returns string

    The color as a hexadecimal string.