@arraypress/effects-astro 0.10.0 → 0.12.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 +214 -10
- package/LICENSE +2 -2
- package/package.json +1 -1
- package/src/components/CascadeGrid.astro +41 -0
- package/src/components/DitherField.astro +41 -0
- package/src/components/DitherGradient.astro +41 -0
- package/src/components/FlowField.astro +38 -0
- package/src/components/FlutedGlow.astro +39 -0
- package/src/components/KineticGrid.astro +38 -0
- package/src/components/LightLeak.astro +39 -0
- package/src/components/PixelFountain.astro +20 -7
- package/src/components/PixelGlitchText.astro +4 -3
- package/src/components/PixelHorizon.astro +40 -0
- package/src/components/TruchetField.astro +40 -0
- package/src/components/VoronoiMesh.astro +39 -0
- package/src/index.d.ts +23 -1
- package/src/index.js +13 -1
- package/src/runtime/ascii-noise.js +6 -107
- package/src/runtime/bayer.d.ts +5 -0
- package/src/runtime/bayer.js +48 -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 +416 -0
- package/src/runtime/dither-gradient.d.ts +91 -0
- package/src/runtime/dither-gradient.js +410 -0
- package/src/runtime/flow-field.d.ts +117 -0
- package/src/runtime/flow-field.js +516 -0
- package/src/runtime/fluted-glow.d.ts +79 -0
- package/src/runtime/fluted-glow.js +312 -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/pixel-fountain.d.ts +29 -13
- package/src/runtime/pixel-fountain.js +183 -42
- package/src/runtime/pixel-glitch.d.ts +2 -0
- package/src/runtime/pixel-glitch.js +8 -2
- package/src/runtime/pixel-horizon.d.ts +60 -0
- package/src/runtime/pixel-horizon.js +274 -0
- package/src/runtime/truchet-field.d.ts +60 -0
- package/src/runtime/truchet-field.js +272 -0
- package/src/runtime/voronoi-mesh.d.ts +101 -0
- package/src/runtime/voronoi-mesh.js +610 -0
|
@@ -9,19 +9,31 @@
|
|
|
9
9
|
* fires a stream, a click or tap a power-up. See
|
|
10
10
|
* src/runtime/pixel-fountain.js.
|
|
11
11
|
*
|
|
12
|
+
* With `source="pointer"`, blocks fire only where the pointer is, as it
|
|
13
|
+
* moves over the host: a block-dust trail off the cursor, in one solid ink
|
|
14
|
+
* (the text's colour, or `color`), that pops up, arcs and breaks down within
|
|
15
|
+
* about a second. Nothing on its own, nothing while the pointer rests; a
|
|
16
|
+
* tap fires a burst where it lands (a click too with `press`).
|
|
17
|
+
*
|
|
12
18
|
* Put it inside the host (its nearest positioned ancestor): the canvas sits
|
|
13
19
|
* above the host's top edge, `rise` px tall (over the host and above it
|
|
14
|
-
* with `source="text"`), so the host must not clip its top (no
|
|
20
|
+
* with `source="text"` or `"pointer"`), so the host must not clip its top (no
|
|
15
21
|
* `overflow: hidden`; `overflow-x: clip` is fine). Or put it in a
|
|
16
22
|
* zero-height positioned strip on the host's top edge and name the host
|
|
17
23
|
* with `host`. The canvas takes no pointer events; the host's are read.
|
|
18
|
-
* With reduced motion, a still scatter of pixels.
|
|
24
|
+
* With reduced motion, a still scatter of pixels (nothing from the pointer).
|
|
19
25
|
*
|
|
20
26
|
* @example
|
|
21
27
|
* <footer class="site-footer" style="position: relative">
|
|
22
28
|
* <PixelFountain cell={8} />
|
|
23
29
|
* …
|
|
24
30
|
* </footer>
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* <div class="wordmark-wrap" style="position: relative; color: #0b0b0b">
|
|
34
|
+
* <PixelFountain source="pointer" cell={10} />
|
|
35
|
+
* <FitText as="div">Arcadia</FitText>
|
|
36
|
+
* </div>
|
|
25
37
|
*/
|
|
26
38
|
import EffectCanvas from './EffectCanvas.astro';
|
|
27
39
|
import type { PixelFountainConfig } from '../runtime/pixel-fountain.js';
|
|
@@ -35,9 +47,10 @@ interface Props extends PixelFountainConfig {
|
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
const { zIndex, lazy = false, class: className, ...config } = Astro.props;
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const
|
|
50
|
+
const pointer = config.source === 'pointer';
|
|
51
|
+
const rise = config.rise ?? (pointer ? 160 : 240);
|
|
52
|
+
const over = config.source === 'text' || pointer;
|
|
53
|
+
const classes = ['effect-pixel-fountain', over && 'is-over', className].filter(Boolean).join(' ');
|
|
41
54
|
---
|
|
42
55
|
|
|
43
56
|
<EffectCanvas
|
|
@@ -62,8 +75,8 @@ const classes = ['effect-pixel-fountain', text && 'is-text', className].filter(B
|
|
|
62
75
|
inset: auto 0 100% 0;
|
|
63
76
|
height: var(--fountain-rise);
|
|
64
77
|
}
|
|
65
|
-
/* From the text: over the host and the space above it. */
|
|
66
|
-
:global(.effect-canvas.effect-pixel-fountain.is-
|
|
78
|
+
/* From the text or the pointer: over the host and the space above it. */
|
|
79
|
+
:global(.effect-canvas.effect-pixel-fountain.is-over[data-effect-pixel-fountain]) {
|
|
67
80
|
inset: auto 0 0 0;
|
|
68
81
|
height: calc(100% + var(--fountain-rise));
|
|
69
82
|
}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* PixelGlitchText: one line of text that breaks into pixels under the
|
|
4
4
|
* pointer and knits back together behind it. With `stroke`, a hollow
|
|
5
5
|
* outline at rest that the pixels fill in; `tear="row"` tears whole rows,
|
|
6
|
-
* and `ghost` lays a coloured copy behind the blocks
|
|
6
|
+
* and `ghost` lays a coloured copy behind the blocks; `glitch={false}`
|
|
7
|
+
* keeps only the drawing at rest (a still outlined wordmark). See
|
|
7
8
|
* src/runtime/pixel-glitch.js.
|
|
8
9
|
*
|
|
9
10
|
* With `fit`, the text is sized to span its parent's width (a footer
|
|
@@ -27,13 +28,13 @@ interface Props extends PixelGlitchConfig {
|
|
|
27
28
|
[attribute: string]: unknown;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
const { as: Tag = 'span', fit = false, cell, reach, decay, block, shift, stroke, tear, ghost, class: className, style: given, ...attributes } = Astro.props;
|
|
31
|
+
const { as: Tag = 'span', fit = false, cell, reach, decay, block, shift, stroke, tear, ghost, glitch, class: className, style: given, ...attributes } = Astro.props;
|
|
31
32
|
---
|
|
32
33
|
|
|
33
34
|
<Tag
|
|
34
35
|
class:list={['effect-pixel-glitch', { 'is-outline': (stroke ?? 0) > 0 }, className]}
|
|
35
36
|
data-effect-pixel-glitch
|
|
36
|
-
data-effect-config={JSON.stringify({ cell, reach, decay, block, shift, stroke, tear, ghost })}
|
|
37
|
+
data-effect-config={JSON.stringify({ cell, reach, decay, block, shift, stroke, tear, ghost, glitch })}
|
|
37
38
|
data-fit-text={fit ? '' : undefined}
|
|
38
39
|
style={withStyle(stroke ? `--glitch-stroke: ${stroke}px` : undefined, given)}
|
|
39
40
|
{...attributes}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* PixelHorizon: a flat colour filling one side and breaking up into square
|
|
4
|
+
* blocks toward the other, blocks winking on and off along a slowly
|
|
5
|
+
* swaying frontier. See src/runtime/pixel-horizon.js.
|
|
6
|
+
*
|
|
7
|
+
* Fills its nearest positioned ancestor, or the viewport with `fixed`.
|
|
8
|
+
* Clear where there is nothing drawn, so it lays over any ground; with a
|
|
9
|
+
* `background`, the element shows a CSS still until the shader starts and
|
|
10
|
+
* without WebGL.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* <section class="hero" style="position: relative; background: #0b0b0b">
|
|
14
|
+
* <PixelHorizon background="#0b0b0b" colors={['#1aff00']} side="bottom" quiet={{ radius: 0.42, depth: 1 }} />
|
|
15
|
+
* <h1>…</h1>
|
|
16
|
+
* </section>
|
|
17
|
+
*/
|
|
18
|
+
import EffectCanvas from './EffectCanvas.astro';
|
|
19
|
+
import { horizonStill, type PixelHorizonConfig } from '../runtime/pixel-horizon.js';
|
|
20
|
+
|
|
21
|
+
interface Props extends PixelHorizonConfig {
|
|
22
|
+
/** Fill the viewport (position: fixed). Default false. */
|
|
23
|
+
fixed?: boolean;
|
|
24
|
+
/** Run only while near the screen (true, or how near as a CSS length), giving its WebGL context back when away: for pages with many effects. Default false. */
|
|
25
|
+
lazy?: boolean | string;
|
|
26
|
+
class?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { fixed = false, lazy = false, class: className, ...config } = Astro.props;
|
|
30
|
+
const still = config.background ? horizonStill(config) : undefined;
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
<EffectCanvas name="pixel-horizon" config={config} fixed={fixed} lazy={lazy} background={still} pixelated class={className} />
|
|
34
|
+
|
|
35
|
+
<script>
|
|
36
|
+
import { mount } from '../runtime/mount.js';
|
|
37
|
+
import { pixelHorizon } from '../runtime/pixel-horizon.js';
|
|
38
|
+
|
|
39
|
+
mount('[data-effect-pixel-horizon]', pixelHorizon);
|
|
40
|
+
</script>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* TruchetField: a field of Truchet tiles, quarter arcs that join into
|
|
4
|
+
* loops and S-bends, a few tiles turning at a time, bright patches
|
|
5
|
+
* drifting through. See src/runtime/truchet-field.js.
|
|
6
|
+
*
|
|
7
|
+
* Fills its nearest positioned ancestor, or the viewport with `fixed`.
|
|
8
|
+
* Clear where there is nothing drawn, so it lays over any ground; with a
|
|
9
|
+
* `background`, the element shows a CSS still until the shader starts and
|
|
10
|
+
* without WebGL.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* <section class="hero" style="position: relative; background: #0b0b0b">
|
|
14
|
+
* <TruchetField background="#0b0b0b" colors={['#3a3a3a', '#f4f3ef']} quiet={{ radius: 0.5, depth: 0.9 }} />
|
|
15
|
+
* <h1>…</h1>
|
|
16
|
+
* </section>
|
|
17
|
+
*/
|
|
18
|
+
import EffectCanvas from './EffectCanvas.astro';
|
|
19
|
+
import { truchetStill, type TruchetFieldConfig } from '../runtime/truchet-field.js';
|
|
20
|
+
|
|
21
|
+
interface Props extends TruchetFieldConfig {
|
|
22
|
+
/** Fill the viewport (position: fixed). Default false. */
|
|
23
|
+
fixed?: boolean;
|
|
24
|
+
/** Run only while near the screen (true, or how near as a CSS length), giving its WebGL context back when away: for pages with many effects. Default false. */
|
|
25
|
+
lazy?: boolean | string;
|
|
26
|
+
class?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const { fixed = false, lazy = false, class: className, ...config } = Astro.props;
|
|
30
|
+
const still = config.background ? truchetStill(config) : undefined;
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
<EffectCanvas name="truchet-field" config={config} fixed={fixed} lazy={lazy} background={still} class={className} />
|
|
34
|
+
|
|
35
|
+
<script>
|
|
36
|
+
import { mount } from '../runtime/mount.js';
|
|
37
|
+
import { truchetField } from '../runtime/truchet-field.js';
|
|
38
|
+
|
|
39
|
+
mount('[data-effect-truchet-field]', truchetField);
|
|
40
|
+
</script>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* VoronoiMesh: a Voronoi mesh in thin lines on a ground, in two nested
|
|
4
|
+
* tiers: macro cells whose seeds orbit slowly, and inner cells inside each
|
|
5
|
+
* that pulse outward from its seed. Pale lines on deep maroon by default.
|
|
6
|
+
* See src/runtime/voronoi-mesh.js.
|
|
7
|
+
*
|
|
8
|
+
* Fills its nearest positioned ancestor, or the viewport with `fixed`.
|
|
9
|
+
* Opaque (its `background`), which the element shows before the shader
|
|
10
|
+
* starts and without WebGL; `meshStill` in the runtime makes an SVG still
|
|
11
|
+
* of the same frame for a box of known size (a card).
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* <section class="hero" style="position: relative">
|
|
15
|
+
* <VoronoiMesh cells={8} quiet={{ x: 0.3, y: 0.5, radius: 0.7, depth: 0.8 }} />
|
|
16
|
+
* <h1>…</h1>
|
|
17
|
+
* </section>
|
|
18
|
+
*/
|
|
19
|
+
import EffectCanvas from './EffectCanvas.astro';
|
|
20
|
+
import { MESH_DEFAULTS, type VoronoiMeshConfig } from '../runtime/voronoi-mesh.js';
|
|
21
|
+
|
|
22
|
+
interface Props extends VoronoiMeshConfig {
|
|
23
|
+
/** Fill the viewport (position: fixed). Default false. */
|
|
24
|
+
fixed?: boolean;
|
|
25
|
+
class?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const { fixed = false, class: className, ...config } = Astro.props;
|
|
29
|
+
const ground = config.background ?? MESH_DEFAULTS.background;
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
<EffectCanvas name="voronoi-mesh" config={config} fixed={fixed} background={ground} class={className} />
|
|
33
|
+
|
|
34
|
+
<script>
|
|
35
|
+
import { mount } from '../runtime/mount.js';
|
|
36
|
+
import { voronoiMesh } from '../runtime/voronoi-mesh.js';
|
|
37
|
+
|
|
38
|
+
mount('[data-effect-voronoi-mesh]', voronoiMesh);
|
|
39
|
+
</script>
|
package/src/index.d.ts
CHANGED
|
@@ -8,6 +8,28 @@ export { asciiRain } from './runtime/ascii-rain.js';
|
|
|
8
8
|
export type { AsciiRainConfig } from './runtime/ascii-rain.js';
|
|
9
9
|
export { asciiNoise, asciiCells, noiseField, noiseColors, rampOf, NOISE_RAMPS, NOISE_DEFAULTS } from './runtime/ascii-noise.js';
|
|
10
10
|
export type { AsciiNoiseConfig } from './runtime/ascii-noise.js';
|
|
11
|
+
export { lightLeak, lightLeakStill } from './runtime/light-leak.js';
|
|
12
|
+
export { ditherField, ditherStill } from './runtime/dither-field.js';
|
|
13
|
+
export { cascadeGrid, cascadeStill } from './runtime/cascade-grid.js';
|
|
14
|
+
export { flowField } from './runtime/flow-field.js';
|
|
15
|
+
export { voronoiMesh, meshStill } from './runtime/voronoi-mesh.js';
|
|
16
|
+
export { kineticGrid, gridStill } from './runtime/kinetic-grid.js';
|
|
17
|
+
export { hash33, grad, gnoise, GLSL_HASH33, GLSL_GRADIENT_NOISE, GLSL_NOISE_FIELD } from './runtime/hash-noise.js';
|
|
18
|
+
export { ditherGradient, gradientStill } from './runtime/dither-gradient.js';
|
|
19
|
+
export { truchetField, truchetStill } from './runtime/truchet-field.js';
|
|
20
|
+
export { pixelHorizon, horizonStill } from './runtime/pixel-horizon.js';
|
|
21
|
+
export { flutedGlow, glowStill } from './runtime/fluted-glow.js';
|
|
22
|
+
export { bayer, GLSL_BAYER } from './runtime/bayer.js';
|
|
23
|
+
export type { DitherGradientConfig } from './runtime/dither-gradient.js';
|
|
24
|
+
export type { TruchetFieldConfig } from './runtime/truchet-field.js';
|
|
25
|
+
export type { PixelHorizonConfig } from './runtime/pixel-horizon.js';
|
|
26
|
+
export type { FlutedGlowConfig } from './runtime/fluted-glow.js';
|
|
27
|
+
export type { LightLeakConfig } from './runtime/light-leak.js';
|
|
28
|
+
export type { DitherFieldConfig } from './runtime/dither-field.js';
|
|
29
|
+
export type { CascadeGridConfig } from './runtime/cascade-grid.js';
|
|
30
|
+
export type { FlowFieldConfig } from './runtime/flow-field.js';
|
|
31
|
+
export type { VoronoiMeshConfig } from './runtime/voronoi-mesh.js';
|
|
32
|
+
export type { KineticGridConfig } from './runtime/kinetic-grid.js';
|
|
11
33
|
export { glassGlyph } from './runtime/glass-glyph.js';
|
|
12
34
|
export type { GlassGlyphConfig } from './runtime/glass-glyph.js';
|
|
13
35
|
export { flutedGlass } from './runtime/fluted-glass.js';
|
|
@@ -20,7 +42,7 @@ export { voxelLogo } from './runtime/voxel-logo.js';
|
|
|
20
42
|
export type { VoxelLogoConfig } from './runtime/voxel-logo.js';
|
|
21
43
|
export { pixelGlitch, outlineAlpha, rowTears } from './runtime/pixel-glitch.js';
|
|
22
44
|
export type { PixelGlitchConfig } from './runtime/pixel-glitch.js';
|
|
23
|
-
export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS } from './runtime/pixel-fountain.js';
|
|
45
|
+
export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS, TRAIL_CAP, POINTER_DEFAULTS } from './runtime/pixel-fountain.js';
|
|
24
46
|
export type { PixelFountainConfig, Pixel, EmitKind, FountainOptions, Fountain } from './runtime/pixel-fountain.js';
|
|
25
47
|
export { fit, fitText } from './runtime/fit-text.js';
|
|
26
48
|
export { textNodes, textRange, splitLetters, joinLetters, textNodesWithin, paintGlyphs } from './runtime/text.js';
|
package/src/index.js
CHANGED
|
@@ -16,13 +16,25 @@ export { ink } from './runtime/ink.js';
|
|
|
16
16
|
export { spotlight } from './runtime/spotlight.js';
|
|
17
17
|
export { asciiRain } from './runtime/ascii-rain.js';
|
|
18
18
|
export { asciiNoise, asciiCells, noiseField, noiseColors, rampOf, NOISE_RAMPS, NOISE_DEFAULTS } from './runtime/ascii-noise.js';
|
|
19
|
+
export { lightLeak, lightLeakStill } from './runtime/light-leak.js';
|
|
20
|
+
export { ditherField, ditherStill } from './runtime/dither-field.js';
|
|
21
|
+
export { cascadeGrid, cascadeStill } from './runtime/cascade-grid.js';
|
|
22
|
+
export { flowField } from './runtime/flow-field.js';
|
|
23
|
+
export { voronoiMesh, meshStill } from './runtime/voronoi-mesh.js';
|
|
24
|
+
export { kineticGrid, gridStill } from './runtime/kinetic-grid.js';
|
|
25
|
+
export { hash33, grad, gnoise, GLSL_HASH33, GLSL_GRADIENT_NOISE, GLSL_NOISE_FIELD } from './runtime/hash-noise.js';
|
|
26
|
+
export { ditherGradient, gradientStill } from './runtime/dither-gradient.js';
|
|
27
|
+
export { truchetField, truchetStill } from './runtime/truchet-field.js';
|
|
28
|
+
export { pixelHorizon, horizonStill } from './runtime/pixel-horizon.js';
|
|
29
|
+
export { flutedGlow, glowStill } from './runtime/fluted-glow.js';
|
|
30
|
+
export { bayer, GLSL_BAYER } from './runtime/bayer.js';
|
|
19
31
|
export { glassGlyph } from './runtime/glass-glyph.js';
|
|
20
32
|
export { flutedGlass } from './runtime/fluted-glass.js';
|
|
21
33
|
export { particleLogo } from './runtime/particle-logo.js';
|
|
22
34
|
export { pointCloud } from './runtime/point-cloud.js';
|
|
23
35
|
export { voxelLogo } from './runtime/voxel-logo.js';
|
|
24
36
|
export { pixelGlitch, outlineAlpha, rowTears } from './runtime/pixel-glitch.js';
|
|
25
|
-
export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS } from './runtime/pixel-fountain.js';
|
|
37
|
+
export { pixelFountain, createFountain, fadeSteps, shadeAt, tierSizes, pixelRect, inkedCells, MAX_PIXELS, TRAIL_CAP, POINTER_DEFAULTS } from './runtime/pixel-fountain.js';
|
|
26
38
|
export { fit, fitText } from './runtime/fit-text.js';
|
|
27
39
|
export { textNodes, textRange, splitLetters, joinLetters, textNodesWithin, paintGlyphs } from './runtime/text.js';
|
|
28
40
|
export { variableType, DEFAULT_AXES } from './runtime/variable-type.js';
|
|
@@ -27,12 +27,16 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import { createStage } from './stage.js';
|
|
30
|
+
import { GLSL_GRADIENT_NOISE, GLSL_NOISE_FIELD, noiseField } from './hash-noise.js';
|
|
30
31
|
import { GLSL_OKLAB, parseColor, toOklab } from './color.js';
|
|
31
32
|
import { GLSL_QUIET, quietUniform } from './glsl.js';
|
|
32
33
|
import { GLSL_GLYPHS, GLYPH_SETS, createGlyphs } from './glyphs.js';
|
|
33
34
|
import { watchColors } from './mount.js';
|
|
34
35
|
import { pickColors } from './palettes.js';
|
|
35
36
|
|
|
37
|
+
/** The warped field (./hash-noise.js), as 0.10.0 exported it from here. */
|
|
38
|
+
export { noiseField };
|
|
39
|
+
|
|
36
40
|
/**
|
|
37
41
|
* @typedef {object} AsciiNoiseConfig
|
|
38
42
|
* @property {string[]} [colors] Two CSS hex colours: the quietest cells' and the loudest's. Default a dim grey and white.
|
|
@@ -106,42 +110,6 @@ export function rampOf(glyphs = NOISE_DEFAULTS.glyphs) {
|
|
|
106
110
|
return chars.length > 1 ? chars : [...NOISE_RAMPS.ascii];
|
|
107
111
|
}
|
|
108
112
|
|
|
109
|
-
/**
|
|
110
|
-
* GLSL (ES 1.00): `float noiseField(vec2 p, float evo, float wt)`, the
|
|
111
|
-
* warped five-octave gradient noise, 0–1. `noiseField` below is the same
|
|
112
|
-
* in JavaScript.
|
|
113
|
-
*/
|
|
114
|
-
const GLSL_FIELD = `
|
|
115
|
-
vec2 grad(vec2 p) {
|
|
116
|
-
vec3 p3 = fract(vec3(p.xyx) * vec3(0.1031, 0.1030, 0.0973));
|
|
117
|
-
p3 += dot(p3, p3.yzx + 33.33);
|
|
118
|
-
return -1.0 + 2.0 * fract((p3.xx + p3.yz) * p3.zy);
|
|
119
|
-
}
|
|
120
|
-
float gnoise(vec2 p) {
|
|
121
|
-
vec2 i = floor(p);
|
|
122
|
-
vec2 f = p - i;
|
|
123
|
-
vec2 u = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);
|
|
124
|
-
float a = dot(grad(i), f);
|
|
125
|
-
float b = dot(grad(i + vec2(1.0, 0.0)), f - vec2(1.0, 0.0));
|
|
126
|
-
float c = dot(grad(i + vec2(0.0, 1.0)), f - vec2(0.0, 1.0));
|
|
127
|
-
float d = dot(grad(i + vec2(1.0, 1.0)), f - vec2(1.0, 1.0));
|
|
128
|
-
return 0.5 + 0.5 * mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
|
|
129
|
-
}
|
|
130
|
-
float noiseField(vec2 p, float evo, float wt) {
|
|
131
|
-
float warp = gnoise(p + wt * 0.04);
|
|
132
|
-
float v = 0.0;
|
|
133
|
-
float amp = 0.5;
|
|
134
|
-
float freq = 1.0;
|
|
135
|
-
for (int i = 0; i < 5; i++) {
|
|
136
|
-
v += amp * gnoise(p * freq + vec2(warp * 0.3, warp * 0.25) + evo * 0.06);
|
|
137
|
-
amp *= 0.5;
|
|
138
|
-
freq *= 2.07;
|
|
139
|
-
warp = v;
|
|
140
|
-
}
|
|
141
|
-
return v;
|
|
142
|
-
}
|
|
143
|
-
`;
|
|
144
|
-
|
|
145
113
|
const FRAG = `
|
|
146
114
|
precision highp float;
|
|
147
115
|
uniform vec2 uRes;
|
|
@@ -159,7 +127,8 @@ uniform vec4 uBg;
|
|
|
159
127
|
${GLSL_OKLAB}
|
|
160
128
|
${GLSL_QUIET}
|
|
161
129
|
${GLSL_GLYPHS}
|
|
162
|
-
${
|
|
130
|
+
${GLSL_GRADIENT_NOISE}
|
|
131
|
+
${GLSL_NOISE_FIELD}
|
|
163
132
|
|
|
164
133
|
void main() {
|
|
165
134
|
// Cells counted from the top left, as the text still lays them.
|
|
@@ -181,76 +150,6 @@ void main() {
|
|
|
181
150
|
}
|
|
182
151
|
`;
|
|
183
152
|
|
|
184
|
-
/**
|
|
185
|
-
* One octave's gradient at a lattice point (the shader's `grad`): Dave
|
|
186
|
-
* Hoskins' Hash without Sine, which brings its input under 1 before it
|
|
187
|
-
* multiplies, so the GPU's 32-bit floats and these 64-bit ones agree.
|
|
188
|
-
* (The sketch's own hash multiplied values in the thousands, where the
|
|
189
|
-
* two drift apart and the text still would not be the shader's frame.)
|
|
190
|
-
*
|
|
191
|
-
* @param {number} x The point's x.
|
|
192
|
-
* @param {number} y The point's y.
|
|
193
|
-
* @returns {[number, number]} A gradient, each part −1 to 1.
|
|
194
|
-
*/
|
|
195
|
-
function grad(x, y) {
|
|
196
|
-
const fract = (/** @type {number} */ n) => n - Math.floor(n);
|
|
197
|
-
let a = fract(x * 0.1031);
|
|
198
|
-
let b = fract(y * 0.103);
|
|
199
|
-
let c = fract(x * 0.0973);
|
|
200
|
-
const d = a * (b + 33.33) + b * (c + 33.33) + c * (a + 33.33);
|
|
201
|
-
a += d;
|
|
202
|
-
b += d;
|
|
203
|
-
c += d;
|
|
204
|
-
return [-1 + 2 * fract((a + b) * c), -1 + 2 * fract((a + c) * b)];
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Gradient noise with a quintic fade (the shader's `gnoise`).
|
|
209
|
-
*
|
|
210
|
-
* @param {number} x Where, x.
|
|
211
|
-
* @param {number} y Where, y.
|
|
212
|
-
* @returns {number} 0–1.
|
|
213
|
-
*/
|
|
214
|
-
function gnoise(x, y) {
|
|
215
|
-
const ix = Math.floor(x);
|
|
216
|
-
const iy = Math.floor(y);
|
|
217
|
-
const fx = x - ix;
|
|
218
|
-
const fy = y - iy;
|
|
219
|
-
const ux = fx * fx * fx * (fx * (fx * 6 - 15) + 10);
|
|
220
|
-
const uy = fy * fy * fy * (fy * (fy * 6 - 15) + 10);
|
|
221
|
-
const dot = (/** @type {[number, number]} */ g, /** @type {number} */ dx, /** @type {number} */ dy) => g[0] * dx + g[1] * dy;
|
|
222
|
-
const a = dot(grad(ix, iy), fx, fy);
|
|
223
|
-
const b = dot(grad(ix + 1, iy), fx - 1, fy);
|
|
224
|
-
const c = dot(grad(ix, iy + 1), fx, fy - 1);
|
|
225
|
-
const d = dot(grad(ix + 1, iy + 1), fx - 1, fy - 1);
|
|
226
|
-
const ab = a + (b - a) * ux;
|
|
227
|
-
const cd = c + (d - c) * ux;
|
|
228
|
-
return 0.5 + 0.5 * (ab + (cd - ab) * uy);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* The field: five octaves of gradient noise, each warped by the sum so far.
|
|
233
|
-
*
|
|
234
|
-
* @param {number} x Where, x.
|
|
235
|
-
* @param {number} y Where, y.
|
|
236
|
-
* @param {number} evo The morphing clock.
|
|
237
|
-
* @param {number} wt The warp's clock (seconds).
|
|
238
|
-
* @returns {number} 0–1, near 0.5 on average.
|
|
239
|
-
*/
|
|
240
|
-
export function noiseField(x, y, evo, wt) {
|
|
241
|
-
let warp = gnoise(x + wt * 0.04, y + wt * 0.04);
|
|
242
|
-
let v = 0;
|
|
243
|
-
let amp = 0.5;
|
|
244
|
-
let freq = 1;
|
|
245
|
-
for (let i = 0; i < 5; i++) {
|
|
246
|
-
v += amp * gnoise(x * freq + warp * 0.3 + evo * 0.06, y * freq + warp * 0.25 + evo * 0.06);
|
|
247
|
-
amp *= 0.5;
|
|
248
|
-
freq *= 2.07;
|
|
249
|
-
warp = v;
|
|
250
|
-
}
|
|
251
|
-
return v;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
153
|
/**
|
|
255
154
|
* One frame as ramp indices: what the shader draws, cell for cell, on a
|
|
256
155
|
* target exactly `cols` by `rows` cells.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** GLSL (ES 1.00): `float bayer8(vec2 cell)`, the 8×8 Bayer threshold 0–63/64 at a dot. */
|
|
2
|
+
export declare const GLSL_BAYER: string;
|
|
3
|
+
|
|
4
|
+
/** The 8×8 Bayer threshold at a dot, 0–63/64 (it repeats every 8 dots). */
|
|
5
|
+
export declare function bayer(x: number, y: number): number;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/bayer
|
|
3
|
+
*
|
|
4
|
+
* The 8×8 Bayer ordered-dither threshold, as GLSL and as a JS function of
|
|
5
|
+
* the same values, built from the 2×2 matrix at three scales so neither
|
|
6
|
+
* side needs a texture. Shared by DitherField and DitherGradient.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The fractional part.
|
|
11
|
+
*
|
|
12
|
+
* @param {number} n A number.
|
|
13
|
+
* @returns {number} `n − floor(n)`, 0–1.
|
|
14
|
+
*/
|
|
15
|
+
const fract = (n) => n - Math.floor(n);
|
|
16
|
+
|
|
17
|
+
/** GLSL (ES 1.00): `float bayer8(vec2 cell)`, the threshold 0–63/64 at a dot (it repeats every 8 dots). */
|
|
18
|
+
export const GLSL_BAYER = `
|
|
19
|
+
float bayer2(vec2 a) { return fract(a.x * 0.5 + a.y * a.y * 0.75); }
|
|
20
|
+
float bayer8(vec2 cell) {
|
|
21
|
+
vec2 a = mod(floor(cell), 8.0);
|
|
22
|
+
vec2 b = floor(a * 0.5);
|
|
23
|
+
vec2 c = floor(a * 0.25);
|
|
24
|
+
return bayer2(a) + bayer2(b) * 0.25 + bayer2(c) * 0.0625;
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* The 8×8 Bayer threshold at a dot (the shader's `bayer8`): the classic
|
|
30
|
+
* ordered-dither matrix, 0/64 to 63/64.
|
|
31
|
+
*
|
|
32
|
+
* @param {number} x The dot's column (any integer; it repeats every 8).
|
|
33
|
+
* @param {number} y The dot's row.
|
|
34
|
+
* @returns {number} The threshold, 0–63/64.
|
|
35
|
+
*/
|
|
36
|
+
export function bayer(x, y) {
|
|
37
|
+
/**
|
|
38
|
+
* The 2×2 matrix (0, 2 / 3, 1 over 4) by a cell's parity.
|
|
39
|
+
*
|
|
40
|
+
* @param {number} a Column.
|
|
41
|
+
* @param {number} b Row.
|
|
42
|
+
* @returns {number} 0, 0.25, 0.5 or 0.75.
|
|
43
|
+
*/
|
|
44
|
+
const two = (a, b) => fract(a * 0.5 + b * b * 0.75);
|
|
45
|
+
const ax = ((Math.floor(x) % 8) + 8) % 8;
|
|
46
|
+
const ay = ((Math.floor(y) % 8) + 8) % 8;
|
|
47
|
+
return two(ax, ay) + two(Math.floor(ax / 2), Math.floor(ay / 2)) * 0.25 + two(Math.floor(ax / 4), Math.floor(ay / 4)) * 0.0625;
|
|
48
|
+
}
|
|
@@ -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;
|