Fudge Core
    Preparing search index...

    Class Color

    Defines a color as values in the range of 0 to 1 for the four channels red, green, blue and alpha (for opacity)

    Hierarchy (View Summary)

    Implements

    Index

    Constructors

    Properties

    a: number
    b: number
    g: number
    r: number
    crc2: CanvasRenderingContext2D = ...

    Accessors

    • get type(): string

      Retrieves the type of this mutable subclass as the name of the runtime class

      Returns string

      The type of the mutable

    Methods

    • Calls a defined callback function on each channel of the color and assigns the result to the channel. Similar to Color.map but mutates this color instead of creating a new one.

      Parameters

      • _function: (
            _value: number,
            _index: number,
            _channel: "a" | "b" | "g" | "r",
            _color: Color,
        ) => number

      Returns Color

      A reference to this color.

    • Returns true if this vector is equal to the given vector within the given tolerance.

      Parameters

      • _compare: Color
      • _tolerance: number = Number.EPSILON

      Returns boolean

    • Set the values of this object from the given array starting at the given offset.

      Parameters

      • _array: ArrayLike<number>

        The array to read the values from.

      • _offset: number = 0

        (optional) The offset to start reading from.

      Returns this

      A reference to this instance.

    • Collect applicable attributes of the instance and copies of their values in a Mutator-object. By default, a mutator cannot be extended, since extensions are not available in the object the mutator belongs to. A mutator may be reduced by the descendants of Mutable to contain only the properties needed.

      Parameters

      • _extendable: boolean = false

      Returns Mutator

    • Calls a defined callback function on each channel of the color, and returns a new color that contains the results. Similar to Array.map.

      Parameters

      • _function: (
            _value: number,
            _index: number,
            _channel: "a" | "b" | "g" | "r",
            _color: Color,
        ) => number
      • _out: Color = ...

        Optional color to store the result in.

      Returns Color

    • Updates the attribute values of the instance according to the state of the mutator. The mutation may be restricted to a subset of the mutator and the event dispatching suppressed. Uses mutateBase, but can be overwritten in subclasses

      Parameters

      Returns void

    • Sets the color channels of this color.

      Parameters

      • _r: number
      • _g: number
      • _b: number
      • _a: number

      Returns Color

      A reference to this color.

    • Sets this color from the given 8-bit values for the color channels.

      Parameters

      • _r: number
      • _g: number
      • _b: number
      • _a: number

      Returns Color

      A reference to this color.

    • Sets the color channels of this color and clamps them between 0 and 1.

      Parameters

      • _r: number
      • _g: number
      • _b: number
      • _a: number

      Returns Color

      A reference to this color.

    • Sets this color from the given css color keyword. Optinally sets the alpha value to the given value.

      Parameters

      • _keyword: string
      • Optional_alpha: number

      Returns Color

      A reference to this color.

    • Sets this color from the given hsl values.

      Parameters

      • _hue: number
      • _saturation: number
      • _lightness: number
      • Optional_alpha: number

      Returns Color

    • Copy the values of this object into the given array starting at the given offset. Creates a new array if none is provided.

      Type Parameters

      • T extends { [n: number]: number } = number[]

      Parameters

      • _out: T = ...

        (optional) The receiving array.

      • _offset: number = 0

        (optional) The offset to start writing to.

      Returns T

      _out or a new array if none is provided.

    • Returns the hex string representation of this color. // TODO: maybe this should return a number instead of a string?

      Returns string

    • Returns a new Color object created from the given css color keyword. Passing an _alpha value will override the alpha value specified in the keyword. Supported color formats are:

      • named colors (e.g. "red", "blue", "green")
      • hex colors (e.g. "#f00" "#ff0000", "#ff0000ff")
      • srgb colors (e.g. "rgb(255 0 0 / 1)", "rgb(255, 0, 0)", "rgba(0, 0, 255, 1))
      • hsl colors (e.g. "hsl(90deg 100% 50% / 1)", "hsl(90, 100%, 50%)", hsla(90, 100%, 50%, 1))

      Note: If possibile try to avoid invoking this method frequently, as it might cause major garbage collection depending on the keyword and browser.

      Parameters

      • _keyword: string
      • Optional_alpha: number
      • _out: Color = ...

        Optional color to store the result in.

      Returns Color

    • Converts the given HSL values to RGB and returns the result in the given object.

      Type Parameters

      • T extends { b: number; g: number; r: number } = { b: number; g: number; r: number }

      Parameters

      • _hue: number

        Hue as an angle in degrees in range [0, 360].

      • _saturation: number

        Saturation in range [0, 1]

      • _lightness: number

        Lightness in range [0, 1]

      • _out: T

        Optional color to store the result in.

      Returns T

      The RGB values in range [0, 1].

    • Type Parameters

      • T extends { h: number; l: number; s: number } = { h: number; l: number; s: number }

      Parameters

      • _red: number

        Red value [0, 1]

      • _green: number

        Green component [0, 1]

      • _blue: number

        Blue component [0, 1]

      • _out: T

        Optional color to store the result in.

      Returns T

      The HSL values. Hue as an angle in degrees in range [0, 360]. Saturation and lightness in range [0, 1].