starry-math
    Preparing search index...

    Class Color

    Color Class for color manipulation and conversion

    Index

    Constructors

    • Initializes a Color instance with optional color value

      Parameters

      • Optionalcolor: number | ColorString

        Optional color value - String format: Supports CSS color formats (e.g., rgba(255,0,0,0.5), #FF0000, transparent) - Number format: Supports hexadecimal color value (e.g., 0xFF0000 for red) - No parameter: Defaults to opaque black (r=0, g=0, b=0, a=1)

      Returns Color

    Properties

    a: number = 1

    Alpha/opacity component (0-1)

    b: number = 0

    Blue component (0-1)

    g: number = 0

    Green component (0-1)

    r: number = 0

    Red component (0-1)

    Methods

    • Creates a new Color instance with the same RGBA values

      Returns Color

      New Color instance with identical values

    • Copies RGBA values from another color

      Parameters

      • source: Color

        Color instance to copy values from

      Returns this

      Current Color instance for chaining

    • Checks if this color equals another color

      Parameters

      • color: Color

        Color instance to compare with

      Returns boolean

      True if colors are identical, false otherwise

    • Gets the color as a hexadecimal number

      Returns number

      Hexadecimal representation of the color

    • Gets the color as a hexadecimal string without the hash prefix

      Returns string

      Hexadecimal string representation of the color (e.g., "FF0000" for red)

    • Gets the color as an RGBA CSS string

      Returns string

      CSS rgba() string representation of the color

    • Sets the RGBA values of the color

      Parameters

      • r: number

        Red component (range: 0-1)

      • g: number

        Green component (range: 0-1)

      • b: number

        Blue component (range: 0-1)

      • a: number

        Alpha/opacity component (range: 0-1)

      Returns this

      Current Color instance for chaining

    • Sets color from a hexadecimal number

      Parameters

      • hex: number

        Hexadecimal color value (e.g., 0xFF0000 for red)

      Returns this

      Current Color instance for chaining

    • Sets color from a CSS color string

      Parameters

      • color: ColorString

        CSS color string in formats like 'red' 'yellow' and so on, 'rgb()', 'rgba()', '#RRGGBB', '#RGB', or 'transparent'

      Returns this

      Current Color instance for chaining

    • Converts the color to an array of RGBA values

      Returns [number, number, number, number]

      Array containing [r, g, b, a] components