@arraypress/effects-astro 0.9.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/AGENTS.md +1 -1
- package/COMPONENTS.md +160 -0
- package/LICENSE +2 -2
- package/package.json +1 -1
- package/src/components/AsciiNoise.astro +37 -0
- package/src/components/CascadeGrid.astro +41 -0
- package/src/components/DitherField.astro +41 -0
- package/src/components/FlowField.astro +38 -0
- package/src/components/KineticGrid.astro +38 -0
- package/src/components/LightLeak.astro +39 -0
- package/src/components/VoronoiMesh.astro +39 -0
- package/src/index.d.ts +15 -0
- package/src/index.js +8 -0
- package/src/runtime/ascii-noise.d.ts +75 -0
- package/src/runtime/ascii-noise.js +276 -0
- package/src/runtime/cascade-grid.d.ts +112 -0
- package/src/runtime/cascade-grid.js +423 -0
- package/src/runtime/dither-field.d.ts +74 -0
- package/src/runtime/dither-field.js +442 -0
- package/src/runtime/flow-field.d.ts +117 -0
- package/src/runtime/flow-field.js +516 -0
- package/src/runtime/hash-noise.d.ts +14 -0
- package/src/runtime/hash-noise.js +169 -0
- package/src/runtime/kinetic-grid.d.ts +88 -0
- package/src/runtime/kinetic-grid.js +487 -0
- package/src/runtime/light-leak.d.ts +72 -0
- package/src/runtime/light-leak.js +408 -0
- package/src/runtime/voronoi-mesh.d.ts +101 -0
- package/src/runtime/voronoi-mesh.js +610 -0
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/ascii-noise
|
|
3
|
+
*
|
|
4
|
+
* A field of slow noise drawn as a grid of monospace characters: each cell
|
|
5
|
+
* samples a five-octave gradient noise (quintic fade, a domain warp) at its
|
|
6
|
+
* centre, the value is pushed hard toward empty or full (`contrast`) and
|
|
7
|
+
* picks a character from a ramp, quietest first, so the field reads as
|
|
8
|
+
* soft-edged blobs of type drifting and morphing across the frame. The
|
|
9
|
+
* quiet cells take one colour and the loud ones another, blended in Oklab.
|
|
10
|
+
*
|
|
11
|
+
* Two clocks, both in seconds: the sample window pans (`drift`) and the
|
|
12
|
+
* shapes morph (`evolve`); the warp drifts on its own, more slowly. The
|
|
13
|
+
* same field is here in plain JavaScript (`noiseField`, `asciiCells`), so a
|
|
14
|
+
* page can lay its first frame as text before the shader starts, and the
|
|
15
|
+
* two agree.
|
|
16
|
+
*
|
|
17
|
+
* Clear where the cells are empty (or the `background` colour), so it lays
|
|
18
|
+
* over any ground. A `quiet` area thins the type behind copy. Without
|
|
19
|
+
* WebGL nothing is drawn; with prefers-reduced-motion it is one still frame.
|
|
20
|
+
*
|
|
21
|
+
* After `ascii_noise_bg`, a Processing sketch shared with the owner
|
|
22
|
+
* (2026-11-20): the noise, the warp, the tunings and the ramps are its;
|
|
23
|
+
* here it runs on the GPU, by the second rather than by the frame, with
|
|
24
|
+
* the width as its unit so a tall card and a wide hero sample alike, and
|
|
25
|
+
* its lattice hash is Dave Hoskins' Hash without Sine (MIT, © 2014 David
|
|
26
|
+
* Hoskins), which keeps the GPU and `asciiCells` in step.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { createStage } from './stage.js';
|
|
30
|
+
import { GLSL_GRADIENT_NOISE, GLSL_NOISE_FIELD, noiseField } from './hash-noise.js';
|
|
31
|
+
import { GLSL_OKLAB, parseColor, toOklab } from './color.js';
|
|
32
|
+
import { GLSL_QUIET, quietUniform } from './glsl.js';
|
|
33
|
+
import { GLSL_GLYPHS, GLYPH_SETS, createGlyphs } from './glyphs.js';
|
|
34
|
+
import { watchColors } from './mount.js';
|
|
35
|
+
import { pickColors } from './palettes.js';
|
|
36
|
+
|
|
37
|
+
/** The warped field (./hash-noise.js), as 0.10.0 exported it from here. */
|
|
38
|
+
export { noiseField };
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {object} AsciiNoiseConfig
|
|
42
|
+
* @property {string[]} [colors] Two CSS hex colours: the quietest cells' and the loudest's. Default a dim grey and white.
|
|
43
|
+
* @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`: its first and last colours.
|
|
44
|
+
* @property {string} [background] A CSS hex colour to fill behind the type; none leaves the canvas clear there.
|
|
45
|
+
* @property {string} [glyphs='ascii'] A ramp (`ascii`, `shade`, `digits`, `rise`, `quads`, `bars`, `arrows`,
|
|
46
|
+
* `letters`, `dense`; or a set of GLYPH_SETS) or the characters themselves, quietest first.
|
|
47
|
+
* @property {number} [cell=14] A character cell's height in CSS px.
|
|
48
|
+
* @property {number} [cols] Cells across instead, whatever the width (overrides `cell`).
|
|
49
|
+
* @property {number} [aspect=0.6] A cell's width over its height.
|
|
50
|
+
* @property {number} [scale=2.45] How many noise features span the width (higher is busier).
|
|
51
|
+
* @property {number} [contrast=6] How hard the edges are: higher pushes cells to empty or full.
|
|
52
|
+
* @property {number} [brightness=-0.1] Shifts the whole field; lower leaves more cells empty.
|
|
53
|
+
* @property {[number, number]} [drift=[0.036, 0.012]] How fast the sample window pans, widths a second, x and y.
|
|
54
|
+
* @property {number} [evolve=0.24] How fast the shapes morph.
|
|
55
|
+
* @property {[number, number]} [offset=[0, 0]] Where the sample window starts, so two cards differ.
|
|
56
|
+
* @property {number} [speed=1] Plays every clock faster or slower; 0 for one still frame.
|
|
57
|
+
* @property {{ x?: number, y?: number, radius?: number, depth?: number } | null} [quiet=null]
|
|
58
|
+
* An area kept quiet: centre (0–1 from the top left), radius (share of the height), depth (0–1).
|
|
59
|
+
* @property {string} [font] The font family the glyphs are drawn in (a monospace stack by default); it is loaded first.
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
/** The ramps, each quietest first. A ramp starting with a space leaves quiet cells empty. */
|
|
63
|
+
export const NOISE_RAMPS = {
|
|
64
|
+
/** Punctuation building to `@`. */
|
|
65
|
+
ascii: ' `^",:;!+*#%@',
|
|
66
|
+
/** Shade blocks, never empty: the whole frame is type. */
|
|
67
|
+
shade: '░▒▓█',
|
|
68
|
+
/** Numerals, 1 to 9. */
|
|
69
|
+
digits: ' 123456789',
|
|
70
|
+
/** Blocks rising from the baseline. */
|
|
71
|
+
rise: ' ▁▂▃▄▅▆▇█',
|
|
72
|
+
/** Quadrant blocks, from one corner to all four. */
|
|
73
|
+
quads: ' ▖▗▘▝▚▞▛▙▜▟█',
|
|
74
|
+
/** Bars filling from the left. */
|
|
75
|
+
bars: ' ▏▎▍▌▋▊▉█',
|
|
76
|
+
/** Arrows (the font must have them). */
|
|
77
|
+
arrows: ' ↑↗→↘↓↙←↖↕',
|
|
78
|
+
/** Letters, light to heavy. */
|
|
79
|
+
letters: ' iljtfrvxzcknyuUHPAOEGQDBMWR',
|
|
80
|
+
/** The long classic ramp. */
|
|
81
|
+
dense: " .'`^,:;I}{1)(|OZbkhao*#MW&8%B@$",
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/** The settings' defaults, shared by the shader and `asciiCells`. */
|
|
85
|
+
export const NOISE_DEFAULTS = {
|
|
86
|
+
glyphs: 'ascii',
|
|
87
|
+
scale: 2.45,
|
|
88
|
+
contrast: 6,
|
|
89
|
+
brightness: -0.1,
|
|
90
|
+
drift: /** @type {[number, number]} */ ([0.036, 0.012]),
|
|
91
|
+
evolve: 0.24,
|
|
92
|
+
aspect: 0.6,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/** The default colours: a dim grey for the quiet cells, white for the loud. */
|
|
96
|
+
const GREY = ['#3a3a3a', '#ffffff'];
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* A ramp's characters.
|
|
100
|
+
*
|
|
101
|
+
* @param {string} [glyphs] A ramp's name (NOISE_RAMPS, then GLYPH_SETS) or the characters.
|
|
102
|
+
* @returns {string[]} The characters, quietest first (at least two).
|
|
103
|
+
*/
|
|
104
|
+
export function rampOf(glyphs = NOISE_DEFAULTS.glyphs) {
|
|
105
|
+
const chars = [
|
|
106
|
+
...(NOISE_RAMPS[/** @type {keyof typeof NOISE_RAMPS} */ (glyphs)] ??
|
|
107
|
+
GLYPH_SETS[/** @type {keyof typeof GLYPH_SETS} */ (glyphs)] ??
|
|
108
|
+
glyphs),
|
|
109
|
+
];
|
|
110
|
+
return chars.length > 1 ? chars : [...NOISE_RAMPS.ascii];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const FRAG = `
|
|
114
|
+
precision highp float;
|
|
115
|
+
uniform vec2 uRes;
|
|
116
|
+
uniform vec2 uCell;
|
|
117
|
+
uniform float uTime;
|
|
118
|
+
uniform float uScale;
|
|
119
|
+
uniform float uContrast;
|
|
120
|
+
uniform float uBrightness;
|
|
121
|
+
uniform vec2 uDrift;
|
|
122
|
+
uniform float uEvolve;
|
|
123
|
+
uniform vec2 uOffset;
|
|
124
|
+
uniform vec3 uLo;
|
|
125
|
+
uniform vec3 uHi;
|
|
126
|
+
uniform vec4 uBg;
|
|
127
|
+
${GLSL_OKLAB}
|
|
128
|
+
${GLSL_QUIET}
|
|
129
|
+
${GLSL_GLYPHS}
|
|
130
|
+
${GLSL_GRADIENT_NOISE}
|
|
131
|
+
${GLSL_NOISE_FIELD}
|
|
132
|
+
|
|
133
|
+
void main() {
|
|
134
|
+
// Cells counted from the top left, as the text still lays them.
|
|
135
|
+
vec2 px = vec2(gl_FragCoord.x, uRes.y - gl_FragCoord.y);
|
|
136
|
+
vec2 cell = floor(px / uCell);
|
|
137
|
+
vec2 centre = (cell + 0.5) * uCell;
|
|
138
|
+
// The field in widths, so its features keep their size whatever the shape.
|
|
139
|
+
vec2 p = (centre / uRes.x) * uScale + uOffset + uDrift * uTime;
|
|
140
|
+
float v = noiseField(p, uEvolve * uTime, uTime);
|
|
141
|
+
v = clamp((v - 0.5) * uContrast + 0.5 + uBrightness, 0.0, 1.0);
|
|
142
|
+
vec2 q = vec2(centre.x - 0.5 * uRes.x, 0.5 * uRes.y - centre.y) / uRes.y;
|
|
143
|
+
v *= mix(1.0 - uQuiet.w, 1.0, quietOpen(q));
|
|
144
|
+
float last = uGlyphCount - 1.0;
|
|
145
|
+
float index = min(floor(v * uGlyphCount), last);
|
|
146
|
+
float k = index / last;
|
|
147
|
+
float a = glyph(vec2(fract(px.x / uCell.x), 1.0 - fract(px.y / uCell.y)), k);
|
|
148
|
+
vec3 col = fromOklab(mix(uLo, uHi, k));
|
|
149
|
+
gl_FragColor = vec4(col * a + uBg.rgb * uBg.a * (1.0 - a), a + uBg.a * (1.0 - a));
|
|
150
|
+
}
|
|
151
|
+
`;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* One frame as ramp indices: what the shader draws, cell for cell, on a
|
|
155
|
+
* target exactly `cols` by `rows` cells.
|
|
156
|
+
*
|
|
157
|
+
* @param {AsciiNoiseConfig} config The settings (the same as the shader's).
|
|
158
|
+
* @param {number} cols Cells across.
|
|
159
|
+
* @param {number} rows Cells down.
|
|
160
|
+
* @param {number} [time=0] Seconds, as the shader's clock (already at its speed).
|
|
161
|
+
* @returns {number[][]} Each row's indices into `rampOf(config.glyphs)`.
|
|
162
|
+
*/
|
|
163
|
+
export function asciiCells(config, cols, rows, time = 0) {
|
|
164
|
+
const { scale, contrast, brightness, drift, evolve, aspect } = { ...NOISE_DEFAULTS, ...config };
|
|
165
|
+
const n = rampOf(config.glyphs).length;
|
|
166
|
+
const [ox, oy] = config.offset ?? [0, 0];
|
|
167
|
+
// a cell is 1 wide and 1 / aspect tall; the quiet area is measured as the shader measures it
|
|
168
|
+
const height = rows / aspect;
|
|
169
|
+
const [qx, qy, radius, depth] = quietUniform(config.quiet, cols / height);
|
|
170
|
+
const smooth = (/** @type {number} */ e0, /** @type {number} */ e1, /** @type {number} */ x) => {
|
|
171
|
+
const t = Math.min(1, Math.max(0, (x - e0) / (e1 - e0)));
|
|
172
|
+
return t * t * (3 - 2 * t);
|
|
173
|
+
};
|
|
174
|
+
return Array.from({ length: rows }, (_, r) =>
|
|
175
|
+
Array.from({ length: cols }, (_, c) => {
|
|
176
|
+
const cx = c + 0.5;
|
|
177
|
+
const cy = (r + 0.5) / aspect;
|
|
178
|
+
let v = noiseField((cx / cols) * scale + ox + drift[0] * time, (cy / cols) * scale + oy + drift[1] * time, evolve * time, time);
|
|
179
|
+
v = Math.min(1, Math.max(0, (v - 0.5) * contrast + 0.5 + brightness));
|
|
180
|
+
if (radius > 0) {
|
|
181
|
+
const d = Math.hypot((cx - cols / 2) / height - qx, (height / 2 - cy) / height - qy);
|
|
182
|
+
v *= 1 - depth + depth * smooth(radius * 0.06, radius, d);
|
|
183
|
+
}
|
|
184
|
+
return Math.min(Math.floor(v * n), n - 1);
|
|
185
|
+
}),
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* The two colours as the shader takes them.
|
|
191
|
+
*
|
|
192
|
+
* @param {AsciiNoiseConfig} config The settings.
|
|
193
|
+
* @returns {[string, string]} The quietest cells' colour and the loudest's.
|
|
194
|
+
*/
|
|
195
|
+
export function noiseColors(config) {
|
|
196
|
+
const colors = pickColors(config, GREY);
|
|
197
|
+
return [colors[0], colors[colors.length - 1]];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Starts the noise on an element: a canvas inside it (its first), filling
|
|
202
|
+
* it. With a `font`, the font is loaded before the glyphs are drawn.
|
|
203
|
+
*
|
|
204
|
+
* @param {HTMLElement} el The element.
|
|
205
|
+
* @param {AsciiNoiseConfig} config The settings.
|
|
206
|
+
* @returns {() => void} Stops it.
|
|
207
|
+
*/
|
|
208
|
+
export function asciiNoise(el, config) {
|
|
209
|
+
let stop = () => {};
|
|
210
|
+
let stopped = false;
|
|
211
|
+
const ramp = rampOf(config.glyphs);
|
|
212
|
+
/** Starts the stage, unless it was stopped while the font loaded. */
|
|
213
|
+
const begin = () => {
|
|
214
|
+
if (!stopped) stop = run(el, config, ramp);
|
|
215
|
+
};
|
|
216
|
+
if (config.font && typeof document !== 'undefined' && document.fonts) document.fonts.load(`48px ${config.font}`, ramp.join('')).then(begin, begin);
|
|
217
|
+
else begin();
|
|
218
|
+
return () => {
|
|
219
|
+
stopped = true;
|
|
220
|
+
stop();
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* The stage itself, once the font is ready.
|
|
226
|
+
*
|
|
227
|
+
* @param {HTMLElement} el The element.
|
|
228
|
+
* @param {AsciiNoiseConfig} config The settings.
|
|
229
|
+
* @param {string[]} ramp The characters.
|
|
230
|
+
* @returns {() => void} Stops it.
|
|
231
|
+
*/
|
|
232
|
+
function run(el, config, ramp) {
|
|
233
|
+
const o = { ...NOISE_DEFAULTS, ...config };
|
|
234
|
+
const speed = config.speed ?? 1;
|
|
235
|
+
const lab = (/** @type {string} */ c) => toOklab(parseColor(c));
|
|
236
|
+
let [lo, hi] = noiseColors(config).map(lab);
|
|
237
|
+
const bg = config.background ? [...parseColor(config.background), 1] : [0, 0, 0, 0];
|
|
238
|
+
const start = performance.now();
|
|
239
|
+
|
|
240
|
+
const { stage, stop } = createStage(el, {
|
|
241
|
+
fragment: FRAG,
|
|
242
|
+
still: speed <= 0,
|
|
243
|
+
setup({ gl, uniform }) {
|
|
244
|
+
const { count } = createGlyphs(gl, ramp.join(''), { unit: 0, font: config.font, aspect: o.aspect });
|
|
245
|
+
gl.uniform1i(uniform('uGlyphs'), 0);
|
|
246
|
+
gl.uniform1f(uniform('uGlyphCount'), count);
|
|
247
|
+
gl.uniform1f(uniform('uScale'), o.scale);
|
|
248
|
+
gl.uniform1f(uniform('uContrast'), o.contrast);
|
|
249
|
+
gl.uniform1f(uniform('uBrightness'), o.brightness);
|
|
250
|
+
gl.uniform2f(uniform('uDrift'), o.drift[0], o.drift[1]);
|
|
251
|
+
gl.uniform1f(uniform('uEvolve'), o.evolve);
|
|
252
|
+
gl.uniform2f(uniform('uOffset'), ...(config.offset ?? [0, 0]));
|
|
253
|
+
gl.uniform4f(uniform('uBg'), bg[0], bg[1], bg[2], bg[3]);
|
|
254
|
+
},
|
|
255
|
+
resize({ gl, uniform, canvas, ratio }) {
|
|
256
|
+
const w = config.cols ? canvas.width / config.cols : (config.cell ?? 14) * ratio * o.aspect;
|
|
257
|
+
gl.uniform2f(uniform('uCell'), w, w / o.aspect);
|
|
258
|
+
gl.uniform4f(uniform('uQuiet'), ...quietUniform(config.quiet, canvas.width / canvas.height));
|
|
259
|
+
},
|
|
260
|
+
uniforms({ gl, uniform }, now) {
|
|
261
|
+
gl.uniform1f(uniform('uTime'), ((now - start) / 1000) * Math.max(0, speed));
|
|
262
|
+
gl.uniform3f(uniform('uLo'), lo[0], lo[1], lo[2]);
|
|
263
|
+
gl.uniform3f(uniform('uHi'), hi[0], hi[1], hi[2]);
|
|
264
|
+
},
|
|
265
|
+
});
|
|
266
|
+
if (!stage) return stop;
|
|
267
|
+
|
|
268
|
+
const unwatch = watchColors(el, (next) => {
|
|
269
|
+
[lo, hi] = noiseColors({ colors: next.colors }).map(lab);
|
|
270
|
+
if (stage.still) stage.redraw();
|
|
271
|
+
});
|
|
272
|
+
return () => {
|
|
273
|
+
stop();
|
|
274
|
+
unwatch();
|
|
275
|
+
};
|
|
276
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { PaletteName } from './palettes.js';
|
|
2
|
+
|
|
3
|
+
export interface CascadeGridConfig {
|
|
4
|
+
/** The cells: staggered pointy-top hexagons, or dots on a square grid. Default `hex`. */
|
|
5
|
+
cell?: 'hex' | 'dot';
|
|
6
|
+
/** A cell's width in CSS px. Default 16. */
|
|
7
|
+
pitch?: number;
|
|
8
|
+
/** Cells across instead, whatever the width (overrides `pitch`). */
|
|
9
|
+
cols?: number;
|
|
10
|
+
/** Two CSS hex colours: an idle cell's and a reactive one's. Default the sketch's grey and green. */
|
|
11
|
+
colors?: string[];
|
|
12
|
+
/** A shared palette by name (`PALETTES`, any case), when there are no `colors`: its last and first colours. */
|
|
13
|
+
palette?: PaletteName | (string & {});
|
|
14
|
+
/** A CSS hex colour to fill behind the cells; none leaves the canvas clear there. */
|
|
15
|
+
background?: string;
|
|
16
|
+
/** An idle cell's size, a share of the cell (0–1). Default 0.12 for hexagons, 0.14 for dots. */
|
|
17
|
+
idle?: number;
|
|
18
|
+
/** A reactive cell's size, a share of the cell (0–1; 1 is flush). Default 0.92 for hexagons, 0.9 for dots. */
|
|
19
|
+
reactive?: number;
|
|
20
|
+
/** How a cell is drawn: filled, outlined, or outlined around a solid core that grows with its level. Default `core` for hexagons, `solid` for dots. */
|
|
21
|
+
fill?: 'solid' | 'outline' | 'core';
|
|
22
|
+
/** The outline's width, idle and reactive, a share of the cell (0–0.5). Default [0.06, 0.12]. */
|
|
23
|
+
stroke?: [number, number];
|
|
24
|
+
/** A cell's opacity, idle and reactive (0–1). Default [0.5, 1]. */
|
|
25
|
+
opacity?: [number, number];
|
|
26
|
+
/** Seconds between one column and the next: the wave crosses `1 / lag` columns a second. Default 0.06. */
|
|
27
|
+
lag?: number;
|
|
28
|
+
/** How fast the spectrum changes, noise units a second. Default 0.6. */
|
|
29
|
+
evolve?: number;
|
|
30
|
+
/** Noise units a row: higher makes the bands narrower. Default 0.12. */
|
|
31
|
+
scale?: number;
|
|
32
|
+
/** The noise window stretched to 0–1: a lower top makes more cells reactive. Default [0.3, 0.75]. */
|
|
33
|
+
range?: [number, number];
|
|
34
|
+
/** How much busier the low rows are (0–1): the bottom row gets it all, the middle none. Default 0.35. */
|
|
35
|
+
tilt?: number;
|
|
36
|
+
/** Which way the wave travels. Up and down make the columns the spectrum, busier at the left. Default `right`. */
|
|
37
|
+
direction?: 'right' | 'left' | 'up' | 'down';
|
|
38
|
+
/** Where the noise starts (a number, or a band and a time shift), so two grids differ. Default 0. */
|
|
39
|
+
offset?: number | [number, number];
|
|
40
|
+
/** Plays the clock faster or slower; 0 for one still frame. Default 1. */
|
|
41
|
+
speed?: number;
|
|
42
|
+
/** An area kept calm: centre (0–1 from the top left), radius (share of the height), depth (0–1). */
|
|
43
|
+
quiet?: { x?: number; y?: number; radius?: number; depth?: number } | null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The settings with every default filled in, as the shader takes them. */
|
|
47
|
+
export interface CascadeOptions {
|
|
48
|
+
cell: 'hex' | 'dot';
|
|
49
|
+
pitch: number;
|
|
50
|
+
idle: number;
|
|
51
|
+
reactive: number;
|
|
52
|
+
fill: 'solid' | 'outline' | 'core';
|
|
53
|
+
stroke: [number, number];
|
|
54
|
+
opacity: [number, number];
|
|
55
|
+
lag: number;
|
|
56
|
+
evolve: number;
|
|
57
|
+
scale: number;
|
|
58
|
+
range: [number, number];
|
|
59
|
+
tilt: number;
|
|
60
|
+
direction: 'right' | 'left' | 'up' | 'down';
|
|
61
|
+
offset: [number, number];
|
|
62
|
+
speed?: number;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The settings' defaults, shared by the shader and the JavaScript twins (`idle`, `reactive` and `fill` depend on the cell). */
|
|
66
|
+
export declare const CASCADE_DEFAULTS: {
|
|
67
|
+
cell: 'hex' | 'dot';
|
|
68
|
+
pitch: number;
|
|
69
|
+
stroke: [number, number];
|
|
70
|
+
opacity: [number, number];
|
|
71
|
+
lag: number;
|
|
72
|
+
evolve: number;
|
|
73
|
+
scale: number;
|
|
74
|
+
range: [number, number];
|
|
75
|
+
tilt: number;
|
|
76
|
+
direction: 'right' | 'left' | 'up' | 'down';
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/** Each cell's own defaults: an idle and a reactive size, and how it is drawn. */
|
|
80
|
+
export declare const CELL_DEFAULTS: {
|
|
81
|
+
hex: { idle: number; reactive: number; fill: 'solid' | 'outline' | 'core' };
|
|
82
|
+
dot: { idle: number; reactive: number; fill: 'solid' | 'outline' | 'core' };
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** The settings with every default filled in, the cell's own included. */
|
|
86
|
+
export declare function cascadeOptions(config?: CascadeGridConfig): CascadeOptions;
|
|
87
|
+
|
|
88
|
+
/** A band's level at a moment, 0–1, before the quiet area: `cascadeLevel(a, b + 1, h, t + lag)` equals `cascadeLevel(a, b, h, t)`. */
|
|
89
|
+
export declare function cascadeLevel(a: number, b: number, h: number, t: number, config?: CascadeGridConfig): number;
|
|
90
|
+
|
|
91
|
+
/** The lattice's spacing on a target: a cell's width and a row's height. */
|
|
92
|
+
export declare function latticeOf(config: CascadeGridConfig, width: number, ratio?: number): { pitch: number; rowHeight: number };
|
|
93
|
+
|
|
94
|
+
/** The cell a point is in (x from the left edge, y down from the middle row), and its centre. */
|
|
95
|
+
export declare function latticeCell(cell: 'hex' | 'dot', x: number, y: number, pitch: number): { col: number; row: number; x: number; y: number };
|
|
96
|
+
|
|
97
|
+
/** One frame, cell by cell: each cell's centre (from the top left) and its level, the quiet area included. */
|
|
98
|
+
export declare function cascadeCells(
|
|
99
|
+
config: CascadeGridConfig,
|
|
100
|
+
width: number,
|
|
101
|
+
height: number,
|
|
102
|
+
time?: number,
|
|
103
|
+
): { col: number; row: number; x: number; y: number; level: number }[];
|
|
104
|
+
|
|
105
|
+
/** The two colours as the shader takes them: an idle cell's and a reactive one's. */
|
|
106
|
+
export declare function cascadeColors(config: CascadeGridConfig): [string, string];
|
|
107
|
+
|
|
108
|
+
/** A CSS `background` showing the grid at rest (idle cells over the `background` colour), for before the shader starts and without WebGL. */
|
|
109
|
+
export declare function cascadeStill(config: CascadeGridConfig, width?: number): string;
|
|
110
|
+
|
|
111
|
+
/** Starts the grid on an element (its first canvas is drawn into). Returns a function that stops it. */
|
|
112
|
+
export declare function cascadeGrid(el: HTMLElement, config: CascadeGridConfig): () => void;
|