melonjs
    Preparing search index...

    Class Color

    A color manipulation object.

    Index

    Constructors

    • Creates a new Color instance.

      Parameters

      • r: string | number | Color = 0

        A Color object or the red component [0 .. 255]. Defaults to 0.

      • g: number = 0

        The green component [0 .. 255]. Defaults to 0.

      • b: number = 0

        The blue component [0 .. 255]. Defaults to 0.

      • alpha: number = 1.0

        The alpha value [0.0 .. 1.0]. Defaults to 1.

      Returns Color

    Accessors

    Methods

    • Darkens this color value by a given scale.

      Parameters

      • scale: number

        The scale to darken the color by [0 .. 1].

      Returns Color

      Reference to this object for method chaining.

    • Linearly interpolates between this color and the given one.

      Parameters

      • color: Color

        The color to interpolate with.

      • alpha: number

        The interpolation factor, with alpha = 0 being this color, and alpha = 1 being the given one.

      Returns Color

      Reference to this object for method chaining.

    • Lightens this color value by a given scale

      Parameters

      • scale: number

        The scale to lighten the color by [0 .. 1].

      Returns Color

      Reference to this object for method chaining.

    • Parse a CSS color name and set this color to the corresponding r,g,b values

      Parameters

      • cssColor: string

        The CSS color name

      Returns Color

      Reference to this object for method chaining

    • Parse a Hex color ("#RGB", "#RGBA" or "#RRGGBB", "#RRGGBBAA" format) and set this color to the corresponding r,g,b,a values

      Parameters

      • hexColor: `#${string}`

        The Hex color string to parse

      • Optionalargb: boolean = false

        true if format is #ARGB, or #AARRGGBB (as opposed to #RGBA or #RGGBBAA)

      Returns Color

      Reference to this object for method chaining

    • Parse an RGB or RGBA CSS color string

      Parameters

      • rgbColor: string

        The RGB or RGBA color string to parse

      Returns Color

      Reference to this object for method chaining

    • Generate random r,g,b values for this color object

      Parameters

      • Optionalmin: number = 0

        minimum value for the random range

      • Optionalmax: number = 255

        maxmium value for the random range

      Returns Color

      Reference to this object for method chaining

    • Sets the color to the specified values.

      Parameters

      • r: number = 0

        The red component [0 .. 255].

      • g: number = 0

        The green component [0 .. 255].

      • b: number = 0

        The blue component [0 .. 255].

      • Optionalalpha: number = 1.0

        The alpha value [0.0 .. 1.0]. Defaults to 1.

      Returns Color

      Reference to this object for method chaining.

    • Sets the color to the specified normalized float values.

      Parameters

      • r: number

        The red component [0.0 .. 1.0].

      • g: number

        The green component [0.0 .. 1.0].

      • b: number

        The blue component [0.0 .. 1.0].

      • Optionalalpha: number = 1.0

        The alpha value [0.0 .. 1.0]. Defaults to 1.

      Returns Color

      Reference to this object for method chaining.

    • Sets the color to the specified HSL values.

      Parameters

      • h: number

        The hue [0 .. 1].

      • s: number

        The saturation [0 .. 1].

      • l: number

        The lightness [0 .. 1].

      Returns Color

      Reference to this object for method chaining.

    • Sets the color to the specified HSV values.

      Parameters

      • h: number

        The hue [0 .. 1].

      • s: number

        The saturation [0 .. 1].

      • v: number

        The value [0 .. 1].

      Returns Color

      Reference to this object for method chaining.

    • Get the color in "#RRGGBBAA" format

      Parameters

      • alpha: number = ...

        The alpha value [0.0 .. 1.0] to use in the output string.

      Returns string

      The color in "#RRGGBBAA" format

    • Get the color in "rgb(R,G,B)" format

      Returns `rgb(${number},${number},${number})`

      The color in "rgb(R,G,B)" format

    • Get the color in "rgba(R,G,B,A)" format

      Parameters

      • Optionalalpha: number = ...

        alpha value [0.0 .. 1.0]

      Returns `rgba(${number},${number},${number},${number})`

      The color in "rgba(R,G,B,A)" format

    • Pack this color RGB components into a Uint32 ARGB representation

      Parameters

      • Optionalalpha: number = 1.0

        alpha value [0.0 .. 1.0]

      Returns number

      A Uint32 ARGB representation of this color