It is a part of kch-rgbw-lib.
See README.md
for general information.
Functions in this documents are in CIE 1931 chromaticity for (x, y)
and in Kelvin for blackbody temperature k
.
In TypeScript/ES2015:
import { CSpace, CSpaceTypes } from 'kch-rgbw-lib';
import { k2x, k2y, xy2k, fadeOutK, fadeInK } from 'kch-rgbw-lib';
Return (x, y) chromaticity of black body corresponding to the given color temperature in K.
Return correlated color temperature (CCT) corresponding to (x, y) chromaticity.
xy
should be in 'xy' or 'xyY' of CSpaceTypes
.
Other types will throw an exception.
Optimized McCamy's approximation is used. Note that returned CCT is
physically meaningful only when (x, y) is on or near the white light.
In particular, the area between blue and red is very inaccurate as shown
in the color mapping of the returned temperature.
Although CCT by McCamy's approximation is known that it's isotherms are less accurate than other methods, it gives the smallest error in [1000, 7000] k according to my experiment.
Return array of CSpace, filling with interpolated points starting/ending
at xy0.
xy0
should be in 'xy' or 'xyY' of CSpaceTypes
.
Other types will throw an exception.
fadeOutK()
ends / fadeInK()
starts at the point where
color temperature is 1000 K.
fade()
is a function used to interpolate between the start and end points.
fade()
is called repeatedly with changing r
from 0 to 1, like:
const p: CSpace[] = new Array(steps) as CSpace[];
for (let i=0; i<steps; i++) {
const r = fade(i / steps);
(interpolate start (x,y) and end (x,y) by r)
(interpolate colorTemperature of (x,y) and 1000 by r)
p[i] = { interpolated x, y, k };
}
It is intended to mimicking lamp gradually turning off/on.
Note: when (x,y) is far from the black body curve, it behaves odd,
due to the limitation of xy2k()
.
The MIT License (MIT) Copyright (c) K. Chinzei ([email protected]) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.