Color is a subclass of Pt. You can think of a color as a point in a color space. The Color class provides support for many color spaces.
Create a Color. Same as creating a Pt.
Pt-like parameters which can be a list of numeric parameters, an array of numbers, or an object with {x,y,z,w} properties
The size in bytes of each element in the array.
The ArrayBuffer instance referenced by the array.
The length in bytes of the array.
The offset in bytes of the array.
The length of the array.
Get alpha value
Get a hex string such as "#FF0000". Same as toString("hex")
Get this Color's mode
Get a rgb string such as "rgb(255,0,0)". Same as toString("rgb")
Get a rgba string such as "rgb(255,0,0,0.5)". Same as toString("rgba")
Get a new Pt with absolute values of this Pt
Like add
, but returns result as a new Pt
Get a new Pt with ceil values of this Pt
Concatenate this Pt with addition dimensional values and return as a new Pt
a list of numbers, an array of number, or an object with {x,y,z,w} properties
3D Cross product of this Pt and another Pt. Return results as a new Pt.
a list of numbers, an array of number, or an object with {x,y,z,w} properties
Like divide
, but returns result as a new Pt
Get a new Pt with floor values of this Pt
Get a new Pt that has the maximum dimensional values of this Pt and another Pt
a list of numbers, an array of number, or an object with {x,y,z,w} properties
Get a new Pt that has the minimum dimensional values of this Pt and another Pt
a list of numbers, an array of number, or an object with {x,y,z,w} properties
Like multiply
, but returns result as a new Pt
Like normalize()
but returns as a new Color
a boolean value specifying whether to normalize (true
) or revert (false
)
new Color
Get a new Pt with round values of this Pt
Like subtract
, but returns result as a new Pt
Take specific dimensional values from this Pt and create a new Pt
a string such as "xy" (use Const.xy) or an array to specify index for two dimensions
Like to()
but returns a new Pt
a list of numbers, an array of number, or an object with {x,y,z,w} properties
Get a unit vector from this Pt
Absolute values for all values in this pt
Add scalar or vector values to this Pt
a list of numbers, an array of number, or an object with {x,y,z,w} properties
Get angle of this vector from origin
a string such as "xy" (use Const.xy) or an array to specify index for two dimensions
Get the angle between this and another Pt
the other Pt
a string such as "xy" (use Const.xy) or an array to specify index for two dimensions
Ceil values for all values in this pt
Clone this Color
2D Cross product of this Pt and another Pt. Return results as a new Pt.
a list of numbers, an array of number, or an object with {x,y,z,w} properties
Divide this Pt over scalar or vector values (as element-wise)
a list of numbers, an array of number, or an object with {x,y,z,w} properties
Dot product of this Pt and another Pt
a list of numbers, an array of number, or an object with {x,y,z,w} properties
Check if another Pt is equal to this Pt, within a threshold
another Pt to compare with
a threshold value within which the two Pts are considered equal. Default is 0.000001.
Floor values for all values in this pt
Get the distance (magnitude) of this Pt from origin
Get the sqaured distance (magnitude) of this Pt from origin
Find the maximum value across all dimensions in this Pt
an object with value
and index
which returns the maximum value and its dimensional index
Find the minimum value across all dimensions in this Pt
an object with value
and index
which returns the minimum value and its dimensional index
Multiply scalar or vector values (as element-wise) with this Pt.
a list of numbers, an array of number, or an object with {x,y,z,w} properties
Normalize the color values to between 0 to 1, or revert it back to the min/max values in current color mode
a boolean value specifying whether to normalize (true
) or revert (false
)
Create an operation using this Pt, passing this Pt into a custom function's first parameter. See the Op guide for details.
For example: let myOp = pt.op( fn ); let result = myOp( [1,2,3] );
any function that takes a Pt as its first parameter
a resulting function that takes other parameters required in fn
This combines a series of operations into an array. See op()
for details.
For example: let myOps = pt.ops([fn1, fn2, fn3]); let results = myOps.map( (op) => op([1,2,3]) );
an array of functions for op
an array of resulting functions
Reflect this Pt along a 2D line
a Group of 2 Pts that defines a line for reflection
optional axis such as "yz" to define a 2D plane of reflection
Rotate this Pt from origin or from an anchor point in 2D
rotate angle
optional anchor point to scale from
optional string such as "yz" to specify a 2D plane
Round values for all values in this pt
Subtract scalar or vector values from this Pt
a list of numbers, an array of number, or an object with {x,y,z,w} properties
Update the values of this Pt
a list of numbers, an array of number, or an object with {x,y,z,w} properties
Update the values of this Pt to point at a specific angle
target angle in radian
Optional magnitude if known. If not provided, it'll calculate and use this Pt's magnitude.
If true
, translate to new position from current position. Default is false
which update the position from origin (0,0);
Convert this Pt to a javascript Array
Convert this color from current color space to another color space
a ColorType string: "rgb" "hsl" "hsb" "lab" "lch" "luv" "xyz";
if true
, convert this Color to the new color space specified in mode
. Default is false
, which only sets the color mode without converting color values.
Convert this Color to a string. It can be used to get a hex or rgb string for use in rendering
"hex", "rgb", "rgba", or "mode" which means using current color mode label. Default is "mode".
Convert to a unit vector, which is a normalized vector whose magnitude equals 1.
Optional: if the magnitude is known, pass it as a parameter to avoid duplicate calculation.
Convert HSB to RGB
a HSB Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new RGB Color
Convert HSL to RGB
a HSL Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new RGB Color
Convert LAB to LCH
a LAB Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new LCH Color
Convert LAB to RGB
a LAB Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new RGB Color
Convert LAB to XYZ
a LAB Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new XYZ Color
Convert LCH to LAB
a LCH Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new LAB Color
Convert LCH to RGB
a LCH Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new RGB Color
Convert LUV to RGB
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new RGB Color
Convert LUV to XYZ
a LUV Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new XYZ Color
Convert RGB to HSB
a RGB Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new HSB Color
Convert RGB to HSL
a RGB Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new HSL Color
Convert RGB to LAB
a RGB Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new LAB Color
Convert RGB to LCH
a RGB Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new LCH Color
Convert RGB to LUV
a RGB Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new LUV Color
Convert RGB to XYZ
a RGB Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new XYZ Color
Convert XYZ to LAB
a XYZ Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new LAB Color
Convert XYZ to LUV
a XYZ Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new LUV Color
Convert XYZ to RGB
a XYZ Color
a boolean specifying whether input color is normalized. Default is not normalized: false
.
a boolean specifying whether output color shoud be normalized. Default is not normalized: false
.
a new RGB Color
Returns the this object after copying a section of the array identified by start and end to the same array starting at position target
If target is negative, it is treated as length+target where length is the length of the array.
If start is negative, it is treated as length+start. If end is negative, it is treated as length+end.
If not specified, length of the this object is used as its default value.
Determines whether all the members of an array satisfy the specified test.
A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array.
Returns the this object after filling the section identified by start and end with value
value to fill array section with
index to start filling the array at. If start is negative, it is treated as length+start where length is the length of the array.
index to stop filling the array at. If end is negative, it is treated as length+end.
Returns the elements of an array that meet the condition specified in a callback function.
A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array.
Returns the value of the first element in the array where predicate is true, and undefined otherwise.
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined.
Returns the index of the first element in the array where predicate is true, and -1 otherwise.
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.
Performs the specified action for each element in an array.
A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
Create a Color object with defaults to 4 dimensions
Pt-like parameters which can be a list of numeric parameters, an array of numbers, or an object with {x,y,z,w} properties
Convert a rgb hex string like #FF0000 or #F00 to a Color object
a hex string, with optional '#' prefix
Create HSB Color
Pt-like parameters which can be a list of numeric parameters, an array of numbers, or an object with {x,y,z,w} properties.
Create HSL Color
Pt-like parameters which can be a list of numeric parameters, an array of numbers, or an object with {x,y,z,w} properties.
Returns the index of the first occurrence of a value in an array.
The value to locate in the array.
The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
Adds all the elements of an array separated by the specified separator string.
A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
Create LAB Color
Pt-like parameters which can be a list of numeric parameters, an array of numbers, or an object with {x,y,z,w} properties.
Returns the index of the last occurrence of a value in an array.
The value to locate in the array.
The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
Create LCH Color
Pt-like parameters which can be a list of numeric parameters, an array of numbers, or an object with {x,y,z,w} properties.
Create LUV Color
Pt-like parameters which can be a list of numeric parameters, an array of numbers, or an object with {x,y,z,w} properties.
Calls a defined callback function on each element of an array, and returns an array that contains the results.
A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
Get a Color object whose values are the maximum of its mode
a mode string such as "rgb" or "lab"
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
If initialValue is specified, it is used as the initial value to start the accumulation. The first call to the callbackfn function provides this value as an argument instead of an array value.
Reverses the elements in an Array.
Create RGB Color
Pt-like parameters which can be a list of numeric parameters, an array of numbers, or an object with {x,y,z,w} properties.
Sets a value or an array of values.
A typed or untyped array of values to set.
The index in the current array at which the values are to be written.
Returns a section of an array.
The beginning of the specified portion of the array.
The end of the specified portion of the array.
Determines whether the specified callback function returns true for any element of an array.
A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array.
Sorts an array.
The name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.
Gets a new Float32Array view of the ArrayBuffer store for this array, referencing the elements at begin, inclusive, up to end, exclusive.
The index of the beginning of the array.
The index of the end of the array.
Converts a number to a string by using the current locale.
Returns a string representation of an array.
Create XYZ Color
Pt-like parameters which can be a list of numeric parameters, an array of numbers, or an object with {x,y,z,w} properties.
Value range for each color space
Generated using TypeDoc
Color is a subclass of Pt. You can think of a color as a point in a color space. The Color class provides support for many color spaces.