-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathlchuv.js
52 lines (43 loc) · 966 Bytes
/
lchuv.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Cylindrical CIE LUV
*
* @module color-space/lchuv
*/
import luv from './luv.js';
import xyz from './xyz.js';
//cylindrical luv
/** @type {Partial<import('./index.js').ColorSpace> & {luv: import('./index.js').Transform}} */
var lchuv = {
name: 'lchuv',
channel: ['lightness', 'chroma', 'hue'],
alias: ['LCHuv', 'cielchuv'],
min: [0,0,0],
max: [100,100,360],
luv: function(luv){
var l = luv[0],
c = luv[1],
h = luv[2],
u, v, hr;
hr = h / 360 * 2 * Math.PI;
u = c * Math.cos(hr);
v = c * Math.sin(hr);
return [l, u, v];
},
xyz: function(arg) {
return luv.xyz(lchuv.luv(arg));
}
};
export default /** @type {import('./index.js').ColorSpace} */ (lchuv);
luv.lchuv = function(luv){
var l = luv[0], u = luv[1], v = luv[2];
var c = Math.sqrt(u*u + v*v);
var hr = Math.atan2(v,u);
var h = hr * 360 / 2 / Math.PI;
if (h < 0) {
h += 360;
}
return [l,c,h]
};
xyz.lchuv = function(arg){
return luv.lchuv(xyz.luv(arg));
};