@alexpeng/dsh-custom-plugin 0.10.0 → 0.11.0
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.
- package/CHANGELOG.md +43 -0
- package/README.i18n.yaml +2 -2
- package/README.md +2 -2
- package/README.zh.md +2 -2
- package/lib/client.js +807 -5
- package/lib/client.js.map +1 -1
- package/lib/index.js +2 -0
- package/lib/types/client/bg-ascii.d.ts +9 -1
- package/lib/types/client/bg-field.d.ts +3 -1
- package/lib/types/client/bg-jelly.d.ts +53 -0
- package/lib/types/client/bg-whale.d.ts +56 -0
- package/lib/types/protocol.d.ts +1 -1
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -48,6 +48,8 @@ window.__ModuleLoader__.load({
|
|
|
48
48
|
"flow",
|
|
49
49
|
"rain",
|
|
50
50
|
"ocean",
|
|
51
|
+
"whale",
|
|
52
|
+
"jelly",
|
|
51
53
|
"starfield",
|
|
52
54
|
"ripple",
|
|
53
55
|
"static"
|
|
@@ -788,7 +790,9 @@ window.__ModuleLoader__.load({
|
|
|
788
790
|
//#region src/client/bg-field.ts
|
|
789
791
|
/** Glyphs a piece may place through the overlay buffer. Index 0 is "none";
|
|
790
792
|
* 1–8 are single-cell direction marks for the small fish, 9–13 are the body,
|
|
791
|
-
* edge, head and tail cells of a koi
|
|
793
|
+
* edge, head and tail cells of a koi, 14–19 are the punctuation the `whale`
|
|
794
|
+
* piece needs for its spout and bubbles. Append-only: existing slots are
|
|
795
|
+
* persisted in no state, but the ocean piece indexes them by number. */
|
|
792
796
|
const OVERLAY_GLYPHS = [
|
|
793
797
|
"",
|
|
794
798
|
">",
|
|
@@ -803,7 +807,13 @@ window.__ModuleLoader__.load({
|
|
|
803
807
|
"%",
|
|
804
808
|
"@",
|
|
805
809
|
"*",
|
|
806
|
-
"o"
|
|
810
|
+
"o",
|
|
811
|
+
"_",
|
|
812
|
+
"-",
|
|
813
|
+
".",
|
|
814
|
+
"'",
|
|
815
|
+
"(",
|
|
816
|
+
")"
|
|
807
817
|
];
|
|
808
818
|
/** Lowest field value the `flow` / `static` piece may emit, as a fraction of
|
|
809
819
|
* the ramp. 0.45 keeps the darkest cell around the middle of the ramp instead
|
|
@@ -1271,7 +1281,7 @@ window.__ModuleLoader__.load({
|
|
|
1271
1281
|
const KOI_MIN = .5;
|
|
1272
1282
|
const KOI_MAX = 2.2;
|
|
1273
1283
|
/** A click is felt inside this radius (cells). */
|
|
1274
|
-
const STARTLE_RADIUS = 9;
|
|
1284
|
+
const STARTLE_RADIUS$2 = 9;
|
|
1275
1285
|
/** The pointer pushes fish away inside this radius (cells). */
|
|
1276
1286
|
const CROWD_RADIUS = 6;
|
|
1277
1287
|
/** A drag drops one small dipole ring per this much time and travel, so the
|
|
@@ -1602,8 +1612,8 @@ window.__ModuleLoader__.load({
|
|
|
1602
1612
|
const dx = f.x - input.pulseX;
|
|
1603
1613
|
const dy = f.y - input.pulseY;
|
|
1604
1614
|
const d = Math.sqrt(dx * dx + dy * dy);
|
|
1605
|
-
if (d >= STARTLE_RADIUS || d < .001) continue;
|
|
1606
|
-
const push = (1 - d / STARTLE_RADIUS) * (f.kind === 0 ? 17 : 9);
|
|
1615
|
+
if (d >= STARTLE_RADIUS$2 || d < .001) continue;
|
|
1616
|
+
const push = (1 - d / STARTLE_RADIUS$2) * (f.kind === 0 ? 17 : 9);
|
|
1607
1617
|
f.vx += dx / d * push;
|
|
1608
1618
|
f.vy += dy / d * push;
|
|
1609
1619
|
f.fear = 1;
|
|
@@ -1775,6 +1785,722 @@ window.__ModuleLoader__.load({
|
|
|
1775
1785
|
pulseX: 0,
|
|
1776
1786
|
pulseY: 0
|
|
1777
1787
|
};
|
|
1788
|
+
//#endregion
|
|
1789
|
+
//#region src/client/bg-whale.ts
|
|
1790
|
+
/**
|
|
1791
|
+
* `whale`: a large ASCII whale that crosses the page, with a spout and bubbles.
|
|
1792
|
+
*
|
|
1793
|
+
* The scene has three layers:
|
|
1794
|
+
* 1. a very faint sea — drifting value-noise water plus two long swell lines
|
|
1795
|
+
* that roll across the lower and middle bands of the page;
|
|
1796
|
+
* 2. one whale, rasterised once from a hand-tuned outline into a cell mask
|
|
1797
|
+
* (a shader-like silhouette with a character ramp inside: dark rim, mid
|
|
1798
|
+
* spine, light belly, a hole for the eye and a darker mouth line), swimming
|
|
1799
|
+
* leftwards with a slow bob and a tail that beats;
|
|
1800
|
+
* 3. particles — a spout above the blowhole every few seconds, a bubble trail
|
|
1801
|
+
* behind the tail, and a few bubbles where the user clicks.
|
|
1802
|
+
*
|
|
1803
|
+
* Every cell of the whale is marked in `emphasis`, so the calm zone may thin it
|
|
1804
|
+
* but never erase it: a recognisable picture is the whole point of the preset,
|
|
1805
|
+
* and the 0.15 floor would leave a ghost. The sea and the automatic bubbles
|
|
1806
|
+
* are *not* marked — only the whale and the bubbles the user just caused keep
|
|
1807
|
+
* the `EFFECT_FOCUS_FLOOR` strength inside the reading column.
|
|
1808
|
+
*
|
|
1809
|
+
* The pointer is felt, not obeyed: inside a 14-cell radius the whale speeds up
|
|
1810
|
+
* a little and banks away vertically; a click inside 18 cells startles it (a
|
|
1811
|
+
* short burst of speed plus a spout). Nothing here allocates per frame — the
|
|
1812
|
+
* mask is module-level, the particle pool is fixed, the per-column swell scratch
|
|
1813
|
+
* grows only with the grid.
|
|
1814
|
+
* @module @alexpeng/dsh-custom-plugin/client/bg-whale
|
|
1815
|
+
*/
|
|
1816
|
+
/** Overlay slots (see `OVERLAY_GLYPHS` in bg-field). */
|
|
1817
|
+
const GLYPH_BUBBLE$1 = 13;
|
|
1818
|
+
const GLYPH_TICK = 17;
|
|
1819
|
+
const GLYPH_DOT$1 = 16;
|
|
1820
|
+
/** Cells/s at the preset's speed 1. A whale should read as slow; the boost
|
|
1821
|
+
* from the pointer is what makes it feel alive. */
|
|
1822
|
+
const WHALE_SPEED = 2.1;
|
|
1823
|
+
/** Vertical bob amplitude in rows and its angular rate. */
|
|
1824
|
+
const WHALE_BOB = 1.2;
|
|
1825
|
+
const WHALE_BOB_RATE = .42;
|
|
1826
|
+
/** Tail beat: cells of travel at the tip and its rate. */
|
|
1827
|
+
const WHALE_TAIL_SWING = 2;
|
|
1828
|
+
const WHALE_TAIL_RATE = 2.6;
|
|
1829
|
+
/** Pointer radii, in cells. */
|
|
1830
|
+
const NOTICE_RADIUS$1 = 14;
|
|
1831
|
+
const STARTLE_RADIUS$1 = 18;
|
|
1832
|
+
/** Spout schedule: the first one lands 2 s after mount, then every 8–13 s. */
|
|
1833
|
+
const FIRST_BLOW = 2;
|
|
1834
|
+
const BLOW_MIN = 8;
|
|
1835
|
+
const BLOW_MAX = 13;
|
|
1836
|
+
const SPRAY_COUNT = 20;
|
|
1837
|
+
/** Spout launch speed and gravity, rows/s and rows/s². A spout has to climb a
|
|
1838
|
+
* few rows to read as water rather than as a spark above the head. */
|
|
1839
|
+
const SPRAY_LAUNCH = 8;
|
|
1840
|
+
const SPRAY_LIFT = 3;
|
|
1841
|
+
const SPRAY_GRAVITY = 6.5;
|
|
1842
|
+
/** Bubble trail behind the tail, one particle per this many seconds. */
|
|
1843
|
+
const TRAIL_INTERVAL = 1.1;
|
|
1844
|
+
const TRAIL_COUNT = 1;
|
|
1845
|
+
/** Fixed particle pool: a spout is 9, a click adds 4, the trail adds 1 at a
|
|
1846
|
+
* time, so 64 slots outlive any realistic burst even with a long life. */
|
|
1847
|
+
const PARTICLE_MAX = 64;
|
|
1848
|
+
/** Whale outline in mask coordinates (x right, y down), head at the left.
|
|
1849
|
+
* Hand-tuned: blunt head, long back, narrow peduncle, two flukes. */
|
|
1850
|
+
const BODY = [
|
|
1851
|
+
[1.2, 4],
|
|
1852
|
+
[2, 2.6],
|
|
1853
|
+
[4, 1.6],
|
|
1854
|
+
[8, .9],
|
|
1855
|
+
[15, .6],
|
|
1856
|
+
[24, .8],
|
|
1857
|
+
[31, 1.5],
|
|
1858
|
+
[35, 2.3],
|
|
1859
|
+
[37.2, 2.9],
|
|
1860
|
+
[44.5, .3],
|
|
1861
|
+
[46.5, .7],
|
|
1862
|
+
[42.2, 3.4],
|
|
1863
|
+
[38.4, 4.2],
|
|
1864
|
+
[46.5, 8],
|
|
1865
|
+
[43.8, 8.9],
|
|
1866
|
+
[37, 5.4],
|
|
1867
|
+
[34, 6.1],
|
|
1868
|
+
[28, 7.3],
|
|
1869
|
+
[20, 8.3],
|
|
1870
|
+
[12, 8.1],
|
|
1871
|
+
[7, 7.3],
|
|
1872
|
+
[3, 6.4],
|
|
1873
|
+
[1, 5.4]
|
|
1874
|
+
];
|
|
1875
|
+
/** Pectoral fin, a separate polygon so its rim is outlined too. */
|
|
1876
|
+
const FIN = [
|
|
1877
|
+
[14.5, 7.4],
|
|
1878
|
+
[18.5, 11],
|
|
1879
|
+
[25, 8]
|
|
1880
|
+
];
|
|
1881
|
+
/** The eye is a hole in the silhouette; the sea behind it shows through. It is
|
|
1882
|
+
* deliberately wider than it is tall (2×2 cells on the shipped grid) and sits
|
|
1883
|
+
* inside a darker ring: a one-cell hole reads as a ramp gap, not as an eye. */
|
|
1884
|
+
const EYE = {
|
|
1885
|
+
x: 6.6,
|
|
1886
|
+
y: 3.4,
|
|
1887
|
+
rx: 1.25,
|
|
1888
|
+
ry: 1.15,
|
|
1889
|
+
ringRx: 2.35,
|
|
1890
|
+
ringRy: 2
|
|
1891
|
+
};
|
|
1892
|
+
/** Mouth: a short gap just above the lower rim, drawn as a hole (level 0 in the
|
|
1893
|
+
* paint loop) so it reads as a light smile against the dark body instead of a
|
|
1894
|
+
* ramp band that blends into the belly. */
|
|
1895
|
+
const MOUTH = [[1.8, 6.1], [7, 7.15]];
|
|
1896
|
+
const MOUTH_WIDTH = .5;
|
|
1897
|
+
/** Cells of the body that belong to the tail, 0..1, for the beat offset. */
|
|
1898
|
+
function tailWeight(dx) {
|
|
1899
|
+
if (dx < 36) return 0;
|
|
1900
|
+
const t = (dx - 36) / 9;
|
|
1901
|
+
return t > 1 ? 1 : t;
|
|
1902
|
+
}
|
|
1903
|
+
function inside(poly, x, y) {
|
|
1904
|
+
let hit = false;
|
|
1905
|
+
for (let i = 0, j = poly.length - 1; i < poly.length; j = i++) {
|
|
1906
|
+
const [xi, yi] = poly[i];
|
|
1907
|
+
const [xj, yj] = poly[j];
|
|
1908
|
+
if (yi > y !== yj > y && x < (xj - xi) * (y - yi) / (yj - yi) + xi) hit = !hit;
|
|
1909
|
+
}
|
|
1910
|
+
return hit;
|
|
1911
|
+
}
|
|
1912
|
+
function distSegment(px, py, ax, ay, bx, by) {
|
|
1913
|
+
const vx = bx - ax;
|
|
1914
|
+
const vy = by - ay;
|
|
1915
|
+
const wx = px - ax;
|
|
1916
|
+
const wy = py - ay;
|
|
1917
|
+
const len2 = vx * vx + vy * vy;
|
|
1918
|
+
let t = len2 > 0 ? (wx * vx + wy * vy) / len2 : 0;
|
|
1919
|
+
t = t < 0 ? 0 : t > 1 ? 1 : t;
|
|
1920
|
+
const dx = px - (ax + vx * t);
|
|
1921
|
+
const dy = py - (ay + vy * t);
|
|
1922
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
1923
|
+
}
|
|
1924
|
+
function mouthDistance(x, y) {
|
|
1925
|
+
let best = Number.POSITIVE_INFINITY;
|
|
1926
|
+
for (let i = 0; i < MOUTH.length - 1; i++) {
|
|
1927
|
+
const d = distSegment(x, y, MOUTH[i][0], MOUTH[i][1], MOUTH[i + 1][0], MOUTH[i + 1][1]);
|
|
1928
|
+
if (d < best) best = d;
|
|
1929
|
+
}
|
|
1930
|
+
return best;
|
|
1931
|
+
}
|
|
1932
|
+
/**
|
|
1933
|
+
* Rasterise the whale outline into cells. Runs once at module load: the rim is
|
|
1934
|
+
* one step darker than the interior (and the interior darkens toward the
|
|
1935
|
+
* spine), which is what draws the silhouette through the ramp alone, so a
|
|
1936
|
+
* ~260-cell whale costs one blit per cell and no overlay pass at all.
|
|
1937
|
+
*/
|
|
1938
|
+
function buildWhaleCells() {
|
|
1939
|
+
const cells = [];
|
|
1940
|
+
for (let row = 0; row < 12; row++) for (let col = 0; col < 50; col++) {
|
|
1941
|
+
const x = col + .5;
|
|
1942
|
+
const y = row + .5;
|
|
1943
|
+
const body = inside(BODY, x, y);
|
|
1944
|
+
const fin = inside(FIN, x, y);
|
|
1945
|
+
if (!body && !fin) continue;
|
|
1946
|
+
const ex = (x - EYE.x) / EYE.rx;
|
|
1947
|
+
const ey = (y - EYE.y) / EYE.ry;
|
|
1948
|
+
if (ex * ex + ey * ey < 1) {
|
|
1949
|
+
cells.push({
|
|
1950
|
+
dx: col,
|
|
1951
|
+
dy: row,
|
|
1952
|
+
level: 0,
|
|
1953
|
+
hole: 1,
|
|
1954
|
+
wag: 0
|
|
1955
|
+
});
|
|
1956
|
+
continue;
|
|
1957
|
+
}
|
|
1958
|
+
if (!fin && mouthDistance(x, y) < MOUTH_WIDTH) {
|
|
1959
|
+
cells.push({
|
|
1960
|
+
dx: col,
|
|
1961
|
+
dy: row,
|
|
1962
|
+
level: 0,
|
|
1963
|
+
hole: 2,
|
|
1964
|
+
wag: tailWeight(col)
|
|
1965
|
+
});
|
|
1966
|
+
continue;
|
|
1967
|
+
}
|
|
1968
|
+
let rim = false;
|
|
1969
|
+
for (let oy = -1; oy <= 1 && !rim; oy++) for (let ox = -1; ox <= 1; ox++) {
|
|
1970
|
+
if (ox === 0 && oy === 0) continue;
|
|
1971
|
+
if (!inside(BODY, x + ox, y + oy) && !inside(FIN, x + ox, y + oy)) {
|
|
1972
|
+
rim = true;
|
|
1973
|
+
break;
|
|
1974
|
+
}
|
|
1975
|
+
}
|
|
1976
|
+
let level;
|
|
1977
|
+
if (rim) level = 9;
|
|
1978
|
+
else if (fin) level = 6;
|
|
1979
|
+
else {
|
|
1980
|
+
const depth = 1 - Math.min(1, Math.abs(y - 2.2) / 4);
|
|
1981
|
+
level = depth > .7 ? 8 : depth > .45 ? 7 : depth > .2 ? 6 : 5;
|
|
1982
|
+
if (hash2(col * 7 + 3, row * 11 + 5) > .82) level -= 1;
|
|
1983
|
+
}
|
|
1984
|
+
const rx = (x - EYE.x) / EYE.ringRx;
|
|
1985
|
+
const ry = (y - EYE.y) / EYE.ringRy;
|
|
1986
|
+
if (!rim && rx * rx + ry * ry < 1) level = 9;
|
|
1987
|
+
cells.push({
|
|
1988
|
+
dx: col,
|
|
1989
|
+
dy: row,
|
|
1990
|
+
level,
|
|
1991
|
+
hole: 0,
|
|
1992
|
+
wag: tailWeight(col)
|
|
1993
|
+
});
|
|
1994
|
+
}
|
|
1995
|
+
return cells;
|
|
1996
|
+
}
|
|
1997
|
+
/** The baked mask, shared by every instance (it never changes). */
|
|
1998
|
+
const WHALE_CELLS = buildWhaleCells();
|
|
1999
|
+
/** Cells per sea look: three broken swell lines plus a faint noise wash. The
|
|
2000
|
+
* lines are gated in four-cell runs, so they read as water scrolling past
|
|
2001
|
+
* instead of as a ruler-straight dashed rule. */
|
|
2002
|
+
const SEA_BANDS = 3;
|
|
2003
|
+
function makeSeaScratch() {
|
|
2004
|
+
return {
|
|
2005
|
+
wave: /* @__PURE__ */ new Float32Array(0),
|
|
2006
|
+
open: /* @__PURE__ */ new Uint8Array(0),
|
|
2007
|
+
cols: 0
|
|
2008
|
+
};
|
|
2009
|
+
}
|
|
2010
|
+
function ensureSeaScratch(scratch, cols) {
|
|
2011
|
+
if (scratch.cols >= cols) return;
|
|
2012
|
+
scratch.wave = new Float32Array(cols * SEA_BANDS);
|
|
2013
|
+
scratch.open = new Uint8Array(cols * SEA_BANDS);
|
|
2014
|
+
scratch.cols = cols;
|
|
2015
|
+
}
|
|
2016
|
+
function makeParticles() {
|
|
2017
|
+
return {
|
|
2018
|
+
x: new Float32Array(PARTICLE_MAX),
|
|
2019
|
+
y: new Float32Array(PARTICLE_MAX),
|
|
2020
|
+
vx: new Float32Array(PARTICLE_MAX),
|
|
2021
|
+
vy: new Float32Array(PARTICLE_MAX),
|
|
2022
|
+
born: new Float64Array(PARTICLE_MAX),
|
|
2023
|
+
life: new Float64Array(PARTICLE_MAX),
|
|
2024
|
+
kind: new Uint8Array(PARTICLE_MAX),
|
|
2025
|
+
count: 0,
|
|
2026
|
+
next: 0
|
|
2027
|
+
};
|
|
2028
|
+
}
|
|
2029
|
+
/**
|
|
2030
|
+
* Create the whale piece. The returned function owns the whale position, the
|
|
2031
|
+
* particle pool and the sea scratch; all three are reused for the piece's
|
|
2032
|
+
* lifetime and reset only when the grid changes.
|
|
2033
|
+
*/
|
|
2034
|
+
function createWhalePiece(levels, dither) {
|
|
2035
|
+
const last = Math.max(0, levels - 1);
|
|
2036
|
+
const levelMap = /* @__PURE__ */ new Uint8Array(10);
|
|
2037
|
+
for (let k = 0; k < 10; k++) levelMap[k] = Math.round(k / 9 * last);
|
|
2038
|
+
const sea = makeSeaScratch();
|
|
2039
|
+
const pool = makeParticles();
|
|
2040
|
+
let cols = 0;
|
|
2041
|
+
let rows = 0;
|
|
2042
|
+
let anchorX = NaN;
|
|
2043
|
+
let anchorY = 0;
|
|
2044
|
+
let lastT = NaN;
|
|
2045
|
+
let boost = 0;
|
|
2046
|
+
let dodge = 0;
|
|
2047
|
+
let nextBlow = NaN;
|
|
2048
|
+
let blowSerial = 0;
|
|
2049
|
+
let lastTrail = NaN;
|
|
2050
|
+
let pulseSeen = -1;
|
|
2051
|
+
let arrivals = 0;
|
|
2052
|
+
function clamp(value, lo, hi) {
|
|
2053
|
+
return value < lo ? lo : value > hi ? hi : value;
|
|
2054
|
+
}
|
|
2055
|
+
function resetGrid(nextCols, nextRows) {
|
|
2056
|
+
cols = nextCols;
|
|
2057
|
+
rows = nextRows;
|
|
2058
|
+
anchorX = cols * .62;
|
|
2059
|
+
anchorY = clamp(rows * .5 - 12 * .5, 0, Math.max(0, rows - 12));
|
|
2060
|
+
lastT = NaN;
|
|
2061
|
+
boost = 0;
|
|
2062
|
+
dodge = 0;
|
|
2063
|
+
nextBlow = NaN;
|
|
2064
|
+
lastTrail = NaN;
|
|
2065
|
+
pulseSeen = -1;
|
|
2066
|
+
arrivals = 0;
|
|
2067
|
+
pool.count = 0;
|
|
2068
|
+
pool.next = 0;
|
|
2069
|
+
}
|
|
2070
|
+
function spawn(x, y, vx, vy, born, life, kind) {
|
|
2071
|
+
const i = pool.next;
|
|
2072
|
+
pool.x[i] = x;
|
|
2073
|
+
pool.y[i] = y;
|
|
2074
|
+
pool.vx[i] = vx;
|
|
2075
|
+
pool.vy[i] = vy;
|
|
2076
|
+
pool.born[i] = born;
|
|
2077
|
+
pool.life[i] = life;
|
|
2078
|
+
pool.kind[i] = kind;
|
|
2079
|
+
pool.next = (i + 1) % PARTICLE_MAX;
|
|
2080
|
+
if (pool.count < PARTICLE_MAX) pool.count++;
|
|
2081
|
+
}
|
|
2082
|
+
/** Spout above the blowhole; the mouth of the spout follows the bob. */
|
|
2083
|
+
function blow(t) {
|
|
2084
|
+
const originX = anchorX + 8;
|
|
2085
|
+
const originY = anchorY + dodge + Math.sin(t * WHALE_BOB_RATE) * WHALE_BOB - .6;
|
|
2086
|
+
for (let k = 0; k < SPRAY_COUNT; k++) {
|
|
2087
|
+
const s = hash2(blowSerial * 31 + k, 5);
|
|
2088
|
+
const r = hash2(blowSerial * 17 + k, 9);
|
|
2089
|
+
spawn(originX + (s - .5) * 1.8, originY, (s - .5) * 1.4, -(SPRAY_LAUNCH + r * SPRAY_LIFT), t, 1.2 + hash2(blowSerial * 7 + k, 13) * .8, 1);
|
|
2090
|
+
}
|
|
2091
|
+
blowSerial++;
|
|
2092
|
+
}
|
|
2093
|
+
function trailBubble(t) {
|
|
2094
|
+
const s = hash2(blowSerial * 3 + 1, 41);
|
|
2095
|
+
spawn(anchorX + 44 + s * 2, anchorY + dodge + 5 + s * 1.5, .12 + s * .2, -(.5 + s * .5), t, 2.4 + s * 1.6, 0);
|
|
2096
|
+
}
|
|
2097
|
+
function clickBubbles(t, x, y) {
|
|
2098
|
+
for (let k = 0; k < 4; k++) {
|
|
2099
|
+
const s = hash2(blowSerial * 5 + k, 23);
|
|
2100
|
+
spawn(x + (s - .5) * 2.6, y + (s - .5) * 1.6, (s - .5) * .9, -(.7 + s * .8), t, 1.2 + s * 1, 0);
|
|
2101
|
+
}
|
|
2102
|
+
}
|
|
2103
|
+
return (t, out, nextCols, nextRows, input, emphasis, overlay) => {
|
|
2104
|
+
if (nextCols !== cols || nextRows !== rows || !Number.isFinite(anchorX)) resetGrid(nextCols, nextRows);
|
|
2105
|
+
const dt = Number.isFinite(lastT) ? Math.min(.1, Math.max(0, t - lastT)) : 0;
|
|
2106
|
+
lastT = t;
|
|
2107
|
+
if (!Number.isFinite(nextBlow)) nextBlow = t + FIRST_BLOW;
|
|
2108
|
+
ensureSeaScratch(sea, cols);
|
|
2109
|
+
for (let col = 0; col < cols; col++) for (let k = 0; k < SEA_BANDS; k++) {
|
|
2110
|
+
const slot = k * cols + col;
|
|
2111
|
+
const phase = valueNoise(col * .03 + t * .05, 11 + k * 7) * 6.283;
|
|
2112
|
+
sea.wave[slot] = Math.sin(col * .085 + phase + t * .32 + k) * (1.1 + k * .35);
|
|
2113
|
+
sea.open[slot] = hash2(col >> 2, 17 + k) > .56 ? 1 : 0;
|
|
2114
|
+
}
|
|
2115
|
+
const bandA = rows * .26;
|
|
2116
|
+
const bandB = rows * .53;
|
|
2117
|
+
const bandC = rows * .8;
|
|
2118
|
+
let i = 0;
|
|
2119
|
+
for (let row = 0; row < rows; row++) for (let col = 0; col < cols; col++, i++) {
|
|
2120
|
+
let v = 0;
|
|
2121
|
+
const n = valueNoise(col * .065 + t * .035, row * .11 + 7.7);
|
|
2122
|
+
if (n > .8) v = (n - .8) * 1.4;
|
|
2123
|
+
const waveA = sea.wave[col];
|
|
2124
|
+
if (sea.open[col] === 1 && row > bandA + waveA - .6 && row < bandA + waveA + .6) v = Math.max(v, .2);
|
|
2125
|
+
const waveB = sea.wave[cols + col];
|
|
2126
|
+
if (sea.open[cols + col] === 1 && row > bandB + waveB - .65 && row < bandB + waveB + .65) v = Math.max(v, .3);
|
|
2127
|
+
const waveC = sea.wave[cols * 2 + col];
|
|
2128
|
+
if (sea.open[cols * 2 + col] === 1 && row > bandC + waveC - .7 && row < bandC + waveC + .7) v = Math.max(v, .24);
|
|
2129
|
+
shade(out, i, v, levels, dither, row, col);
|
|
2130
|
+
}
|
|
2131
|
+
let boostTarget = 0;
|
|
2132
|
+
let dodgeTarget = 0;
|
|
2133
|
+
if (input !== void 0) {
|
|
2134
|
+
if (input.active) {
|
|
2135
|
+
const hx = anchorX + 8;
|
|
2136
|
+
const hy = anchorY + 4 + Math.sin(t * WHALE_BOB_RATE) * WHALE_BOB;
|
|
2137
|
+
const dx = input.x - hx;
|
|
2138
|
+
const dy = input.y - hy;
|
|
2139
|
+
const d = Math.sqrt(dx * dx + dy * dy);
|
|
2140
|
+
const near = d < NOTICE_RADIUS$1 ? 1 - d / NOTICE_RADIUS$1 : 0;
|
|
2141
|
+
if (near > 0) {
|
|
2142
|
+
boostTarget = near * 1.6;
|
|
2143
|
+
dodgeTarget = (dy >= 0 ? 1 : -1) * near * 2.2;
|
|
2144
|
+
}
|
|
2145
|
+
}
|
|
2146
|
+
if (pulseSeen < 0) pulseSeen = input.pulseId;
|
|
2147
|
+
else if (input.pulseId !== pulseSeen) {
|
|
2148
|
+
pulseSeen = input.pulseId;
|
|
2149
|
+
clickBubbles(t, input.pulseX, input.pulseY);
|
|
2150
|
+
const dx = input.pulseX - (anchorX + 8);
|
|
2151
|
+
const dy = input.pulseY - (anchorY + 4);
|
|
2152
|
+
if (dx * dx + dy * dy < STARTLE_RADIUS$1 * STARTLE_RADIUS$1) {
|
|
2153
|
+
boost = Math.max(boost, 2.4);
|
|
2154
|
+
blow(t);
|
|
2155
|
+
nextBlow = t + BLOW_MIN + hash2(blowSerial, 31) * (BLOW_MAX - BLOW_MIN);
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
}
|
|
2159
|
+
if (dt > 0) {
|
|
2160
|
+
const ease = 1 - Math.exp(-dt * 2.5);
|
|
2161
|
+
boost += (boostTarget - boost) * ease;
|
|
2162
|
+
dodge += (dodgeTarget - dodge) * ease;
|
|
2163
|
+
boost *= Math.exp(-dt / 2.2);
|
|
2164
|
+
anchorX -= dt * WHALE_SPEED * (1 + boost);
|
|
2165
|
+
}
|
|
2166
|
+
if (anchorX + 50 < -2) {
|
|
2167
|
+
arrivals++;
|
|
2168
|
+
anchorX = cols + 2 + hash2(arrivals, 3) * 5;
|
|
2169
|
+
anchorY = clamp(rows * (.16 + hash2(arrivals, 7) * .5) - 12 * .5, 0, Math.max(0, rows - 12));
|
|
2170
|
+
boost = 0;
|
|
2171
|
+
dodge = 0;
|
|
2172
|
+
}
|
|
2173
|
+
const bob = Math.round(Math.sin(t * WHALE_BOB_RATE) * WHALE_BOB);
|
|
2174
|
+
const ax = Math.round(anchorX);
|
|
2175
|
+
const ay = Math.round(anchorY + dodge + bob);
|
|
2176
|
+
const tailWave = Math.sin(t * WHALE_TAIL_RATE);
|
|
2177
|
+
for (let k = 0; k < WHALE_CELLS.length; k++) {
|
|
2178
|
+
const cell = WHALE_CELLS[k];
|
|
2179
|
+
const col = ax + cell.dx;
|
|
2180
|
+
if (col < 0 || col >= cols) continue;
|
|
2181
|
+
let row = ay + cell.dy;
|
|
2182
|
+
if (cell.wag > 0) row += Math.round(tailWave * cell.wag * WHALE_TAIL_SWING);
|
|
2183
|
+
if (row < 0 || row >= rows) continue;
|
|
2184
|
+
const idx = row * cols + col;
|
|
2185
|
+
if (cell.hole !== 0) {
|
|
2186
|
+
out[idx] = 0;
|
|
2187
|
+
continue;
|
|
2188
|
+
}
|
|
2189
|
+
const lv = levelMap[cell.level];
|
|
2190
|
+
if (lv > out[idx]) out[idx] = lv;
|
|
2191
|
+
if (emphasis !== void 0) emphasis[idx] = 1;
|
|
2192
|
+
}
|
|
2193
|
+
if (t >= nextBlow) {
|
|
2194
|
+
blow(t);
|
|
2195
|
+
nextBlow = t + BLOW_MIN + hash2(blowSerial, 31) * (BLOW_MAX - BLOW_MIN);
|
|
2196
|
+
}
|
|
2197
|
+
if (!Number.isFinite(lastTrail)) lastTrail = t;
|
|
2198
|
+
if (t - lastTrail >= TRAIL_INTERVAL) {
|
|
2199
|
+
lastTrail = t;
|
|
2200
|
+
for (let k = 0; k < TRAIL_COUNT; k++) trailBubble(t);
|
|
2201
|
+
}
|
|
2202
|
+
for (let p = 0; p < pool.count; p++) {
|
|
2203
|
+
const age = t - pool.born[p];
|
|
2204
|
+
if (age < 0 || age >= pool.life[p]) continue;
|
|
2205
|
+
if (dt > 0) {
|
|
2206
|
+
if (pool.kind[p] === 1) pool.vy[p] += SPRAY_GRAVITY * dt;
|
|
2207
|
+
else pool.vx[p] += Math.sin(t * 1.3 + p) * .12 * dt;
|
|
2208
|
+
pool.x[p] += pool.vx[p] * dt;
|
|
2209
|
+
pool.y[p] += pool.vy[p] * dt;
|
|
2210
|
+
}
|
|
2211
|
+
const col = Math.round(pool.x[p]);
|
|
2212
|
+
const row = Math.round(pool.y[p]);
|
|
2213
|
+
if (col < 0 || col >= cols || row < 0 || row >= rows) continue;
|
|
2214
|
+
const idx = row * cols + col;
|
|
2215
|
+
const kind = pool.kind[p];
|
|
2216
|
+
const lv = kind === 1 ? age < pool.life[p] * .45 ? levelMap[9] : levelMap[7] : levelMap[5];
|
|
2217
|
+
if (lv > out[idx]) out[idx] = lv;
|
|
2218
|
+
if (overlay !== void 0) if (kind === 1) overlay[idx] = age < .3 ? GLYPH_TICK : age < pool.life[p] * .6 ? GLYPH_BUBBLE$1 : GLYPH_DOT$1;
|
|
2219
|
+
else overlay[idx] = GLYPH_BUBBLE$1;
|
|
2220
|
+
if (emphasis !== void 0) emphasis[idx] = 1;
|
|
2221
|
+
}
|
|
2222
|
+
};
|
|
2223
|
+
}
|
|
2224
|
+
//#endregion
|
|
2225
|
+
//#region src/client/bg-jelly.ts
|
|
2226
|
+
/**
|
|
2227
|
+
* `jelly`: a jellyfish rising slowly through the page.
|
|
2228
|
+
*
|
|
2229
|
+
* The animal is three layers:
|
|
2230
|
+
* 1. a bell rasterised once from a half-ellipse at module load — concentric
|
|
2231
|
+
* tonal rings (rim level 9 down to a translucent level 4 centre) with a
|
|
2232
|
+
* wavy skirt on the bottom row;
|
|
2233
|
+
* 2. six parametric tendrils hanging from the skirt, each with its own
|
|
2234
|
+
* phase, amplitude and length drawn as `| / \ ~` direction marks with a
|
|
2235
|
+
* faint ramp cell underneath;
|
|
2236
|
+
* 3. drifting plankton (sparse level 1–2 dots that wrap vertically) and click
|
|
2237
|
+
* sparks (short-lived overlay points that spread out from the pointer).
|
|
2238
|
+
*
|
|
2239
|
+
* The bell pulses at 1.15 rad/s: the whole animal bobs one row and the
|
|
2240
|
+
* tendrils shorten on the contraction, which is what makes it read as
|
|
2241
|
+
* swimming rather than floating. The pointer is felt: inside 12 cells the
|
|
2242
|
+
* jellyfish rises faster and contracts; a click adds a stronger contraction
|
|
2243
|
+
* and lights a ring of sparks at the click.
|
|
2244
|
+
*
|
|
2245
|
+
* Every bell and tendril cell is marked for emphasis, and the preset carries
|
|
2246
|
+
* `emphasisFull` (bg-ascii spec flag), so the animal keeps its own ink inside
|
|
2247
|
+
* the calm zone instead of fading to the 0.65 floor — the same contract the
|
|
2248
|
+
* whale uses. Plankton stays masked like any texture. Nothing allocates per
|
|
2249
|
+
* frame: the bell is module-level, the spark pool is fixed, and the plankton
|
|
2250
|
+
* positions are hashes of their index.
|
|
2251
|
+
* @module @alexpeng/dsh-custom-plugin/client/bg-jelly
|
|
2252
|
+
*/
|
|
2253
|
+
/** Overlay slots (see `OVERLAY_GLYPHS` in bg-field). */
|
|
2254
|
+
const GLYPH_PIPE = 7;
|
|
2255
|
+
const GLYPH_SLASH = 4;
|
|
2256
|
+
const GLYPH_BACKSLASH = 2;
|
|
2257
|
+
const GLYPH_TILDE = 8;
|
|
2258
|
+
const GLYPH_SPARK = 12;
|
|
2259
|
+
const GLYPH_BUBBLE = 13;
|
|
2260
|
+
const GLYPH_DOT = 16;
|
|
2261
|
+
/** Tendrils: count, longest length and where they start along the skirt. */
|
|
2262
|
+
const TENDRILS = 6;
|
|
2263
|
+
const TENDRIL_MAX = 16;
|
|
2264
|
+
/** Rise speed in cells/s on the preset's own clock. */
|
|
2265
|
+
const RISE_SPEED = 1.5;
|
|
2266
|
+
/** Pulse angular rate and the fraction of the tendril length it retracts. */
|
|
2267
|
+
const PULSE_RATE = 1.15;
|
|
2268
|
+
const PULSE_RETRACT = .16;
|
|
2269
|
+
/** Pointer radii in cells. */
|
|
2270
|
+
const NOTICE_RADIUS = 12;
|
|
2271
|
+
const STARTLE_RADIUS = 16;
|
|
2272
|
+
/** Click sparks: fixed pool, golden-angle spread. */
|
|
2273
|
+
const SPARK_MAX = 32;
|
|
2274
|
+
const SPARK_COUNT = 9;
|
|
2275
|
+
const SPARK_LIFE = .95;
|
|
2276
|
+
/** Plankton: a fixed count of drifting dots, hashed into place. */
|
|
2277
|
+
const PLANKTON = 26;
|
|
2278
|
+
/** Bell centre and radii in mask coordinates. The mask only keeps the upper
|
|
2279
|
+
* half of the ellipse: the flat bottom is the skirt the tendrils hang from. */
|
|
2280
|
+
const BELL_CX = 23 / 2;
|
|
2281
|
+
const BELL_CY = 7.5;
|
|
2282
|
+
const BELL_RX = 24 / 2 - .5;
|
|
2283
|
+
const BELL_RY = 7.4;
|
|
2284
|
+
/**
|
|
2285
|
+
* Rasterise the bell. Runs once at module load. The tonal rings are what give
|
|
2286
|
+
* the bell its dome: the rim is the darkest step, the interior steps down ring
|
|
2287
|
+
* by ring, and the very centre stays translucent (level 4).
|
|
2288
|
+
*/
|
|
2289
|
+
function buildJellyBell() {
|
|
2290
|
+
const cells = [];
|
|
2291
|
+
for (let row = 0; row < 8; row++) for (let col = 0; col < 24; col++) {
|
|
2292
|
+
const x = col + .5;
|
|
2293
|
+
const y = row + .5;
|
|
2294
|
+
const nx = (x - BELL_CX) / BELL_RX;
|
|
2295
|
+
const ny = (y - BELL_CY) / BELL_RY;
|
|
2296
|
+
const r = Math.sqrt(nx * nx + ny * ny);
|
|
2297
|
+
if (r > 1 || y > BELL_CY) continue;
|
|
2298
|
+
let level;
|
|
2299
|
+
if (r > .9) level = 9;
|
|
2300
|
+
else if (r > .72) level = 8;
|
|
2301
|
+
else if (r > .52) level = 7;
|
|
2302
|
+
else if (r > .3) level = 6;
|
|
2303
|
+
else level = 5;
|
|
2304
|
+
if (r < .18) level = 4;
|
|
2305
|
+
const skirt = row === 7;
|
|
2306
|
+
cells.push({
|
|
2307
|
+
dx: col,
|
|
2308
|
+
dy: row,
|
|
2309
|
+
level,
|
|
2310
|
+
skirt
|
|
2311
|
+
});
|
|
2312
|
+
}
|
|
2313
|
+
return cells;
|
|
2314
|
+
}
|
|
2315
|
+
/** The baked bell, shared by every instance. */
|
|
2316
|
+
const JELLY_BELL_CELLS = buildJellyBell();
|
|
2317
|
+
function makeSparks() {
|
|
2318
|
+
return {
|
|
2319
|
+
x: new Float32Array(SPARK_MAX),
|
|
2320
|
+
y: new Float32Array(SPARK_MAX),
|
|
2321
|
+
vx: new Float32Array(SPARK_MAX),
|
|
2322
|
+
vy: new Float32Array(SPARK_MAX),
|
|
2323
|
+
born: new Float64Array(SPARK_MAX),
|
|
2324
|
+
life: new Float64Array(SPARK_MAX),
|
|
2325
|
+
count: 0,
|
|
2326
|
+
next: 0
|
|
2327
|
+
};
|
|
2328
|
+
}
|
|
2329
|
+
/**
|
|
2330
|
+
* Create the jellyfish piece. The returned function owns the bell position, the
|
|
2331
|
+
* contraction state, the spark pool and the plankton hashes; all of it is
|
|
2332
|
+
* reused for the piece's lifetime and reset only when the grid changes.
|
|
2333
|
+
*/
|
|
2334
|
+
function createJellyPiece(levels, dither) {
|
|
2335
|
+
const last = Math.max(0, levels - 1);
|
|
2336
|
+
const levelMap = /* @__PURE__ */ new Uint8Array(10);
|
|
2337
|
+
for (let k = 0; k < 10; k++) levelMap[k] = Math.round(k / 9 * last);
|
|
2338
|
+
const sparks = makeSparks();
|
|
2339
|
+
let cols = 0;
|
|
2340
|
+
let rows = 0;
|
|
2341
|
+
let anchorX = NaN;
|
|
2342
|
+
let anchorY = 0;
|
|
2343
|
+
let driftPhase = 0;
|
|
2344
|
+
let lastT = NaN;
|
|
2345
|
+
let boost = 0;
|
|
2346
|
+
let contract = 0;
|
|
2347
|
+
let pulseSeen = -1;
|
|
2348
|
+
let arrivals = 0;
|
|
2349
|
+
function resetGrid(nextCols, nextRows) {
|
|
2350
|
+
cols = nextCols;
|
|
2351
|
+
rows = nextRows;
|
|
2352
|
+
anchorX = cols * .62;
|
|
2353
|
+
anchorY = rows - 2;
|
|
2354
|
+
driftPhase = .4;
|
|
2355
|
+
lastT = NaN;
|
|
2356
|
+
boost = 0;
|
|
2357
|
+
contract = 0;
|
|
2358
|
+
pulseSeen = -1;
|
|
2359
|
+
arrivals = 0;
|
|
2360
|
+
sparks.count = 0;
|
|
2361
|
+
sparks.next = 0;
|
|
2362
|
+
}
|
|
2363
|
+
function spawnSpark(x, y, vx, vy, born, life) {
|
|
2364
|
+
const i = sparks.next;
|
|
2365
|
+
sparks.x[i] = x;
|
|
2366
|
+
sparks.y[i] = y;
|
|
2367
|
+
sparks.vx[i] = vx;
|
|
2368
|
+
sparks.vy[i] = vy;
|
|
2369
|
+
sparks.born[i] = born;
|
|
2370
|
+
sparks.life[i] = life;
|
|
2371
|
+
sparks.next = (i + 1) % SPARK_MAX;
|
|
2372
|
+
if (sparks.count < SPARK_MAX) sparks.count++;
|
|
2373
|
+
}
|
|
2374
|
+
/** A ring of sparks around the click; the bell contracts when it is close. */
|
|
2375
|
+
function clickSparks(t, x, y, near) {
|
|
2376
|
+
for (let k = 0; k < SPARK_COUNT; k++) {
|
|
2377
|
+
const angle = k / SPARK_COUNT * Math.PI * 2 + hash2(k + sparks.next, 7) * .6;
|
|
2378
|
+
const speed = .8 + hash2(k + sparks.next, 11) * 1;
|
|
2379
|
+
spawnSpark(x + Math.cos(angle) * .8, y + Math.sin(angle) * .6, Math.cos(angle) * speed, Math.sin(angle) * speed * .7, t, SPARK_LIFE * (.7 + hash2(k + sparks.next, 13) * .5));
|
|
2380
|
+
}
|
|
2381
|
+
if (near) {
|
|
2382
|
+
contract = 1;
|
|
2383
|
+
boost = Math.max(boost, 1.5);
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
return (t, out, nextCols, nextRows, input, emphasis, overlay) => {
|
|
2387
|
+
if (nextCols !== cols || nextRows !== rows || !Number.isFinite(anchorX)) resetGrid(nextCols, nextRows);
|
|
2388
|
+
const dt = Number.isFinite(lastT) ? Math.min(.1, Math.max(0, t - lastT)) : 0;
|
|
2389
|
+
lastT = t;
|
|
2390
|
+
let i = 0;
|
|
2391
|
+
for (let row = 0; row < rows; row++) for (let col = 0; col < cols; col++, i++) {
|
|
2392
|
+
let v = 0;
|
|
2393
|
+
if (hash2(col * 3 + 1, row * 5 + 3) > .987) v = .12;
|
|
2394
|
+
shade(out, i, v, levels, dither, row, col);
|
|
2395
|
+
}
|
|
2396
|
+
for (let p = 0; p < PLANKTON; p++) {
|
|
2397
|
+
const baseX = hash2(p * 5 + 1, 17) * cols;
|
|
2398
|
+
const speed = .12 + hash2(p * 5 + 2, 23) * .25;
|
|
2399
|
+
const wrapped = ((hash2(p * 5 + 3, 29) * (rows + 8) - t * speed) % (rows + 8) + rows + 8) % (rows + 8) - 4;
|
|
2400
|
+
const twinkle = .5 + .5 * Math.sin(t * .9 + p * 1.7);
|
|
2401
|
+
const col = Math.round(baseX + Math.sin(t * .2 + p) * 1.2);
|
|
2402
|
+
const row = Math.round(wrapped);
|
|
2403
|
+
if (col < 0 || col >= cols || row < 0 || row >= rows) continue;
|
|
2404
|
+
const idx = row * cols + col;
|
|
2405
|
+
const lv = twinkle > .72 ? levelMap[2] : levelMap[1];
|
|
2406
|
+
if (lv > out[idx]) out[idx] = lv;
|
|
2407
|
+
}
|
|
2408
|
+
let boostTarget = 0;
|
|
2409
|
+
let contractTarget = 0;
|
|
2410
|
+
if (input !== void 0) {
|
|
2411
|
+
if (input.active) {
|
|
2412
|
+
const hx = anchorX + BELL_CX;
|
|
2413
|
+
const hy = anchorY + BELL_CY;
|
|
2414
|
+
const dx = input.x - hx;
|
|
2415
|
+
const dy = input.y - hy;
|
|
2416
|
+
const d = Math.sqrt(dx * dx + dy * dy);
|
|
2417
|
+
const near = d < NOTICE_RADIUS ? 1 - d / NOTICE_RADIUS : 0;
|
|
2418
|
+
if (near > 0) {
|
|
2419
|
+
boostTarget = near * 1.1;
|
|
2420
|
+
contractTarget = near * .85;
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
if (pulseSeen < 0) pulseSeen = input.pulseId;
|
|
2424
|
+
else if (input.pulseId !== pulseSeen) {
|
|
2425
|
+
pulseSeen = input.pulseId;
|
|
2426
|
+
const dx = input.pulseX - (anchorX + BELL_CX);
|
|
2427
|
+
const dy = input.pulseY - (anchorY + BELL_CY);
|
|
2428
|
+
clickSparks(t, input.pulseX, input.pulseY, dx * dx + dy * dy < STARTLE_RADIUS * STARTLE_RADIUS);
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
if (dt > 0) {
|
|
2432
|
+
const ease = 1 - Math.exp(-dt * 3);
|
|
2433
|
+
boost += (boostTarget - boost) * ease;
|
|
2434
|
+
boost *= Math.exp(-dt / 1.8);
|
|
2435
|
+
contract += (contractTarget - contract) * ease;
|
|
2436
|
+
contract *= Math.exp(-dt / .6);
|
|
2437
|
+
anchorY -= dt * RISE_SPEED * (1 + boost);
|
|
2438
|
+
}
|
|
2439
|
+
if (anchorY + 8 + TENDRIL_MAX < -2) {
|
|
2440
|
+
arrivals++;
|
|
2441
|
+
anchorY = rows + 4 + hash2(arrivals, 5) * 6;
|
|
2442
|
+
anchorX = cols * (.12 + hash2(arrivals, 9) * .66);
|
|
2443
|
+
boost = 0;
|
|
2444
|
+
contract = 0;
|
|
2445
|
+
}
|
|
2446
|
+
const pulse = Math.sin(t * PULSE_RATE);
|
|
2447
|
+
const bob = Math.round(pulse);
|
|
2448
|
+
const shrink = Math.round(contract);
|
|
2449
|
+
const bx = Math.round(anchorX + Math.sin(t * .22 + driftPhase) * 2.2);
|
|
2450
|
+
const by = Math.round(anchorY + bob - shrink);
|
|
2451
|
+
for (let k = 0; k < JELLY_BELL_CELLS.length; k++) {
|
|
2452
|
+
const cell = JELLY_BELL_CELLS[k];
|
|
2453
|
+
const col = bx + cell.dx;
|
|
2454
|
+
const row = by + cell.dy;
|
|
2455
|
+
if (col < 0 || col >= cols || row < 0 || row >= rows) continue;
|
|
2456
|
+
const idx = row * cols + col;
|
|
2457
|
+
const lv = levelMap[cell.level];
|
|
2458
|
+
if (lv > out[idx]) out[idx] = lv;
|
|
2459
|
+
if (cell.skirt && overlay !== void 0 && (cell.dx & 1) === 0) overlay[idx] = GLYPH_TILDE;
|
|
2460
|
+
if (emphasis !== void 0) emphasis[idx] = 1;
|
|
2461
|
+
}
|
|
2462
|
+
const skirtRow = by + 8 - 1;
|
|
2463
|
+
for (let d = 0; d < TENDRILS; d++) {
|
|
2464
|
+
const baseX = 3 + d * 3.6;
|
|
2465
|
+
const phase = hash2(d * 5 + 1, 7) * 6.283;
|
|
2466
|
+
const amp = 1 + hash2(d * 5 + 2, 11) * 1;
|
|
2467
|
+
const len = Math.round((10 + hash2(d * 5 + 3, 13) * 6) * (1 - contract * PULSE_RETRACT) * (1 + pulse * .05));
|
|
2468
|
+
let prevOff = Math.sin(t * 1.3 + phase) * amp * .12;
|
|
2469
|
+
for (let k = 0; k < len; k++) {
|
|
2470
|
+
const off = Math.sin(t * 1.3 + phase + k * .42) * amp * (k / len) * 3;
|
|
2471
|
+
const delta = off - prevOff;
|
|
2472
|
+
prevOff = off;
|
|
2473
|
+
const col = Math.round(bx + baseX + off);
|
|
2474
|
+
const row = skirtRow + k + 1;
|
|
2475
|
+
if (col < 0 || col >= cols || row < 0 || row >= rows) continue;
|
|
2476
|
+
const idx = row * cols + col;
|
|
2477
|
+
const lv = levelMap[4];
|
|
2478
|
+
if (lv > out[idx]) out[idx] = lv;
|
|
2479
|
+
if (overlay !== void 0) if (k > len - 3 && hash2(d * 7 + k, 31) > .5) overlay[idx] = GLYPH_TILDE;
|
|
2480
|
+
else overlay[idx] = Math.abs(delta) < .28 ? GLYPH_PIPE : delta > 0 ? GLYPH_BACKSLASH : GLYPH_SLASH;
|
|
2481
|
+
if (emphasis !== void 0) emphasis[idx] = 1;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
for (let p = 0; p < sparks.count; p++) {
|
|
2485
|
+
const age = t - sparks.born[p];
|
|
2486
|
+
if (age < 0 || age >= sparks.life[p]) continue;
|
|
2487
|
+
if (dt > 0) {
|
|
2488
|
+
sparks.x[p] += sparks.vx[p] * dt;
|
|
2489
|
+
sparks.y[p] += sparks.vy[p] * dt;
|
|
2490
|
+
sparks.vx[p] *= Math.exp(-dt * 1.8);
|
|
2491
|
+
}
|
|
2492
|
+
const col = Math.round(sparks.x[p]);
|
|
2493
|
+
const row = Math.round(sparks.y[p]);
|
|
2494
|
+
if (col < 0 || col >= cols || row < 0 || row >= rows) continue;
|
|
2495
|
+
const idx = row * cols + col;
|
|
2496
|
+
const phase = age / sparks.life[p];
|
|
2497
|
+
const lv = phase < .4 ? levelMap[4] : phase < .75 ? levelMap[3] : levelMap[2];
|
|
2498
|
+
if (lv > out[idx]) out[idx] = lv;
|
|
2499
|
+
if (overlay !== void 0) overlay[idx] = phase < .35 ? GLYPH_SPARK : phase < .7 ? GLYPH_BUBBLE : GLYPH_DOT;
|
|
2500
|
+
if (emphasis !== void 0) emphasis[idx] = 1;
|
|
2501
|
+
}
|
|
2502
|
+
};
|
|
2503
|
+
}
|
|
1778
2504
|
/** Monospace stack; `ui-monospace` resolves locally, so nothing is fetched. */
|
|
1779
2505
|
const MONO_STACK = "ui-monospace, SFMono-Regular, Menlo, Consolas, \"Cascadia Mono\", \"DejaVu Sans Mono\", monospace";
|
|
1780
2506
|
/** Glyph ramps ordered by increasing ink density. */
|
|
@@ -1902,6 +2628,74 @@ window.__ModuleLoader__.load({
|
|
|
1902
2628
|
}
|
|
1903
2629
|
}
|
|
1904
2630
|
},
|
|
2631
|
+
whale: {
|
|
2632
|
+
density: .65,
|
|
2633
|
+
speed: .8,
|
|
2634
|
+
fps: 24,
|
|
2635
|
+
charset: "blocks",
|
|
2636
|
+
dither: false,
|
|
2637
|
+
opacity: .68,
|
|
2638
|
+
fontPx: 12,
|
|
2639
|
+
inkScale: 1.4,
|
|
2640
|
+
interactive: true,
|
|
2641
|
+
emphasisFull: true,
|
|
2642
|
+
ranges: {
|
|
2643
|
+
density: {
|
|
2644
|
+
min: .45,
|
|
2645
|
+
max: .85
|
|
2646
|
+
},
|
|
2647
|
+
speed: {
|
|
2648
|
+
min: 0,
|
|
2649
|
+
max: 1.6
|
|
2650
|
+
},
|
|
2651
|
+
fps: {
|
|
2652
|
+
min: 15,
|
|
2653
|
+
max: 33
|
|
2654
|
+
},
|
|
2655
|
+
fontPx: {
|
|
2656
|
+
min: 8,
|
|
2657
|
+
max: 16
|
|
2658
|
+
},
|
|
2659
|
+
opacity: {
|
|
2660
|
+
min: .36,
|
|
2661
|
+
max: 1
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
},
|
|
2665
|
+
jelly: {
|
|
2666
|
+
density: .65,
|
|
2667
|
+
speed: .8,
|
|
2668
|
+
fps: 24,
|
|
2669
|
+
charset: "blocks",
|
|
2670
|
+
dither: false,
|
|
2671
|
+
opacity: .66,
|
|
2672
|
+
fontPx: 12,
|
|
2673
|
+
inkScale: 1.35,
|
|
2674
|
+
interactive: true,
|
|
2675
|
+
emphasisFull: true,
|
|
2676
|
+
ranges: {
|
|
2677
|
+
density: {
|
|
2678
|
+
min: .45,
|
|
2679
|
+
max: .85
|
|
2680
|
+
},
|
|
2681
|
+
speed: {
|
|
2682
|
+
min: 0,
|
|
2683
|
+
max: 1.6
|
|
2684
|
+
},
|
|
2685
|
+
fps: {
|
|
2686
|
+
min: 15,
|
|
2687
|
+
max: 33
|
|
2688
|
+
},
|
|
2689
|
+
fontPx: {
|
|
2690
|
+
min: 8,
|
|
2691
|
+
max: 16
|
|
2692
|
+
},
|
|
2693
|
+
opacity: {
|
|
2694
|
+
min: .32,
|
|
2695
|
+
max: 1
|
|
2696
|
+
}
|
|
2697
|
+
}
|
|
2698
|
+
},
|
|
1905
2699
|
starfield: {
|
|
1906
2700
|
density: .65,
|
|
1907
2701
|
speed: .3,
|
|
@@ -2682,6 +3476,8 @@ window.__ModuleLoader__.load({
|
|
|
2682
3476
|
switch (preset) {
|
|
2683
3477
|
case "rain": return createRainPiece(levels, dither);
|
|
2684
3478
|
case "ocean": return createOceanPiece(levels, dither);
|
|
3479
|
+
case "whale": return createWhalePiece(levels, dither);
|
|
3480
|
+
case "jelly": return createJellyPiece(levels, dither);
|
|
2685
3481
|
case "starfield": return createStarfieldPiece(levels, dither);
|
|
2686
3482
|
case "ripple": return createRipplePiece(levels, dither);
|
|
2687
3483
|
case "static": return createFlowPiece(levels, dither, false);
|
|
@@ -3158,6 +3954,7 @@ window.__ModuleLoader__.load({
|
|
|
3158
3954
|
const empty = baked.empty;
|
|
3159
3955
|
const lastLevel = CHARSET[spec().charset].length - 1;
|
|
3160
3956
|
const effectFloor = Math.round(lastLevel * EFFECT_FOCUS_FLOOR);
|
|
3957
|
+
const pictureFull = spec().emphasisFull === true;
|
|
3161
3958
|
let emphasisCells = 0;
|
|
3162
3959
|
let overlayCells = 0;
|
|
3163
3960
|
let i = 0;
|
|
@@ -3169,6 +3966,7 @@ window.__ModuleLoader__.load({
|
|
|
3169
3966
|
if (emphasis !== null && emphasis[i] === 1) {
|
|
3170
3967
|
emphasisCells++;
|
|
3171
3968
|
if (caps !== null && lv < effectFloor) lv = effectFloor;
|
|
3969
|
+
if (pictureFull) lv = raw;
|
|
3172
3970
|
}
|
|
3173
3971
|
if (overlay !== null && overlay[i] !== 0) overlayCells++;
|
|
3174
3972
|
let tile = lv;
|
|
@@ -7432,6 +8230,8 @@ void main() {
|
|
|
7432
8230
|
flow: "流动",
|
|
7433
8231
|
rain: "数字雨",
|
|
7434
8232
|
ocean: "海面",
|
|
8233
|
+
whale: "鲸鱼",
|
|
8234
|
+
jelly: "水母",
|
|
7435
8235
|
ripple: "涟漪",
|
|
7436
8236
|
starfield: "星野",
|
|
7437
8237
|
static: "静态",
|
|
@@ -7472,6 +8272,8 @@ void main() {
|
|
|
7472
8272
|
];
|
|
7473
8273
|
const INTERACTION_HINTS = {
|
|
7474
8274
|
ocean: "海面只铺在会话中栏,需要打开一个会话;设置页会盖住它,关闭后可见。拖动会泛起涟漪,点击溅起水花,鱼群会被惊动后重新聚拢。",
|
|
8275
|
+
whale: "一头鲸鱼会慢慢游过整页,隔一阵在头顶喷水,尾巴后面跟着气泡;鼠标靠近它会游快一点,点击会让它摆尾喷水。",
|
|
8276
|
+
jelly: "一只水母会从页面下方缓缓升起,伞盖一开一合、触手随水飘动;鼠标靠近它会游得更快并收伞,点击会在落点亮起一小圈浮游微光。",
|
|
7475
8277
|
flow: "拖动会搅动雾面,点击会推开一圈涟漪。",
|
|
7476
8278
|
rain: "鼠标划过像一阵风,会把雨丝吹斜;点击向两侧拨开雨帘,随后慢慢合拢。",
|
|
7477
8279
|
ripple: "点击会在落点漾开一圈新的涟漪,拖动会沿途留下小水纹。",
|