Rac. Color

Color with RBGA values, each one in the [0,1] range.

instance.Color

Instances of Rac contain a convenience rac.Color function to create Color objects with fewer parameters. This function also contains ready-made convenience objects, like rac.Color.red, listed under instance.Color.

Example
let rac = new Rac()
// new instance with constructor
let color = new Rac.Color(rac, 0.2, 0.4, 0.6)
// or convenience function
let otherColor = rac.Color(0.2, 0.4, 0.6)
See also:

Constructor

new Color(rac, r, g, b, aopt)

Creates a new Color instance.

Parameters:
Name Type Attributes Default Description
rac Rac

Instance to use for drawing and creating other objects

r Number

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

g Number

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

b Number

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

a Number <optional>
1

The alpha channel value, in the [0,1] range

Members

a :Number

The alpha channel of the color, in the [0,1] range.

b :Number

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

g :Number

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

r :Number

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

rac :Rac

Instance of Rac used for drawing and passed along to any created object.

Methods

(static) fromHex(rac, hexString) → {Rac.Color}

Creates a new Color instance from a hexadecimal triplet or quadruplet string.

The hexString is expected to have 6 or 8 hex digits for the RGB and optionally alpha channels. It can start with #. AABBCC and #CCDDEEFF are both valid inputs.

The three digit shorthand is not yet supported.

An error is thrown if hexString is misformatted or cannot be parsed.

Parameters:
Name Type Description
rac Rac

Instance to use for drawing and creating other objects

hexString String

The hex string to interpret

(static) fromRgba(rac, r, g, b, aopt) → {Rac.Color}

Creates a new Color instance with each channel received in the [0,255] range

Parameters:
Name Type Attributes Default Description
rac Rac

Instance to use for drawing and creating other objects

r Number

The red channel value, in the [0,255] range

g Number

The green channel value, in the [0,255] range

b Number

The blue channel value, in the [0,255] range

a Number <optional>
255

The alpha channel value, in the [0,255] range

equals(otherColor) → {Boolean}

Returns true when the difference with otherColor for each channel is under rac.equalityThreshold; otherwise returns false.

When otherColor is any class other that Rac.Color, returns false.

Values are compared using rac.unitaryEquals.

See also:
Parameters:
Name Type Description
otherColor Rac.Color

A Color to compare

fill() → {Rac.Fill}

Returns a new Fill that uses this as color.

linearTransition(ratio, target) → {Rac.Color}

Returns a new Color in the linear transition between this and target at a ratio in the range [0,1].

When ratio is 0 or less the new Color is equivalent to this, when ratio is 1 or larger the new Color is equivalent to target.

Parameters:
Name Type Description
ratio Number

The transition ratio for the new Color

target Rac.Color

The transition target Color

stroke(weightnullable) → {Rac.Stroke}

Returns a new Stroke that uses this as color.

Parameters:
Name Type Attributes Default Description
weight Number <nullable>
null

The weight of the new Stroke

toString(digitsopt) → {String}

Returns a string representation intended for human consumption.

Parameters:
Name Type Attributes Default Description
digits Number <optional>
null

The number of digits to print after the decimal point, when ommited all digits are printed

Example
rac.Color(0.1, 0.2, 0.3, 0.4).toString()
// returns: 'Color(0.1,0.2,0.3,0.4)'

withAlpha(newAlpha) → {Rac.Color}

Returns a new Color with a set to newAlpha.

Parameters:
Name Type Description
newAlpha Number

The alpha channel for the new Color, in the [0,1] range

withAlphaRatio(ratio) → {Rac.Color}

Returns a new Color with a set to this.a * ratio.

Parameters:
Name Type Description
ratio Number

The factor to multiply a by