simview 3.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- simview/__init__.py +69 -0
- simview/__main__.py +174 -0
- simview/launcher.py +109 -0
- simview/live.py +204 -0
- simview/merge.py +593 -0
- simview/model.py +690 -0
- simview/py.typed +0 -0
- simview/scene.py +603 -0
- simview/server.py +739 -0
- simview/state.py +190 -0
- simview/static/css/controls.css +36 -0
- simview/static/js/SimView.js +601 -0
- simview/static/js/components/AnimationController.js +654 -0
- simview/static/js/components/BatchManager.js +198 -0
- simview/static/js/components/InteractionController.js +446 -0
- simview/static/js/components/InteractionControls.js +116 -0
- simview/static/js/components/Scene.js +166 -0
- simview/static/js/components/StateStore.js +188 -0
- simview/static/js/config.js +233 -0
- simview/static/js/main.js +3 -0
- simview/static/js/objects/Body.js +616 -0
- simview/static/js/objects/StaticObject.js +181 -0
- simview/static/js/objects/Terrain.js +514 -0
- simview/static/js/objects/utils.js +378 -0
- simview/static/js/ui/AnalysisPanel.js +233 -0
- simview/static/js/ui/BatchLegend.js +207 -0
- simview/static/js/ui/BodyStateWindow.js +521 -0
- simview/static/js/ui/Controls.js +586 -0
- simview/static/js/ui/ErrorMetrics.js +664 -0
- simview/static/js/ui/Legend.js +87 -0
- simview/static/js/ui/PlaybackControls.js +314 -0
- simview/static/js/ui/ScalarPlotter.js +575 -0
- simview/static/js/utils/blobCodec.js +73 -0
- simview/static/js/utils/bodyTransforms.js +151 -0
- simview/static/js/utils/csv.js +46 -0
- simview/static/js/utils/errorMath.js +69 -0
- simview/static/js/utils/injectStyles.js +16 -0
- simview/static/js/utils/interpolate.js +65 -0
- simview/static/js/utils/liveFollow.js +17 -0
- simview/static/js/utils/loadRecordingLibs.js +34 -0
- simview/static/js/utils/viewState.js +226 -0
- simview/static/lib/chroma-js-3.1.2/index.min.js +8 -0
- simview/static/lib/chroma-js-3.1.2/src/Color.js +49 -0
- simview/static/lib/chroma-js-3.1.2/src/chroma.js +10 -0
- simview/static/lib/chroma-js-3.1.2/src/colors/colorbrewer.js +81 -0
- simview/static/lib/chroma-js-3.1.2/src/colors/w3cx11.js +164 -0
- simview/static/lib/chroma-js-3.1.2/src/generator/average.js +88 -0
- simview/static/lib/chroma-js-3.1.2/src/generator/bezier.js +86 -0
- simview/static/lib/chroma-js-3.1.2/src/generator/blend.js +57 -0
- simview/static/lib/chroma-js-3.1.2/src/generator/cubehelix.js +87 -0
- simview/static/lib/chroma-js-3.1.2/src/generator/mix.js +19 -0
- simview/static/lib/chroma-js-3.1.2/src/generator/random.js +12 -0
- simview/static/lib/chroma-js-3.1.2/src/generator/scale.js +394 -0
- simview/static/lib/chroma-js-3.1.2/src/interpolator/_hsx.js +59 -0
- simview/static/lib/chroma-js-3.1.2/src/interpolator/hcg.js +12 -0
- simview/static/lib/chroma-js-3.1.2/src/interpolator/hsi.js +12 -0
- simview/static/lib/chroma-js-3.1.2/src/interpolator/hsl.js +12 -0
- simview/static/lib/chroma-js-3.1.2/src/interpolator/hsv.js +12 -0
- simview/static/lib/chroma-js-3.1.2/src/interpolator/index.js +1 -0
- simview/static/lib/chroma-js-3.1.2/src/interpolator/lab.js +19 -0
- simview/static/lib/chroma-js-3.1.2/src/interpolator/lch.js +13 -0
- simview/static/lib/chroma-js-3.1.2/src/interpolator/lrgb.js +19 -0
- simview/static/lib/chroma-js-3.1.2/src/interpolator/num.js +15 -0
- simview/static/lib/chroma-js-3.1.2/src/interpolator/oklab.js +19 -0
- simview/static/lib/chroma-js-3.1.2/src/interpolator/oklch.js +12 -0
- simview/static/lib/chroma-js-3.1.2/src/interpolator/rgb.js +18 -0
- simview/static/lib/chroma-js-3.1.2/src/io/cmyk/cmyk2rgb.js +16 -0
- simview/static/lib/chroma-js-3.1.2/src/io/cmyk/index.js +27 -0
- simview/static/lib/chroma-js-3.1.2/src/io/cmyk/rgb2cmyk.js +17 -0
- simview/static/lib/chroma-js-3.1.2/src/io/css/css2rgb.js +238 -0
- simview/static/lib/chroma-js-3.1.2/src/io/css/hsl2css.js +26 -0
- simview/static/lib/chroma-js-3.1.2/src/io/css/index.js +27 -0
- simview/static/lib/chroma-js-3.1.2/src/io/css/lab2css.js +24 -0
- simview/static/lib/chroma-js-3.1.2/src/io/css/lch2css.js +24 -0
- simview/static/lib/chroma-js-3.1.2/src/io/css/oklab2css.js +16 -0
- simview/static/lib/chroma-js-3.1.2/src/io/css/oklch2css.js +16 -0
- simview/static/lib/chroma-js-3.1.2/src/io/css/rgb2css.js +61 -0
- simview/static/lib/chroma-js-3.1.2/src/io/gl/index.js +22 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hcg/hcg2rgb.js +55 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hcg/index.js +27 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hcg/rgb2hcg.js +23 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hex/hex2rgb.js +56 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hex/index.js +29 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hex/rgb2hex.js +29 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hsi/hsi2rgb.js +45 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hsi/index.js +27 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hsi/rgb2hsi.js +31 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hsl/hsl2rgb.js +35 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hsl/index.js +27 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hsl/rgb2hsl.js +45 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hsv/hsv2rgb.js +47 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hsv/index.js +27 -0
- simview/static/lib/chroma-js-3.1.2/src/io/hsv/rgb2hsv.js +32 -0
- simview/static/lib/chroma-js-3.1.2/src/io/input.js +4 -0
- simview/static/lib/chroma-js-3.1.2/src/io/lab/index.js +28 -0
- simview/static/lib/chroma-js-3.1.2/src/io/lab/lab-constants.js +120 -0
- simview/static/lib/chroma-js-3.1.2/src/io/lab/lab2rgb.js +101 -0
- simview/static/lib/chroma-js-3.1.2/src/io/lab/rgb2lab.js +67 -0
- simview/static/lib/chroma-js-3.1.2/src/io/lch/hcl2rgb.js +9 -0
- simview/static/lib/chroma-js-3.1.2/src/io/lch/index.js +35 -0
- simview/static/lib/chroma-js-3.1.2/src/io/lch/lab2lch.js +12 -0
- simview/static/lib/chroma-js-3.1.2/src/io/lch/lch2lab.js +18 -0
- simview/static/lib/chroma-js-3.1.2/src/io/lch/lch2rgb.js +13 -0
- simview/static/lib/chroma-js-3.1.2/src/io/lch/rgb2lch.js +12 -0
- simview/static/lib/chroma-js-3.1.2/src/io/named/index.js +30 -0
- simview/static/lib/chroma-js-3.1.2/src/io/num/index.js +32 -0
- simview/static/lib/chroma-js-3.1.2/src/io/num/num2rgb.js +13 -0
- simview/static/lib/chroma-js-3.1.2/src/io/num/rgb2num.js +8 -0
- simview/static/lib/chroma-js-3.1.2/src/io/oklab/index.js +27 -0
- simview/static/lib/chroma-js-3.1.2/src/io/oklab/oklab2rgb.js +34 -0
- simview/static/lib/chroma-js-3.1.2/src/io/oklab/rgb2oklab.js +37 -0
- simview/static/lib/chroma-js-3.1.2/src/io/oklch/index.js +27 -0
- simview/static/lib/chroma-js-3.1.2/src/io/oklch/oklch2rgb.js +13 -0
- simview/static/lib/chroma-js-3.1.2/src/io/oklch/rgb2oklch.js +12 -0
- simview/static/lib/chroma-js-3.1.2/src/io/rgb/index.js +44 -0
- simview/static/lib/chroma-js-3.1.2/src/io/temp/index.js +22 -0
- simview/static/lib/chroma-js-3.1.2/src/io/temp/rgb2temperature.js +30 -0
- simview/static/lib/chroma-js-3.1.2/src/io/temp/temperature2rgb.js +39 -0
- simview/static/lib/chroma-js-3.1.2/src/ops/alpha.js +13 -0
- simview/static/lib/chroma-js-3.1.2/src/ops/clipped.js +5 -0
- simview/static/lib/chroma-js-3.1.2/src/ops/darken.js +17 -0
- simview/static/lib/chroma-js-3.1.2/src/ops/get.js +13 -0
- simview/static/lib/chroma-js-3.1.2/src/ops/luminance.js +54 -0
- simview/static/lib/chroma-js-3.1.2/src/ops/mix.js +10 -0
- simview/static/lib/chroma-js-3.1.2/src/ops/premultiply.js +12 -0
- simview/static/lib/chroma-js-3.1.2/src/ops/saturate.js +15 -0
- simview/static/lib/chroma-js-3.1.2/src/ops/set.js +43 -0
- simview/static/lib/chroma-js-3.1.2/src/ops/shade.js +11 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/analyze.js +191 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/clip_rgb.js +15 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/contrast.js +12 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/contrastAPCA.js +68 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/delta-e.js +62 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/distance.js +17 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/index.js +27 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/last.js +8 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/limit.js +5 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/multiply-matrices.js +36 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/scales.js +15 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/type.js +18 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/unpack.js +17 -0
- simview/static/lib/chroma-js-3.1.2/src/utils/valid.js +11 -0
- simview/static/lib/chroma-js-3.1.2/src/version.js +2 -0
- simview/static/lib/download.js +132 -0
- simview/static/lib/js-colormaps.js +19335 -0
- simview/static/lib/tar.js +334 -0
- simview/static/lib/three-0.174.0/addons/controls/OrbitControls.js +1556 -0
- simview/static/lib/three-0.174.0/addons/libs/lil-gui.module.min.js +8 -0
- simview/static/lib/three-0.174.0/three.core.js +48830 -0
- simview/static/lib/three-0.174.0/three.module.js +17313 -0
- simview/static/lib/uPlot.esm.js +6140 -0
- simview/static/lib/uPlot.min.css +2 -0
- simview/static/textures/contacts/red-cross0.png +0 -0
- simview/static/textures/points/ball0.png +0 -0
- simview/static/textures/points/ball1.png +0 -0
- simview/templates/index.html +81 -0
- simview/utils.py +41 -0
- simview-3.2.dist-info/METADATA +552 -0
- simview-3.2.dist-info/RECORD +163 -0
- simview-3.2.dist-info/WHEEL +5 -0
- simview-3.2.dist-info/entry_points.txt +2 -0
- simview-3.2.dist-info/licenses/LICENSE +28 -0
- simview-3.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { last, clip_rgb, type } from './utils/index.js';
|
|
2
|
+
import _input from './io/input.js';
|
|
3
|
+
|
|
4
|
+
class Color {
|
|
5
|
+
constructor(...args) {
|
|
6
|
+
const me = this;
|
|
7
|
+
if (
|
|
8
|
+
type(args[0]) === 'object' &&
|
|
9
|
+
args[0].constructor &&
|
|
10
|
+
args[0].constructor === this.constructor
|
|
11
|
+
) {
|
|
12
|
+
// the argument is already a Color instance
|
|
13
|
+
return args[0];
|
|
14
|
+
}
|
|
15
|
+
// last argument could be the mode
|
|
16
|
+
let mode = last(args);
|
|
17
|
+
let autodetect = false;
|
|
18
|
+
if (!mode) {
|
|
19
|
+
autodetect = true;
|
|
20
|
+
|
|
21
|
+
if (!_input.sorted) {
|
|
22
|
+
_input.autodetect = _input.autodetect.sort((a, b) => b.p - a.p);
|
|
23
|
+
_input.sorted = true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// auto-detect format
|
|
27
|
+
for (let chk of _input.autodetect) {
|
|
28
|
+
mode = chk.test(...args);
|
|
29
|
+
if (mode) break;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (_input.format[mode]) {
|
|
33
|
+
const rgb = _input.format[mode].apply(
|
|
34
|
+
null,
|
|
35
|
+
autodetect ? args : args.slice(0, -1)
|
|
36
|
+
);
|
|
37
|
+
me._rgb = clip_rgb(rgb);
|
|
38
|
+
} else {
|
|
39
|
+
throw new Error('unknown format: ' + args);
|
|
40
|
+
}
|
|
41
|
+
// add alpha channel
|
|
42
|
+
if (me._rgb.length === 3) me._rgb.push(1);
|
|
43
|
+
}
|
|
44
|
+
toString() {
|
|
45
|
+
if (type(this.hex) == 'function') return this.hex();
|
|
46
|
+
return `[${this._rgb.join(',')}]`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export default Color;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
ColorBrewer colors for chroma.js
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The
|
|
5
|
+
Pennsylvania State University.
|
|
6
|
+
|
|
7
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
you may not use this file except in compliance with the License.
|
|
9
|
+
You may obtain a copy of the License at
|
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
13
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
14
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
15
|
+
specific language governing permissions and limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const colorbrewer = {
|
|
19
|
+
// sequential
|
|
20
|
+
OrRd: ['#fff7ec', '#fee8c8', '#fdd49e', '#fdbb84', '#fc8d59', '#ef6548', '#d7301f', '#b30000', '#7f0000'],
|
|
21
|
+
PuBu: ['#fff7fb', '#ece7f2', '#d0d1e6', '#a6bddb', '#74a9cf', '#3690c0', '#0570b0', '#045a8d', '#023858'],
|
|
22
|
+
BuPu: ['#f7fcfd', '#e0ecf4', '#bfd3e6', '#9ebcda', '#8c96c6', '#8c6bb1', '#88419d', '#810f7c', '#4d004b'],
|
|
23
|
+
Oranges: ['#fff5eb', '#fee6ce', '#fdd0a2', '#fdae6b', '#fd8d3c', '#f16913', '#d94801', '#a63603', '#7f2704'],
|
|
24
|
+
BuGn: ['#f7fcfd', '#e5f5f9', '#ccece6', '#99d8c9', '#66c2a4', '#41ae76', '#238b45', '#006d2c', '#00441b'],
|
|
25
|
+
YlOrBr: ['#ffffe5', '#fff7bc', '#fee391', '#fec44f', '#fe9929', '#ec7014', '#cc4c02', '#993404', '#662506'],
|
|
26
|
+
YlGn: ['#ffffe5', '#f7fcb9', '#d9f0a3', '#addd8e', '#78c679', '#41ab5d', '#238443', '#006837', '#004529'],
|
|
27
|
+
Reds: ['#fff5f0', '#fee0d2', '#fcbba1', '#fc9272', '#fb6a4a', '#ef3b2c', '#cb181d', '#a50f15', '#67000d'],
|
|
28
|
+
RdPu: ['#fff7f3', '#fde0dd', '#fcc5c0', '#fa9fb5', '#f768a1', '#dd3497', '#ae017e', '#7a0177', '#49006a'],
|
|
29
|
+
Greens: ['#f7fcf5', '#e5f5e0', '#c7e9c0', '#a1d99b', '#74c476', '#41ab5d', '#238b45', '#006d2c', '#00441b'],
|
|
30
|
+
YlGnBu: ['#ffffd9', '#edf8b1', '#c7e9b4', '#7fcdbb', '#41b6c4', '#1d91c0', '#225ea8', '#253494', '#081d58'],
|
|
31
|
+
Purples: ['#fcfbfd', '#efedf5', '#dadaeb', '#bcbddc', '#9e9ac8', '#807dba', '#6a51a3', '#54278f', '#3f007d'],
|
|
32
|
+
GnBu: ['#f7fcf0', '#e0f3db', '#ccebc5', '#a8ddb5', '#7bccc4', '#4eb3d3', '#2b8cbe', '#0868ac', '#084081'],
|
|
33
|
+
Greys: ['#ffffff', '#f0f0f0', '#d9d9d9', '#bdbdbd', '#969696', '#737373', '#525252', '#252525', '#000000'],
|
|
34
|
+
YlOrRd: ['#ffffcc', '#ffeda0', '#fed976', '#feb24c', '#fd8d3c', '#fc4e2a', '#e31a1c', '#bd0026', '#800026'],
|
|
35
|
+
PuRd: ['#f7f4f9', '#e7e1ef', '#d4b9da', '#c994c7', '#df65b0', '#e7298a', '#ce1256', '#980043', '#67001f'],
|
|
36
|
+
Blues: ['#f7fbff', '#deebf7', '#c6dbef', '#9ecae1', '#6baed6', '#4292c6', '#2171b5', '#08519c', '#08306b'],
|
|
37
|
+
PuBuGn: ['#fff7fb', '#ece2f0', '#d0d1e6', '#a6bddb', '#67a9cf', '#3690c0', '#02818a', '#016c59', '#014636'],
|
|
38
|
+
Viridis: ['#440154', '#482777', '#3f4a8a', '#31678e', '#26838f', '#1f9d8a', '#6cce5a', '#b6de2b', '#fee825'],
|
|
39
|
+
|
|
40
|
+
// diverging
|
|
41
|
+
Spectral: ['#9e0142', '#d53e4f', '#f46d43', '#fdae61', '#fee08b', '#ffffbf', '#e6f598', '#abdda4', '#66c2a5', '#3288bd', '#5e4fa2'],
|
|
42
|
+
RdYlGn: ['#a50026', '#d73027', '#f46d43', '#fdae61', '#fee08b', '#ffffbf', '#d9ef8b', '#a6d96a', '#66bd63', '#1a9850', '#006837'],
|
|
43
|
+
RdBu: ['#67001f', '#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#f7f7f7', '#d1e5f0', '#92c5de', '#4393c3', '#2166ac', '#053061'],
|
|
44
|
+
PiYG: ['#8e0152', '#c51b7d', '#de77ae', '#f1b6da', '#fde0ef', '#f7f7f7', '#e6f5d0', '#b8e186', '#7fbc41', '#4d9221', '#276419'],
|
|
45
|
+
PRGn: ['#40004b', '#762a83', '#9970ab', '#c2a5cf', '#e7d4e8', '#f7f7f7', '#d9f0d3', '#a6dba0', '#5aae61', '#1b7837', '#00441b'],
|
|
46
|
+
RdYlBu: ['#a50026', '#d73027', '#f46d43', '#fdae61', '#fee090', '#ffffbf', '#e0f3f8', '#abd9e9', '#74add1', '#4575b4', '#313695'],
|
|
47
|
+
BrBG: ['#543005', '#8c510a', '#bf812d', '#dfc27d', '#f6e8c3', '#f5f5f5', '#c7eae5', '#80cdc1', '#35978f', '#01665e', '#003c30'],
|
|
48
|
+
RdGy: ['#67001f', '#b2182b', '#d6604d', '#f4a582', '#fddbc7', '#ffffff', '#e0e0e0', '#bababa', '#878787', '#4d4d4d', '#1a1a1a'],
|
|
49
|
+
PuOr: ['#7f3b08', '#b35806', '#e08214', '#fdb863', '#fee0b6', '#f7f7f7', '#d8daeb', '#b2abd2', '#8073ac', '#542788', '#2d004b'],
|
|
50
|
+
|
|
51
|
+
// qualitative
|
|
52
|
+
Set2: ['#66c2a5', '#fc8d62', '#8da0cb', '#e78ac3', '#a6d854', '#ffd92f', '#e5c494', '#b3b3b3'],
|
|
53
|
+
Accent: ['#7fc97f', '#beaed4', '#fdc086', '#ffff99', '#386cb0', '#f0027f', '#bf5b17', '#666666'],
|
|
54
|
+
Set1: ['#e41a1c', '#377eb8', '#4daf4a', '#984ea3', '#ff7f00', '#ffff33', '#a65628', '#f781bf', '#999999'],
|
|
55
|
+
Set3: ['#8dd3c7', '#ffffb3', '#bebada', '#fb8072', '#80b1d3', '#fdb462', '#b3de69', '#fccde5', '#d9d9d9', '#bc80bd', '#ccebc5', '#ffed6f'],
|
|
56
|
+
Dark2: ['#1b9e77', '#d95f02', '#7570b3', '#e7298a', '#66a61e', '#e6ab02', '#a6761d', '#666666'],
|
|
57
|
+
Paired: ['#a6cee3', '#1f78b4', '#b2df8a', '#33a02c', '#fb9a99', '#e31a1c', '#fdbf6f', '#ff7f00', '#cab2d6', '#6a3d9a', '#ffff99', '#b15928'],
|
|
58
|
+
Pastel2: ['#b3e2cd', '#fdcdac', '#cbd5e8', '#f4cae4', '#e6f5c9', '#fff2ae', '#f1e2cc', '#cccccc'],
|
|
59
|
+
Pastel1: ['#fbb4ae', '#b3cde3', '#ccebc5', '#decbe4', '#fed9a6', '#ffffcc', '#e5d8bd', '#fddaec', '#f2f2f2']
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const colorbrewerTypes = Object.keys(colorbrewer);
|
|
63
|
+
const typeMap = new Map(colorbrewerTypes.map((key) => [key.toLowerCase(), key]));
|
|
64
|
+
|
|
65
|
+
// use Proxy to allow case-insensitive access to palettes
|
|
66
|
+
const colorbrewerProxy =
|
|
67
|
+
typeof Proxy === 'function'
|
|
68
|
+
? new Proxy(colorbrewer, {
|
|
69
|
+
get(target, prop) {
|
|
70
|
+
const lower = prop.toLowerCase();
|
|
71
|
+
if (typeMap.has(lower)) {
|
|
72
|
+
return target[typeMap.get(lower)];
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
getOwnPropertyNames() {
|
|
76
|
+
return Object.getOwnPropertyNames(colorbrewerTypes);
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
: colorbrewer;
|
|
80
|
+
|
|
81
|
+
export default colorbrewerProxy;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
X11 color names
|
|
3
|
+
|
|
4
|
+
http://www.w3.org/TR/css3-color/#svg-color
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const w3cx11 = {
|
|
8
|
+
aliceblue: '#f0f8ff',
|
|
9
|
+
antiquewhite: '#faebd7',
|
|
10
|
+
aqua: '#00ffff',
|
|
11
|
+
aquamarine: '#7fffd4',
|
|
12
|
+
azure: '#f0ffff',
|
|
13
|
+
beige: '#f5f5dc',
|
|
14
|
+
bisque: '#ffe4c4',
|
|
15
|
+
black: '#000000',
|
|
16
|
+
blanchedalmond: '#ffebcd',
|
|
17
|
+
blue: '#0000ff',
|
|
18
|
+
blueviolet: '#8a2be2',
|
|
19
|
+
brown: '#a52a2a',
|
|
20
|
+
burlywood: '#deb887',
|
|
21
|
+
cadetblue: '#5f9ea0',
|
|
22
|
+
chartreuse: '#7fff00',
|
|
23
|
+
chocolate: '#d2691e',
|
|
24
|
+
coral: '#ff7f50',
|
|
25
|
+
cornflowerblue: '#6495ed',
|
|
26
|
+
cornsilk: '#fff8dc',
|
|
27
|
+
crimson: '#dc143c',
|
|
28
|
+
cyan: '#00ffff',
|
|
29
|
+
darkblue: '#00008b',
|
|
30
|
+
darkcyan: '#008b8b',
|
|
31
|
+
darkgoldenrod: '#b8860b',
|
|
32
|
+
darkgray: '#a9a9a9',
|
|
33
|
+
darkgreen: '#006400',
|
|
34
|
+
darkgrey: '#a9a9a9',
|
|
35
|
+
darkkhaki: '#bdb76b',
|
|
36
|
+
darkmagenta: '#8b008b',
|
|
37
|
+
darkolivegreen: '#556b2f',
|
|
38
|
+
darkorange: '#ff8c00',
|
|
39
|
+
darkorchid: '#9932cc',
|
|
40
|
+
darkred: '#8b0000',
|
|
41
|
+
darksalmon: '#e9967a',
|
|
42
|
+
darkseagreen: '#8fbc8f',
|
|
43
|
+
darkslateblue: '#483d8b',
|
|
44
|
+
darkslategray: '#2f4f4f',
|
|
45
|
+
darkslategrey: '#2f4f4f',
|
|
46
|
+
darkturquoise: '#00ced1',
|
|
47
|
+
darkviolet: '#9400d3',
|
|
48
|
+
deeppink: '#ff1493',
|
|
49
|
+
deepskyblue: '#00bfff',
|
|
50
|
+
dimgray: '#696969',
|
|
51
|
+
dimgrey: '#696969',
|
|
52
|
+
dodgerblue: '#1e90ff',
|
|
53
|
+
firebrick: '#b22222',
|
|
54
|
+
floralwhite: '#fffaf0',
|
|
55
|
+
forestgreen: '#228b22',
|
|
56
|
+
fuchsia: '#ff00ff',
|
|
57
|
+
gainsboro: '#dcdcdc',
|
|
58
|
+
ghostwhite: '#f8f8ff',
|
|
59
|
+
gold: '#ffd700',
|
|
60
|
+
goldenrod: '#daa520',
|
|
61
|
+
gray: '#808080',
|
|
62
|
+
green: '#008000',
|
|
63
|
+
greenyellow: '#adff2f',
|
|
64
|
+
grey: '#808080',
|
|
65
|
+
honeydew: '#f0fff0',
|
|
66
|
+
hotpink: '#ff69b4',
|
|
67
|
+
indianred: '#cd5c5c',
|
|
68
|
+
indigo: '#4b0082',
|
|
69
|
+
ivory: '#fffff0',
|
|
70
|
+
khaki: '#f0e68c',
|
|
71
|
+
laserlemon: '#ffff54',
|
|
72
|
+
lavender: '#e6e6fa',
|
|
73
|
+
lavenderblush: '#fff0f5',
|
|
74
|
+
lawngreen: '#7cfc00',
|
|
75
|
+
lemonchiffon: '#fffacd',
|
|
76
|
+
lightblue: '#add8e6',
|
|
77
|
+
lightcoral: '#f08080',
|
|
78
|
+
lightcyan: '#e0ffff',
|
|
79
|
+
lightgoldenrod: '#fafad2',
|
|
80
|
+
lightgoldenrodyellow: '#fafad2',
|
|
81
|
+
lightgray: '#d3d3d3',
|
|
82
|
+
lightgreen: '#90ee90',
|
|
83
|
+
lightgrey: '#d3d3d3',
|
|
84
|
+
lightpink: '#ffb6c1',
|
|
85
|
+
lightsalmon: '#ffa07a',
|
|
86
|
+
lightseagreen: '#20b2aa',
|
|
87
|
+
lightskyblue: '#87cefa',
|
|
88
|
+
lightslategray: '#778899',
|
|
89
|
+
lightslategrey: '#778899',
|
|
90
|
+
lightsteelblue: '#b0c4de',
|
|
91
|
+
lightyellow: '#ffffe0',
|
|
92
|
+
lime: '#00ff00',
|
|
93
|
+
limegreen: '#32cd32',
|
|
94
|
+
linen: '#faf0e6',
|
|
95
|
+
magenta: '#ff00ff',
|
|
96
|
+
maroon: '#800000',
|
|
97
|
+
maroon2: '#7f0000',
|
|
98
|
+
maroon3: '#b03060',
|
|
99
|
+
mediumaquamarine: '#66cdaa',
|
|
100
|
+
mediumblue: '#0000cd',
|
|
101
|
+
mediumorchid: '#ba55d3',
|
|
102
|
+
mediumpurple: '#9370db',
|
|
103
|
+
mediumseagreen: '#3cb371',
|
|
104
|
+
mediumslateblue: '#7b68ee',
|
|
105
|
+
mediumspringgreen: '#00fa9a',
|
|
106
|
+
mediumturquoise: '#48d1cc',
|
|
107
|
+
mediumvioletred: '#c71585',
|
|
108
|
+
midnightblue: '#191970',
|
|
109
|
+
mintcream: '#f5fffa',
|
|
110
|
+
mistyrose: '#ffe4e1',
|
|
111
|
+
moccasin: '#ffe4b5',
|
|
112
|
+
navajowhite: '#ffdead',
|
|
113
|
+
navy: '#000080',
|
|
114
|
+
oldlace: '#fdf5e6',
|
|
115
|
+
olive: '#808000',
|
|
116
|
+
olivedrab: '#6b8e23',
|
|
117
|
+
orange: '#ffa500',
|
|
118
|
+
orangered: '#ff4500',
|
|
119
|
+
orchid: '#da70d6',
|
|
120
|
+
palegoldenrod: '#eee8aa',
|
|
121
|
+
palegreen: '#98fb98',
|
|
122
|
+
paleturquoise: '#afeeee',
|
|
123
|
+
palevioletred: '#db7093',
|
|
124
|
+
papayawhip: '#ffefd5',
|
|
125
|
+
peachpuff: '#ffdab9',
|
|
126
|
+
peru: '#cd853f',
|
|
127
|
+
pink: '#ffc0cb',
|
|
128
|
+
plum: '#dda0dd',
|
|
129
|
+
powderblue: '#b0e0e6',
|
|
130
|
+
purple: '#800080',
|
|
131
|
+
purple2: '#7f007f',
|
|
132
|
+
purple3: '#a020f0',
|
|
133
|
+
rebeccapurple: '#663399',
|
|
134
|
+
red: '#ff0000',
|
|
135
|
+
rosybrown: '#bc8f8f',
|
|
136
|
+
royalblue: '#4169e1',
|
|
137
|
+
saddlebrown: '#8b4513',
|
|
138
|
+
salmon: '#fa8072',
|
|
139
|
+
sandybrown: '#f4a460',
|
|
140
|
+
seagreen: '#2e8b57',
|
|
141
|
+
seashell: '#fff5ee',
|
|
142
|
+
sienna: '#a0522d',
|
|
143
|
+
silver: '#c0c0c0',
|
|
144
|
+
skyblue: '#87ceeb',
|
|
145
|
+
slateblue: '#6a5acd',
|
|
146
|
+
slategray: '#708090',
|
|
147
|
+
slategrey: '#708090',
|
|
148
|
+
snow: '#fffafa',
|
|
149
|
+
springgreen: '#00ff7f',
|
|
150
|
+
steelblue: '#4682b4',
|
|
151
|
+
tan: '#d2b48c',
|
|
152
|
+
teal: '#008080',
|
|
153
|
+
thistle: '#d8bfd8',
|
|
154
|
+
tomato: '#ff6347',
|
|
155
|
+
turquoise: '#40e0d0',
|
|
156
|
+
violet: '#ee82ee',
|
|
157
|
+
wheat: '#f5deb3',
|
|
158
|
+
white: '#ffffff',
|
|
159
|
+
whitesmoke: '#f5f5f5',
|
|
160
|
+
yellow: '#ffff00',
|
|
161
|
+
yellowgreen: '#9acd32'
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export default w3cx11;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import Color from '../Color.js';
|
|
2
|
+
import { clip_rgb } from '../utils/index.js';
|
|
3
|
+
|
|
4
|
+
const { pow, sqrt, PI, cos, sin, atan2 } = Math;
|
|
5
|
+
|
|
6
|
+
export default (colors, mode = 'lrgb', weights = null) => {
|
|
7
|
+
const l = colors.length;
|
|
8
|
+
if (!weights) weights = Array.from(new Array(l)).map(() => 1);
|
|
9
|
+
// normalize weights
|
|
10
|
+
const k =
|
|
11
|
+
l /
|
|
12
|
+
weights.reduce(function (a, b) {
|
|
13
|
+
return a + b;
|
|
14
|
+
});
|
|
15
|
+
weights.forEach((w, i) => {
|
|
16
|
+
weights[i] *= k;
|
|
17
|
+
});
|
|
18
|
+
// convert colors to Color objects
|
|
19
|
+
colors = colors.map((c) => new Color(c));
|
|
20
|
+
if (mode === 'lrgb') {
|
|
21
|
+
return _average_lrgb(colors, weights);
|
|
22
|
+
}
|
|
23
|
+
const first = colors.shift();
|
|
24
|
+
const xyz = first.get(mode);
|
|
25
|
+
const cnt = [];
|
|
26
|
+
let dx = 0;
|
|
27
|
+
let dy = 0;
|
|
28
|
+
// initial color
|
|
29
|
+
for (let i = 0; i < xyz.length; i++) {
|
|
30
|
+
xyz[i] = (xyz[i] || 0) * weights[0];
|
|
31
|
+
cnt.push(isNaN(xyz[i]) ? 0 : weights[0]);
|
|
32
|
+
if (mode.charAt(i) === 'h' && !isNaN(xyz[i])) {
|
|
33
|
+
const A = (xyz[i] / 180) * PI;
|
|
34
|
+
dx += cos(A) * weights[0];
|
|
35
|
+
dy += sin(A) * weights[0];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let alpha = first.alpha() * weights[0];
|
|
40
|
+
colors.forEach((c, ci) => {
|
|
41
|
+
const xyz2 = c.get(mode);
|
|
42
|
+
alpha += c.alpha() * weights[ci + 1];
|
|
43
|
+
for (let i = 0; i < xyz.length; i++) {
|
|
44
|
+
if (!isNaN(xyz2[i])) {
|
|
45
|
+
cnt[i] += weights[ci + 1];
|
|
46
|
+
if (mode.charAt(i) === 'h') {
|
|
47
|
+
const A = (xyz2[i] / 180) * PI;
|
|
48
|
+
dx += cos(A) * weights[ci + 1];
|
|
49
|
+
dy += sin(A) * weights[ci + 1];
|
|
50
|
+
} else {
|
|
51
|
+
xyz[i] += xyz2[i] * weights[ci + 1];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
for (let i = 0; i < xyz.length; i++) {
|
|
58
|
+
if (mode.charAt(i) === 'h') {
|
|
59
|
+
let A = (atan2(dy / cnt[i], dx / cnt[i]) / PI) * 180;
|
|
60
|
+
while (A < 0) A += 360;
|
|
61
|
+
while (A >= 360) A -= 360;
|
|
62
|
+
xyz[i] = A;
|
|
63
|
+
} else {
|
|
64
|
+
xyz[i] = xyz[i] / cnt[i];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
alpha /= l;
|
|
68
|
+
return new Color(xyz, mode).alpha(alpha > 0.99999 ? 1 : alpha, true);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const _average_lrgb = (colors, weights) => {
|
|
72
|
+
const l = colors.length;
|
|
73
|
+
const xyz = [0, 0, 0, 0];
|
|
74
|
+
for (let i = 0; i < colors.length; i++) {
|
|
75
|
+
const col = colors[i];
|
|
76
|
+
const f = weights[i] / l;
|
|
77
|
+
const rgb = col._rgb;
|
|
78
|
+
xyz[0] += pow(rgb[0], 2) * f;
|
|
79
|
+
xyz[1] += pow(rgb[1], 2) * f;
|
|
80
|
+
xyz[2] += pow(rgb[2], 2) * f;
|
|
81
|
+
xyz[3] += rgb[3] * f;
|
|
82
|
+
}
|
|
83
|
+
xyz[0] = sqrt(xyz[0]);
|
|
84
|
+
xyz[1] = sqrt(xyz[1]);
|
|
85
|
+
xyz[2] = sqrt(xyz[2]);
|
|
86
|
+
if (xyz[3] > 0.9999999) xyz[3] = 1;
|
|
87
|
+
return new Color(clip_rgb(xyz));
|
|
88
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
//
|
|
2
|
+
// interpolates between a set of colors uzing a bezier spline
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
// @requires utils lab
|
|
6
|
+
import Color from '../Color.js';
|
|
7
|
+
import '../io/lab/index.js';
|
|
8
|
+
import scale from './scale.js';
|
|
9
|
+
|
|
10
|
+
// nth row of the pascal triangle
|
|
11
|
+
const binom_row = function (n) {
|
|
12
|
+
let row = [1, 1];
|
|
13
|
+
for (let i = 1; i < n; i++) {
|
|
14
|
+
let newrow = [1];
|
|
15
|
+
for (let j = 1; j <= row.length; j++) {
|
|
16
|
+
newrow[j] = (row[j] || 0) + row[j - 1];
|
|
17
|
+
}
|
|
18
|
+
row = newrow;
|
|
19
|
+
}
|
|
20
|
+
return row;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const bezier = function (colors) {
|
|
24
|
+
let I, lab0, lab1, lab2;
|
|
25
|
+
colors = colors.map((c) => new Color(c));
|
|
26
|
+
if (colors.length === 2) {
|
|
27
|
+
// linear interpolation
|
|
28
|
+
[lab0, lab1] = colors.map((c) => c.lab());
|
|
29
|
+
I = function (t) {
|
|
30
|
+
const lab = [0, 1, 2].map((i) => lab0[i] + t * (lab1[i] - lab0[i]));
|
|
31
|
+
return new Color(lab, 'lab');
|
|
32
|
+
};
|
|
33
|
+
} else if (colors.length === 3) {
|
|
34
|
+
// quadratic bezier interpolation
|
|
35
|
+
[lab0, lab1, lab2] = colors.map((c) => c.lab());
|
|
36
|
+
I = function (t) {
|
|
37
|
+
const lab = [0, 1, 2].map(
|
|
38
|
+
(i) =>
|
|
39
|
+
(1 - t) * (1 - t) * lab0[i] +
|
|
40
|
+
2 * (1 - t) * t * lab1[i] +
|
|
41
|
+
t * t * lab2[i]
|
|
42
|
+
);
|
|
43
|
+
return new Color(lab, 'lab');
|
|
44
|
+
};
|
|
45
|
+
} else if (colors.length === 4) {
|
|
46
|
+
// cubic bezier interpolation
|
|
47
|
+
let lab3;
|
|
48
|
+
[lab0, lab1, lab2, lab3] = colors.map((c) => c.lab());
|
|
49
|
+
I = function (t) {
|
|
50
|
+
const lab = [0, 1, 2].map(
|
|
51
|
+
(i) =>
|
|
52
|
+
(1 - t) * (1 - t) * (1 - t) * lab0[i] +
|
|
53
|
+
3 * (1 - t) * (1 - t) * t * lab1[i] +
|
|
54
|
+
3 * (1 - t) * t * t * lab2[i] +
|
|
55
|
+
t * t * t * lab3[i]
|
|
56
|
+
);
|
|
57
|
+
return new Color(lab, 'lab');
|
|
58
|
+
};
|
|
59
|
+
} else if (colors.length >= 5) {
|
|
60
|
+
// general case (degree n bezier)
|
|
61
|
+
let labs, row, n;
|
|
62
|
+
labs = colors.map((c) => c.lab());
|
|
63
|
+
n = colors.length - 1;
|
|
64
|
+
row = binom_row(n);
|
|
65
|
+
I = function (t) {
|
|
66
|
+
const u = 1 - t;
|
|
67
|
+
const lab = [0, 1, 2].map((i) =>
|
|
68
|
+
labs.reduce(
|
|
69
|
+
(sum, el, j) =>
|
|
70
|
+
sum + row[j] * u ** (n - j) * t ** j * el[i],
|
|
71
|
+
0
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
return new Color(lab, 'lab');
|
|
75
|
+
};
|
|
76
|
+
} else {
|
|
77
|
+
throw new RangeError('No point in running bezier with only one color.');
|
|
78
|
+
}
|
|
79
|
+
return I;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export default (colors) => {
|
|
83
|
+
const f = bezier(colors);
|
|
84
|
+
f.scale = () => scale(f);
|
|
85
|
+
return f;
|
|
86
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* interpolates between a set of colors uzing a bezier spline
|
|
3
|
+
* blend mode formulas taken from https://web.archive.org/web/20180110014946/http://www.venture-ware.com/kevin/coding/lets-learn-math-photoshop-blend-modes/
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import '../io/rgb/index.js';
|
|
7
|
+
import chroma from '../chroma.js';
|
|
8
|
+
|
|
9
|
+
const blend = (bottom, top, mode) => {
|
|
10
|
+
if (!blend[mode]) {
|
|
11
|
+
throw new Error('unknown blend mode ' + mode);
|
|
12
|
+
}
|
|
13
|
+
return blend[mode](bottom, top);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const blend_f = (f) => (bottom, top) => {
|
|
17
|
+
const c0 = chroma(top).rgb();
|
|
18
|
+
const c1 = chroma(bottom).rgb();
|
|
19
|
+
return chroma.rgb(f(c0, c1));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const each = (f) => (c0, c1) => {
|
|
23
|
+
const out = [];
|
|
24
|
+
out[0] = f(c0[0], c1[0]);
|
|
25
|
+
out[1] = f(c0[1], c1[1]);
|
|
26
|
+
out[2] = f(c0[2], c1[2]);
|
|
27
|
+
return out;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const normal = (a) => a;
|
|
31
|
+
const multiply = (a, b) => (a * b) / 255;
|
|
32
|
+
const darken = (a, b) => (a > b ? b : a);
|
|
33
|
+
const lighten = (a, b) => (a > b ? a : b);
|
|
34
|
+
const screen = (a, b) => 255 * (1 - (1 - a / 255) * (1 - b / 255));
|
|
35
|
+
const overlay = (a, b) =>
|
|
36
|
+
b < 128 ? (2 * a * b) / 255 : 255 * (1 - 2 * (1 - a / 255) * (1 - b / 255));
|
|
37
|
+
const burn = (a, b) => 255 * (1 - (1 - b / 255) / (a / 255));
|
|
38
|
+
const dodge = (a, b) => {
|
|
39
|
+
if (a === 255) return 255;
|
|
40
|
+
a = (255 * (b / 255)) / (1 - a / 255);
|
|
41
|
+
return a > 255 ? 255 : a;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// # add = (a,b) ->
|
|
45
|
+
// # if (a + b > 255) then 255 else a + b
|
|
46
|
+
|
|
47
|
+
blend.normal = blend_f(each(normal));
|
|
48
|
+
blend.multiply = blend_f(each(multiply));
|
|
49
|
+
blend.screen = blend_f(each(screen));
|
|
50
|
+
blend.overlay = blend_f(each(overlay));
|
|
51
|
+
blend.darken = blend_f(each(darken));
|
|
52
|
+
blend.lighten = blend_f(each(lighten));
|
|
53
|
+
blend.dodge = blend_f(each(dodge));
|
|
54
|
+
blend.burn = blend_f(each(burn));
|
|
55
|
+
// blend.add = blend_f(each(add));
|
|
56
|
+
|
|
57
|
+
export default blend;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// cubehelix interpolation
|
|
2
|
+
// based on D.A. Green "A colour scheme for the display of astronomical intensity images"
|
|
3
|
+
// http://astron-soc.in/bulletin/11June/289392011.pdf
|
|
4
|
+
import { type, clip_rgb, TWOPI } from '../utils/index.js';
|
|
5
|
+
import chroma from '../chroma.js';
|
|
6
|
+
const { pow, sin, cos } = Math;
|
|
7
|
+
|
|
8
|
+
export default function (
|
|
9
|
+
start = 300,
|
|
10
|
+
rotations = -1.5,
|
|
11
|
+
hue = 1,
|
|
12
|
+
gamma = 1,
|
|
13
|
+
lightness = [0, 1]
|
|
14
|
+
) {
|
|
15
|
+
let dh = 0,
|
|
16
|
+
dl;
|
|
17
|
+
if (type(lightness) === 'array') {
|
|
18
|
+
dl = lightness[1] - lightness[0];
|
|
19
|
+
} else {
|
|
20
|
+
dl = 0;
|
|
21
|
+
lightness = [lightness, lightness];
|
|
22
|
+
}
|
|
23
|
+
const f = function (fract) {
|
|
24
|
+
const a = TWOPI * ((start + 120) / 360 + rotations * fract);
|
|
25
|
+
const l = pow(lightness[0] + dl * fract, gamma);
|
|
26
|
+
const h = dh !== 0 ? hue[0] + fract * dh : hue;
|
|
27
|
+
const amp = (h * l * (1 - l)) / 2;
|
|
28
|
+
const cos_a = cos(a);
|
|
29
|
+
const sin_a = sin(a);
|
|
30
|
+
const r = l + amp * (-0.14861 * cos_a + 1.78277 * sin_a);
|
|
31
|
+
const g = l + amp * (-0.29227 * cos_a - 0.90649 * sin_a);
|
|
32
|
+
const b = l + amp * (+1.97294 * cos_a);
|
|
33
|
+
return chroma(clip_rgb([r * 255, g * 255, b * 255, 1]));
|
|
34
|
+
};
|
|
35
|
+
f.start = function (s) {
|
|
36
|
+
if (s == null) {
|
|
37
|
+
return start;
|
|
38
|
+
}
|
|
39
|
+
start = s;
|
|
40
|
+
return f;
|
|
41
|
+
};
|
|
42
|
+
f.rotations = function (r) {
|
|
43
|
+
if (r == null) {
|
|
44
|
+
return rotations;
|
|
45
|
+
}
|
|
46
|
+
rotations = r;
|
|
47
|
+
return f;
|
|
48
|
+
};
|
|
49
|
+
f.gamma = function (g) {
|
|
50
|
+
if (g == null) {
|
|
51
|
+
return gamma;
|
|
52
|
+
}
|
|
53
|
+
gamma = g;
|
|
54
|
+
return f;
|
|
55
|
+
};
|
|
56
|
+
f.hue = function (h) {
|
|
57
|
+
if (h == null) {
|
|
58
|
+
return hue;
|
|
59
|
+
}
|
|
60
|
+
hue = h;
|
|
61
|
+
if (type(hue) === 'array') {
|
|
62
|
+
dh = hue[1] - hue[0];
|
|
63
|
+
if (dh === 0) {
|
|
64
|
+
hue = hue[1];
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
dh = 0;
|
|
68
|
+
}
|
|
69
|
+
return f;
|
|
70
|
+
};
|
|
71
|
+
f.lightness = function (h) {
|
|
72
|
+
if (h == null) {
|
|
73
|
+
return lightness;
|
|
74
|
+
}
|
|
75
|
+
if (type(h) === 'array') {
|
|
76
|
+
lightness = h;
|
|
77
|
+
dl = h[1] - h[0];
|
|
78
|
+
} else {
|
|
79
|
+
lightness = [h, h];
|
|
80
|
+
dl = 0;
|
|
81
|
+
}
|
|
82
|
+
return f;
|
|
83
|
+
};
|
|
84
|
+
f.scale = () => chroma.scale(f);
|
|
85
|
+
f.hue(hue);
|
|
86
|
+
return f;
|
|
87
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Color from '../Color.js';
|
|
2
|
+
import { type } from '../utils/index.js';
|
|
3
|
+
import interpolator from '../interpolator/index.js';
|
|
4
|
+
|
|
5
|
+
export default (col1, col2, f = 0.5, ...rest) => {
|
|
6
|
+
let mode = rest[0] || 'lrgb';
|
|
7
|
+
if (!interpolator[mode] && !rest.length) {
|
|
8
|
+
// fall back to the first supported mode
|
|
9
|
+
mode = Object.keys(interpolator)[0];
|
|
10
|
+
}
|
|
11
|
+
if (!interpolator[mode]) {
|
|
12
|
+
throw new Error(`interpolation mode ${mode} is not defined`);
|
|
13
|
+
}
|
|
14
|
+
if (type(col1) !== 'object') col1 = new Color(col1);
|
|
15
|
+
if (type(col2) !== 'object') col2 = new Color(col2);
|
|
16
|
+
return interpolator[mode](col1, col2, f).alpha(
|
|
17
|
+
col1.alpha() + f * (col2.alpha() - col1.alpha())
|
|
18
|
+
);
|
|
19
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import Color from '../Color.js';
|
|
2
|
+
const digits = '0123456789abcdef';
|
|
3
|
+
|
|
4
|
+
const { floor, random } = Math;
|
|
5
|
+
|
|
6
|
+
export default () => {
|
|
7
|
+
let code = '#';
|
|
8
|
+
for (let i = 0; i < 6; i++) {
|
|
9
|
+
code += digits.charAt(floor(random() * 16));
|
|
10
|
+
}
|
|
11
|
+
return new Color(code, 'hex');
|
|
12
|
+
};
|