'use strict';
const Rac = require('../Rac');
/**
* Members and methods attached to the
* [`rac.Color` function]{@link Rac#Color}.
*
* The function contains ready-made convenience
* [`Color`]{@link Rac.Color} objects for usual values, all setup with the
* owning `Rac` instance.
*
* @example
* let rac = new Rac()
* rac.Color.red // ready-made red color
* rac.Color.red.rac === rac // true
*
* @namespace instance.Color
*/
module.exports = function attachRacColor(rac) {
// Intended to receive a Rac instance as parameter
/**
* Returns a new `Color` with each channel received in the *[0,255]* range.
*
* @param {Number} r - The red channel value, in the *[0,255]* range
* @param {Number} g - The green channel value, in the *[0,255]* range
* @param {Number} b - The blue channel value, in the *[0,255]* range
* @param {Number} [a=255] - The alpha channel value, in the *[0,255]* range
*
* @returns {Rac.Color}
*
* @function fromRgba
* @memberof instance.Color#
*/
rac.Color.fromRgba = function(r, g, b, a = 255) {
return Rac.Color.fromRgba(rac, r, g, b, a);
};
/**
* Returns 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.
*
* @param {String} hexString - The RGB hex triplet to interpret
* @returns {Rac.Color}
*/
rac.Color.fromHex = function(hexString) {
return Rac.Color.fromHex(rac, hexString);
}
/**
* A black `Color`.
*
* @name black
* @memberof instance.Color#
*/
rac.Color.black = rac.Color(0, 0, 0);
/**
* A red `Color`.
*
* @name red
* @memberof instance.Color#
*/
rac.Color.red = rac.Color(1, 0, 0);
rac.Color.green = rac.Color(0, 1, 0);
rac.Color.blue = rac.Color(0, 0, 1);
rac.Color.yellow = rac.Color(1, 1, 0);
rac.Color.magenta = rac.Color(1, 0, 1);
rac.Color.cyan = rac.Color(0, 1, 1);
rac.Color.white = rac.Color(1, 1, 1);
} // attachRacColor