-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviridis.js
More file actions
31 lines (29 loc) · 1.02 KB
/
Copy pathviridis.js
File metadata and controls
31 lines (29 loc) · 1.02 KB
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-entry viridis lookup table. Generated by linear interpolation between
// the same 5 stops the Python build uses (renderer.py:cmap_viridis), so the
// browser demo matches the desktop demo byte-for-byte on uniform inputs.
//
// Stops: [68,1,84] [59,82,139] [33,144,141] [94,201,98] [253,231,37]
const _VIRIDIS_STOPS = [
[ 68, 1, 84],
[ 59, 82, 139],
[ 33, 144, 141],
[ 94, 201, 98],
[253, 231, 37],
];
function _buildViridisLUT(n) {
const out = new Uint8Array(n * 3);
for (let i = 0; i < n; i++) {
const t = i / (n - 1);
const idx = t * (_VIRIDIS_STOPS.length - 1);
const lo = Math.floor(idx);
const hi = Math.min(lo + 1, _VIRIDIS_STOPS.length - 1);
const frac = idx - lo;
const a = _VIRIDIS_STOPS[lo];
const b = _VIRIDIS_STOPS[hi];
out[i * 3 + 0] = Math.round(a[0] * (1 - frac) + b[0] * frac);
out[i * 3 + 1] = Math.round(a[1] * (1 - frac) + b[1] * frac);
out[i * 3 + 2] = Math.round(a[2] * (1 - frac) + b[2] * frac);
}
return out;
}
const VIRIDIS_LUT = _buildViridisLUT(64);