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 string.

The hexString is expected to have 6 digits and can optionally start with #. AABBCC and #DDEEFF 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 RGB hex triplet 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

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() → {String}

Returns a string representation intended for human consumption.

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