First Commit
This commit is contained in:
4
node_modules/culori/src/cubehelix/constants.js
generated
vendored
Normal file
4
node_modules/culori/src/cubehelix/constants.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export const M = [-0.14861, 1.78277, -0.29227, -0.90649, 1.97294, 0];
|
||||
|
||||
export const degToRad = Math.PI / 180;
|
||||
export const radToDeg = 180 / Math.PI;
|
21
node_modules/culori/src/cubehelix/convertCubehelixToRgb.js
generated
vendored
Normal file
21
node_modules/culori/src/cubehelix/convertCubehelixToRgb.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { degToRad, M } from './constants.js';
|
||||
|
||||
const convertCubehelixToRgb = ({ h, s, l, alpha }) => {
|
||||
let res = { mode: 'rgb' };
|
||||
|
||||
h = (h === undefined ? 0 : h + 120) * degToRad;
|
||||
|
||||
let amp = s === undefined ? 0 : s * l * (1 - l);
|
||||
|
||||
let cosh = Math.cos(h);
|
||||
let sinh = Math.sin(h);
|
||||
|
||||
res.r = l + amp * (M[0] * cosh + M[1] * sinh);
|
||||
res.g = l + amp * (M[2] * cosh + M[3] * sinh);
|
||||
res.b = l + amp * (M[4] * cosh + M[5] * sinh);
|
||||
|
||||
if (alpha !== undefined) res.alpha = alpha;
|
||||
return res;
|
||||
};
|
||||
|
||||
export default convertCubehelixToRgb;
|
40
node_modules/culori/src/cubehelix/convertRgbToCubehelix.js
generated
vendored
Normal file
40
node_modules/culori/src/cubehelix/convertRgbToCubehelix.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Convert a RGB color to the Cubehelix HSL color space.
|
||||
|
||||
This computation is not present in Green's paper:
|
||||
https://arxiv.org/pdf/1108.5083.pdf
|
||||
|
||||
...but can be derived from the inverse, HSL to RGB conversion.
|
||||
|
||||
It matches the math in Mike Bostock's D3 implementation:
|
||||
|
||||
https://github.com/d3/d3-color/blob/master/src/cubehelix.js
|
||||
*/
|
||||
|
||||
import { radToDeg, M } from './constants.js';
|
||||
|
||||
let DE = M[3] * M[4];
|
||||
let BE = M[1] * M[4];
|
||||
let BCAD = M[1] * M[2] - M[0] * M[3];
|
||||
|
||||
const convertRgbToCubehelix = ({ r, g, b, alpha }) => {
|
||||
let l = (BCAD * b + r * DE - g * BE) / (BCAD + DE - BE);
|
||||
let x = b - l;
|
||||
let y = (M[4] * (g - l) - M[2] * x) / M[3];
|
||||
|
||||
let res = {
|
||||
mode: 'cubehelix',
|
||||
l: l,
|
||||
s:
|
||||
l === 0 || l === 1
|
||||
? undefined
|
||||
: Math.sqrt(x * x + y * y) / (M[4] * l * (1 - l))
|
||||
};
|
||||
|
||||
if (res.s) res.h = Math.atan2(y, x) * radToDeg - 120;
|
||||
if (alpha !== undefined) res.alpha = alpha;
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
export default convertRgbToCubehelix;
|
84
node_modules/culori/src/cubehelix/definition.js
generated
vendored
Normal file
84
node_modules/culori/src/cubehelix/definition.js
generated
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
Dave Green's Cubehelix
|
||||
----------------------
|
||||
|
||||
Green, D. A., 2011, "A colour scheme for the display of astronomical intensity images",
|
||||
Bulletin of the Astronomical Society of India, 39, 289. (2011BASI...39..289G at ADS.)
|
||||
|
||||
https://www.mrao.cam.ac.uk/%7Edag/CUBEHELIX/
|
||||
https://arxiv.org/pdf/1108.5083.pdf
|
||||
|
||||
Although Cubehelix was defined to be a method to obtain a colour scheme,
|
||||
it actually contains a definition of a colour space, as identified by
|
||||
Mike Bostock and implemented in D3.js.
|
||||
|
||||
Green's paper introduces the following terminology:
|
||||
|
||||
* a `lightness` dimension in the interval [0, 1]
|
||||
on which we interpolate to obtain the colour scheme
|
||||
* a `start` colour that is analogous to a Hue in HSL space
|
||||
* a number of `rotations` around the Hue cylinder.
|
||||
* a `hue` parameter which should more appropriately be called `saturation`
|
||||
|
||||
As such, the original definition of the Cubehelix scheme is actually an
|
||||
interpolation between two colors in the Cubehelix space:
|
||||
|
||||
H: start H: start + 360 * rotations
|
||||
S: hue -> S: hue
|
||||
L: 0 L: 1
|
||||
|
||||
We can therefore extend the interpolation to any two colors in this space,
|
||||
with a variable Saturation and a Lightness interval other than the fixed 0 -> 1.
|
||||
*/
|
||||
|
||||
import { fixupHueShorter } from '../fixup/hue.js';
|
||||
import { fixupAlpha } from '../fixup/alpha.js';
|
||||
import { interpolatorLinear } from '../interpolate/linear.js';
|
||||
import convertRgbToCubehelix from './convertRgbToCubehelix.js';
|
||||
import convertCubehelixToRgb from './convertCubehelixToRgb.js';
|
||||
import { differenceHueSaturation } from '../difference.js';
|
||||
import { averageAngle } from '../average.js';
|
||||
|
||||
const definition = {
|
||||
mode: 'cubehelix',
|
||||
channels: ['h', 's', 'l', 'alpha'],
|
||||
parse: ['--cubehelix'],
|
||||
serialize: '--cubehelix',
|
||||
|
||||
ranges: {
|
||||
h: [0, 360],
|
||||
s: [0, 4.614],
|
||||
l: [0, 1]
|
||||
},
|
||||
|
||||
fromMode: {
|
||||
rgb: convertRgbToCubehelix
|
||||
},
|
||||
|
||||
toMode: {
|
||||
rgb: convertCubehelixToRgb
|
||||
},
|
||||
|
||||
interpolate: {
|
||||
h: {
|
||||
use: interpolatorLinear,
|
||||
fixup: fixupHueShorter
|
||||
},
|
||||
s: interpolatorLinear,
|
||||
l: interpolatorLinear,
|
||||
alpha: {
|
||||
use: interpolatorLinear,
|
||||
fixup: fixupAlpha
|
||||
}
|
||||
},
|
||||
|
||||
difference: {
|
||||
h: differenceHueSaturation
|
||||
},
|
||||
|
||||
average: {
|
||||
h: averageAngle
|
||||
}
|
||||
};
|
||||
|
||||
export default definition;
|
Reference in New Issue
Block a user