PageSourceSearch

https://www.cmetracker.ai/js/fluid-palette.js

js cmetracker.ai collected 2026-10-05 11:56:11 UTC 2,377 bytes, 44 lines download raw bytes

1// Colour scales for the Fluid layer, matching the NOAA/Enlil convention people
2// already know: speed 200 → 1400 km/s and r²-scaled density 0 → 60 cm⁻³ on a
3// jet-style ramp (dark blue → blue → cyan → green → yellow → orange → red).
4// Shared by the map raster (js/render.js) and the HTML legend (js/fluid.js).
5import { DEFAULTS } from "./huxt.js";
6
7const SPEED_STOPS = [
8  [0.00, [10, 20, 90]], [0.12, [20, 60, 200]], [0.28, [40, 170, 235]], [0.42, [60, 215, 170]],
9  [0.56, [140, 230, 70]], [0.70, [245, 225, 50]], [0.84, [250, 140, 30]], [1.00, [200, 25, 25]],
10];
11// Density reaches red by ~45 cm⁻³ and goes white-hot above ~55, as Enlil's scale
12// does, so a compressed sheath (30–50) reads as the event it is rather than as
13// "warm". Quiet wind (3–8) stays in the blues.
14const DENSITY_STOPS = [
15  [0.00, [10, 20, 90]], [0.10, [20, 60, 200]], [0.22, [40, 170, 235]], [0.34, [60, 215, 170]],
16  [0.46, [140, 230, 70]], [0.58, [245, 225, 50]], [0.68, [250, 140, 30]], [0.78, [215, 30, 30]],
17  [0.90, [255, 110, 170]], [1.00, [255, 245, 245]],
18];
19export const SPEED_RANGE = [200, 1400], DENSITY_RANGE = [0, 60];
20const stopsFor = (mode) => (mode === "density" ? DENSITY_STOPS : SPEED_STOPS);
21
22export function rampColor(u, mode = "speed") {
23  const STOPS = stopsFor(mode);
24  u = Math.max(0, Math.min(1, u));
25  let k = 1; while (k < STOPS.length - 1 && STOPS[k][0] < u) k++;
26  const [u0, c0] = STOPS[k - 1], [u1, c1] = STOPS[k], f = (u - u0) / (u1 - u0);
27  return c0.map((a, i) => Math.round(a + (c1[i] - a) * f));
28}
29
30/** 256-entry RGBA lookup indexed by the packed byte for a mode. */
31export function buildLut(mode) {
32  const lut = new Uint32Array(256);
33  const le = new Uint8Array(new Uint32Array([1]).buffer)[0] === 1;
34  for (let b = 0; b < 256; b++) {
35    const value = mode === "density" ? b / DEFAULTS.nQuant : DEFAULTS.vFloor + b * DEFAULTS.vQuant;
36    const [lo, hi] = mode === "density" ? DENSITY_RANGE : SPEED_RANGE;
37    const [r, g, bl] = rampColor((value - lo) / (hi - lo), mode);
38    lut[b] = le ? ((255 << 24) | (bl << 16) | (g << 8) | r) >>> 0 : ((r << 24) | (g << 16) | (bl << 8) | 255) >>> 0;
39  }
40  return lut;
41}
42
43/** CSS gradient string for the legend bar of a mode. */
44export const cssRamp = (mode = "speed") => `linear-gradient(90deg, ${stopsFor(mode).map(([u, c]) => `rgb(${c.join(",")}) ${Math.round(u * 100)}%`).join(", ")})`;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.