@arraypress/effects-astro 0.12.0 → 0.14.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 +89 -0
- package/package.json +1 -1
- package/src/components/FluidFolds.astro +40 -0
- package/src/components/FlutedBokeh.astro +40 -0
- package/src/components/GlassDrop.astro +40 -0
- package/src/components/GlassStack.astro +41 -0
- package/src/index.d.ts +13 -0
- package/src/index.js +7 -0
- package/src/runtime/dither-gradient.d.ts +9 -3
- package/src/runtime/dither-gradient.js +55 -12
- package/src/runtime/fluid-folds.d.ts +58 -0
- package/src/runtime/fluid-folds.js +317 -0
- package/src/runtime/fluted-bokeh.d.ts +70 -0
- package/src/runtime/fluted-bokeh.js +355 -0
- package/src/runtime/glass-drop-plan.d.ts +59 -0
- package/src/runtime/glass-drop-plan.js +133 -0
- package/src/runtime/glass-drop.d.ts +61 -0
- package/src/runtime/glass-drop.js +331 -0
- package/src/runtime/glass-optics.d.ts +5 -0
- package/src/runtime/glass-optics.js +49 -0
- package/src/runtime/glass-stack.d.ts +65 -0
- package/src/runtime/glass-stack.js +315 -0
- package/src/runtime/slab-runs.d.ts +18 -0
- package/src/runtime/slab-runs.js +112 -0
package/AGENTS.md
CHANGED
|
@@ -32,7 +32,7 @@ Pick by what is asked for:
|
|
|
32
32
|
| A "we sell worldwide" or "we ship from here" section | `<WorldRoutes>` with the cities that matter to the shop; `home="…"` for a hub, `colors` + `gradient` for colour, `labels`, `region="europe"` (or `routes`) to crop |
|
|
33
33
|
| A space, astronomy, night-sky or sci-fi hero: a nebula with stars | `<Galaxy palette="…">` (Canvas 2D, no WebGL; `stars`, `glitter`, `speed`) |
|
|
34
34
|
| A light or texture over a background (a spotlight, film grain) | `<GlowField>`, `<Grain>` (`still` for either to hold) |
|
|
35
|
-
| The brand's logo as the hero's centrepiece | `<GlassGlyph>`, `<LiquidMetal>` (liquid chrome you can poke and splash; `tint="gold"`…), `<ParticleLogo>`, `<NeonSwarm>` (a flowing neon swarm), `<NebulaLogo>` (filled with nebula gas), `<VoxelLogo>`, `<PointCloud>`, all with `src="/logo.svg"` or `text` |
|
|
35
|
+
| The brand's logo as the hero's centrepiece | `<GlassGlyph>`, `<GlassDrop>` (a drop of liquid glass becomes a tile over the logo, or the logo itself, then melts; `loop`), `<GlassStack>` (the logo as stacked tinted glass discs on a lit card), `<LiquidMetal>` (liquid chrome you can poke and splash; `tint="gold"`…), `<ParticleLogo>`, `<NeonSwarm>` (a flowing neon swarm), `<NebulaLogo>` (filled with nebula gas), `<VoxelLogo>`, `<PointCloud>`, all with `src="/logo.svg"` or `text` |
|
|
36
36
|
| A footer wordmark | `<SpotlightText fit>`, `<PixelGlitchText fit>`, `<OutlineWordmark>` |
|
|
37
37
|
| Something retro or 8-bit on a footer: pixels firing out of it, sparks, "insert coin" | `<PixelFountain>` inside the footer (its top edge must not clip: `overflow-x: clip`, not `overflow: hidden`); `source="text"` sheds pixels from a wordmark; `color` or `colors` for the ramp |
|
|
38
38
|
| Sections that arrive on scroll, site-wide | `<ScrollReveal />` once in the layout, then reveal.css classes (`fade-in-up`…) on elements |
|
package/COMPONENTS.md
CHANGED
|
@@ -409,6 +409,51 @@ Glass: a liquid glass panel, with a rim that catches the light and a sheen that
|
|
|
409
409
|
| `specular` | `number` | With `refract`, how bright the highlight along the rim is, 0–1. Default 0.7. |
|
|
410
410
|
| `class` | `string` | Classes for the element. |
|
|
411
411
|
|
|
412
|
+
## `<GlassDrop>`
|
|
413
|
+
|
|
414
|
+
GlassDrop: a logo arriving as liquid glass. A drop forms, lands with rings running out, and spreads into a glass tile with the logo rising under it (or into the logo's own shape, `form="mark"`); it holds, then melts away and leaves the logo flat on the ground. Once, or on a loop. See src/runtime/glass-drop.js.
|
|
415
|
+
|
|
416
|
+
```astro
|
|
417
|
+
<section class="hero" style="position: relative">
|
|
418
|
+
<GlassDrop src="/logo.svg" loop />
|
|
419
|
+
<h1>…</h1>
|
|
420
|
+
</section>
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
| Prop | Type | |
|
|
424
|
+
|---|---|---|
|
|
425
|
+
| `src` | `string` | An image (an SVG logo) to make the glass of. |
|
|
426
|
+
| `text` | `string` | A character or word instead of an image. |
|
|
427
|
+
| `font` | `string` | Its CSS font, without the size. Default: the page's, bold. |
|
|
428
|
+
| `area` | `{ x: number; y: number; width: number; height: number }` | Where the glass sits, each 0–1 from the top left. Default all of the element. |
|
|
429
|
+
| `form` | `'tile' \| 'mark'` | What the drop becomes: `tile`, a glass tile with the logo under it, or `mark`, the logo's own shape in glass. Default `tile`. |
|
|
430
|
+
| `size` | `number` | The tile's edge, a share of the area's shorter side, 0.2–1. Default 0.7. |
|
|
431
|
+
| `markScale` | `number` | The logo's size under the glass, a share of the tile, 0.2–1. Default 0.62. |
|
|
432
|
+
| `restScale` | `number` | The logo's size once the glass has melted, times its size under the glass, 0.5–2. Default 1. |
|
|
433
|
+
| `radius` | `number` | The tile's corner radius, a share of its edge, 0–0.5. Default 0.24. |
|
|
434
|
+
| `background` | `string` | The ground. Default `#000000`. |
|
|
435
|
+
| `color` | `string` | The logo's colour. Default `#ffffff`. |
|
|
436
|
+
| `plate` | `string` | The tile's surface under the logo. Default `#0a1020`. |
|
|
437
|
+
| `light` | `string` | The studio light the glass mirrors. Default `#ffffff`. |
|
|
438
|
+
| `depth` | `number` | How hard the glass bends what is under it, 0–2. Default 1. |
|
|
439
|
+
| `dispersion` | `number` | How far the colours part at the rim, 0–2; 0 for none. Default 1. |
|
|
440
|
+
| `bevel` | `number` | How wide the rounded rim is, a share of the tile (or the logo), 0.02–0.3. Default 0.1. |
|
|
441
|
+
| `highlights` | `number` | The lip and the studio's reflections, 0–2. Default 1. |
|
|
442
|
+
| `caustics` | `number` | Light focused at the glass's edge and onto the ground, 0–2. Default 1. |
|
|
443
|
+
| `bloom` | `number` | A soft glow round the glass, 0–1. Default 0.5. |
|
|
444
|
+
| `ripples` | `number` | The rings the drop sends across the ground, 0–2; 0 for none. Default 1. |
|
|
445
|
+
| `tint` | `number` | With `form: 'mark'`: how strongly the glass takes the logo's colour, 0–1. Default 0.88. |
|
|
446
|
+
| `lightAngle` | `number` | Where the light comes from, degrees, 0–360 (0 right, 90 top). Default 125. |
|
|
447
|
+
| `speed` | `number` | How fast the sequence plays, 0.25–3. Default 1. |
|
|
448
|
+
| `delay` | `number` | Seconds to wait before it starts, 0–10. Default 0. |
|
|
449
|
+
| `hold` | `number` | Seconds the glass holds before it melts, 0–10. Default 2.4. |
|
|
450
|
+
| `loop` | `boolean` | Play it again after a rest; each round starts from the resting logo, which fades as the new drop forms. Default false. |
|
|
451
|
+
| `loopDelay` | `number` | With `loop`: seconds the logo rests before the next drop, 0–10. Default 1.6. |
|
|
452
|
+
| `rest` | `'flat' \| 'glass'` | How it ends: `flat`, the glass melted and the logo left on the ground, or `glass`, the glass held. Default `flat`. |
|
|
453
|
+
| `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
|
|
454
|
+
| `lazy` | `boolean \| string` | 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. |
|
|
455
|
+
| `class` | `string` | Classes for the element. |
|
|
456
|
+
|
|
412
457
|
## `<GlassGlyph>`
|
|
413
458
|
|
|
414
459
|
GlassGlyph: a character or a logo as a thick slab of dark, smoked glass, lit from behind by beams of one coloured light. The light barely shows on the near-black ground; the glass catches it and glows with it through its body and bevels. The slab turns slowly on its own and leans away from the pointer; the light stays put. See src/runtime/glass-glyph.js.
|
|
@@ -446,6 +491,50 @@ GlassGlyph: a character or a logo as a thick slab of dark, smoked glass, lit fro
|
|
|
446
491
|
| `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
|
|
447
492
|
| `class` | `string` | Classes for the element. |
|
|
448
493
|
|
|
494
|
+
## `<GlassStack>`
|
|
495
|
+
|
|
496
|
+
GlassStack: a logo as a stack of tinted glass discs in front of a lit card, seen a little from below. The logo is cut into slices and every stretch of it in a slice becomes a disc; the tints run from the top slice to the bottom. The discs grow from the bottom up when it first shows, then the stack leans gently on its own and toward the pointer. See src/runtime/glass-stack.js.
|
|
497
|
+
|
|
498
|
+
```astro
|
|
499
|
+
<section class="hero" style="position: relative">
|
|
500
|
+
<GlassStack src="/logo.svg" background="#0b0b0b" colors={['#f4ffd0', '#c8ff00', '#0e8c7e']} />
|
|
501
|
+
<h1>…</h1>
|
|
502
|
+
</section>
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
| Prop | Type | |
|
|
506
|
+
|---|---|---|
|
|
507
|
+
| `src` | `string` | An image (an SVG logo) to make the stack of. |
|
|
508
|
+
| `text` | `string` | A character or word instead of an image. |
|
|
509
|
+
| `font` | `string` | Its CSS font, without the size. Default: the page's, bold. |
|
|
510
|
+
| `area` | `{ x: number; y: number; width: number; height: number }` | Where the stack sits, each 0–1 from the top left. Default all of the element. |
|
|
511
|
+
| `logoScale` | `number` | The logo's size, a share of the area's shorter side, 0.2–1. Default 0.73. |
|
|
512
|
+
| `colors` | `string[]` | The glass's tints from the top slice to the bottom, 2–6 colours. Default aqua to deep blue. |
|
|
513
|
+
| `background` | `string` | The ground. Default `#ffffff`. |
|
|
514
|
+
| `light` | `string` | The lit card behind the stack, and the studio the glass mirrors. Default `#ffffff`. |
|
|
515
|
+
| `slabs` | `number` | How many slices the logo is cut into, 4–64. Default 22. |
|
|
516
|
+
| `phase` | `number` | Where in its slice each disc samples the logo, 0 the top to 1 the bottom. Default 0.5. |
|
|
517
|
+
| `band` | `number` | How much of its slice each disc samples, 0 a line to 1 all of it; more keeps small parts. Default 0.35. |
|
|
518
|
+
| `depth` | `number` | How open each disc is from below (the camera's height), a share of the slice, 0.05–1.4. Default 0.55. |
|
|
519
|
+
| `thickness` | `number` | How much of each disc's front edge shows, a share of the slice, 0–1. Default 0.35. |
|
|
520
|
+
| `ior` | `number` | The glass's refractive index: how hard its rims bend the card, 1–2. Default 1.45. |
|
|
521
|
+
| `reflectivity` | `number` | How strongly the glass mirrors the studio, 0–1. Default 0.3. |
|
|
522
|
+
| `density` | `number` | How deeply the glass is tinted, 0–3. Default 0.9. |
|
|
523
|
+
| `opacity` | `number` | How much the discs hide the discs behind them, 0–1. Default 0.92. |
|
|
524
|
+
| `exposure` | `number` | The card's brightness, 0–2. Default 1.1. |
|
|
525
|
+
| `ambient` | `number` | How far the card's light spills onto the ground, 0–1. Default 0.05. |
|
|
526
|
+
| `cardSize` | `number` | The card's size, times the logo's box, 0 for none to 3. Default 1.15. |
|
|
527
|
+
| `lightAngle` | `number` | Where the light comes from, degrees, 0–360 (0 right, 90 top). Default 115. |
|
|
528
|
+
| `tilt` | `number` | How far the stack leans toward the pointer, 0–2; 0 for not at all. Default 1. |
|
|
529
|
+
| `sway` | `number` | How far it leans on its own, slowly, 0–2; 0 holds it still. Default 0.5. |
|
|
530
|
+
| `intro` | `boolean` | Grow the discs from the bottom up when it first shows. Default true. |
|
|
531
|
+
| `introDuration` | `number` | Seconds until the top disc has grown, 0.2–6. Default 1.6. |
|
|
532
|
+
| `delay` | `number` | Seconds before the intro starts, 0–10. Default 0. |
|
|
533
|
+
| `speed` | `number` | How fast the intro plays, 0.25–3. Default 1. |
|
|
534
|
+
| `fixed` | `boolean` | Fill the viewport, behind the page (position: fixed, z-index -1). Default false. |
|
|
535
|
+
| `lazy` | `boolean \| string` | 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. |
|
|
536
|
+
| `class` | `string` | Classes for the element. |
|
|
537
|
+
|
|
449
538
|
## `<GlitchText>`
|
|
450
539
|
|
|
451
540
|
GlitchText: a headline that glitches now and then. Every few seconds two coloured copies of it (pink and blue by default) flash over it for a few frames, sliced into bands and shifted sideways, and the text nudges with them; the rest of the time it sits still. Livelier under the pointer (on the text, or a link or button round it). Each one on the page glitches on its own beat. CSS only, from glitch-text.css; with reduced motion it is the plain text. Not the canvas `<PixelGlitchText>`, which breaks into pixels under the pointer.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arraypress/effects-astro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "GPU effects for Astro sites, as components: liquid light with a real fluid under it, ink in water, and outline text a spotlight fills. Plain WebGL, no third-party dependencies, with the fallbacks a theme needs (reduced motion, no WebGL, touch screens, off-screen pausing).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* FluidFolds: glossy folds of liquid colour on a dark ground, warped by slow
|
|
4
|
+
* noise and lit from one side, the colour drifting along a ramp of three;
|
|
5
|
+
* poured enamel (`style="liquid"`) or long silk dunes (`style="dunes"`). No
|
|
6
|
+
* pointer, made to sit behind copy. See src/runtime/fluid-folds.js.
|
|
7
|
+
*
|
|
8
|
+
* Fills its nearest positioned ancestor, or the viewport with `fixed`.
|
|
9
|
+
* Opaque: it paints its `background` (default near-black) everywhere; the
|
|
10
|
+
* element shows a CSS still of it until the shader starts and without WebGL.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* <section class="hero" style="position: relative; background: #050409">
|
|
14
|
+
* <FluidFolds colors={['#1638ff', '#7b2cff', '#ff4a3d']} style="liquid" />
|
|
15
|
+
* <h1>…</h1>
|
|
16
|
+
* </section>
|
|
17
|
+
*/
|
|
18
|
+
import EffectCanvas from './EffectCanvas.astro';
|
|
19
|
+
import { foldsStill, type FluidFoldsConfig } from '../runtime/fluid-folds.js';
|
|
20
|
+
|
|
21
|
+
interface Props extends FluidFoldsConfig {
|
|
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 = foldsStill(config);
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
<EffectCanvas name="fluid-folds" config={config} fixed={fixed} lazy={lazy} background={still} class={className} />
|
|
34
|
+
|
|
35
|
+
<script>
|
|
36
|
+
import { mount } from '../runtime/mount.js';
|
|
37
|
+
import { fluidFolds } from '../runtime/fluid-folds.js';
|
|
38
|
+
|
|
39
|
+
mount('[data-effect-fluid-folds]', fluidFolds);
|
|
40
|
+
</script>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* FlutedBokeh: coloured lights out of focus behind reeded glass (upright
|
|
4
|
+
* flutes with a thin rainbow at each seam) or a wall of glass blocks, the
|
|
5
|
+
* lights drifting slowly. No pointer, made to sit behind copy. See
|
|
6
|
+
* src/runtime/fluted-bokeh.js.
|
|
7
|
+
*
|
|
8
|
+
* Fills its nearest positioned ancestor, or the viewport with `fixed`.
|
|
9
|
+
* Opaque: it paints its `background` (default near-black) everywhere; the
|
|
10
|
+
* element shows a CSS still of it until the shader starts and without WebGL.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* <section class="hero" style="position: relative; background: #050608">
|
|
14
|
+
* <FlutedBokeh colors={['#ff4a2a', '#ffb347', '#4fc3ff']} mode="reeds" />
|
|
15
|
+
* <h1>…</h1>
|
|
16
|
+
* </section>
|
|
17
|
+
*/
|
|
18
|
+
import EffectCanvas from './EffectCanvas.astro';
|
|
19
|
+
import { bokehStill, type FlutedBokehConfig } from '../runtime/fluted-bokeh.js';
|
|
20
|
+
|
|
21
|
+
interface Props extends FlutedBokehConfig {
|
|
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 = bokehStill(config);
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
<EffectCanvas name="fluted-bokeh" config={config} fixed={fixed} lazy={lazy} background={still} class={className} />
|
|
34
|
+
|
|
35
|
+
<script>
|
|
36
|
+
import { mount } from '../runtime/mount.js';
|
|
37
|
+
import { flutedBokeh } from '../runtime/fluted-bokeh.js';
|
|
38
|
+
|
|
39
|
+
mount('[data-effect-fluted-bokeh]', flutedBokeh);
|
|
40
|
+
</script>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* GlassDrop: a logo arriving as liquid glass. A drop forms, lands with
|
|
4
|
+
* rings running out, and spreads into a glass tile with the logo rising
|
|
5
|
+
* under it (or into the logo's own shape, `form="mark"`); it holds, then
|
|
6
|
+
* melts away and leaves the logo flat on the ground. Once, or on a loop.
|
|
7
|
+
* See src/runtime/glass-drop.js.
|
|
8
|
+
*
|
|
9
|
+
* Opaque: it is the whole background of what it fills (its nearest
|
|
10
|
+
* positioned ancestor, or the viewport with `fixed`). Without WebGL the
|
|
11
|
+
* `background` colour shows; with reduced motion, the final frame.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* <section class="hero" style="position: relative">
|
|
15
|
+
* <GlassDrop src="/logo.svg" loop />
|
|
16
|
+
* <h1>…</h1>
|
|
17
|
+
* </section>
|
|
18
|
+
*/
|
|
19
|
+
import EffectCanvas from './EffectCanvas.astro';
|
|
20
|
+
import type { GlassDropConfig } from '../runtime/glass-drop.js';
|
|
21
|
+
|
|
22
|
+
interface Props extends GlassDropConfig {
|
|
23
|
+
/** Fill the viewport, behind the page (position: fixed, z-index -1). Default false. */
|
|
24
|
+
fixed?: boolean;
|
|
25
|
+
/** 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. */
|
|
26
|
+
lazy?: boolean | string;
|
|
27
|
+
class?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const { fixed = false, lazy = false, class: className, ...config } = Astro.props;
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
<EffectCanvas name="glass-drop" config={config} fixed={fixed} lazy={lazy} class={className} behind background={config.background ?? '#000000'} />
|
|
34
|
+
|
|
35
|
+
<script>
|
|
36
|
+
import { mount } from '../runtime/mount.js';
|
|
37
|
+
import { glassDrop } from '../runtime/glass-drop.js';
|
|
38
|
+
|
|
39
|
+
mount('[data-effect-glass-drop]', glassDrop);
|
|
40
|
+
</script>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* GlassStack: a logo as a stack of tinted glass discs in front of a lit
|
|
4
|
+
* card, seen a little from below. The logo is cut into slices and every
|
|
5
|
+
* stretch of it in a slice becomes a disc; the tints run from the top slice
|
|
6
|
+
* to the bottom. The discs grow from the bottom up when it first shows,
|
|
7
|
+
* then the stack leans gently on its own and toward the pointer.
|
|
8
|
+
* See src/runtime/glass-stack.js.
|
|
9
|
+
*
|
|
10
|
+
* Opaque: it is the whole background of what it fills (its nearest
|
|
11
|
+
* positioned ancestor, or the viewport with `fixed`). Without WebGL the
|
|
12
|
+
* `background` colour shows; with reduced motion, every disc grown.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* <section class="hero" style="position: relative">
|
|
16
|
+
* <GlassStack src="/logo.svg" background="#0b0b0b" colors={['#f4ffd0', '#c8ff00', '#0e8c7e']} />
|
|
17
|
+
* <h1>…</h1>
|
|
18
|
+
* </section>
|
|
19
|
+
*/
|
|
20
|
+
import EffectCanvas from './EffectCanvas.astro';
|
|
21
|
+
import type { GlassStackConfig } from '../runtime/glass-stack.js';
|
|
22
|
+
|
|
23
|
+
interface Props extends GlassStackConfig {
|
|
24
|
+
/** Fill the viewport, behind the page (position: fixed, z-index -1). Default false. */
|
|
25
|
+
fixed?: boolean;
|
|
26
|
+
/** 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. */
|
|
27
|
+
lazy?: boolean | string;
|
|
28
|
+
class?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const { fixed = false, lazy = false, class: className, ...config } = Astro.props;
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
<EffectCanvas name="glass-stack" config={config} fixed={fixed} lazy={lazy} class={className} behind background={config.background ?? '#ffffff'} />
|
|
35
|
+
|
|
36
|
+
<script>
|
|
37
|
+
import { mount } from '../runtime/mount.js';
|
|
38
|
+
import { glassStack } from '../runtime/glass-stack.js';
|
|
39
|
+
|
|
40
|
+
mount('[data-effect-glass-stack]', glassStack);
|
|
41
|
+
</script>
|
package/src/index.d.ts
CHANGED
|
@@ -19,11 +19,15 @@ export { ditherGradient, gradientStill } from './runtime/dither-gradient.js';
|
|
|
19
19
|
export { truchetField, truchetStill } from './runtime/truchet-field.js';
|
|
20
20
|
export { pixelHorizon, horizonStill } from './runtime/pixel-horizon.js';
|
|
21
21
|
export { flutedGlow, glowStill } from './runtime/fluted-glow.js';
|
|
22
|
+
export { fluidFolds, foldsStill } from './runtime/fluid-folds.js';
|
|
23
|
+
export { flutedBokeh, bokehStill } from './runtime/fluted-bokeh.js';
|
|
22
24
|
export { bayer, GLSL_BAYER } from './runtime/bayer.js';
|
|
23
25
|
export type { DitherGradientConfig } from './runtime/dither-gradient.js';
|
|
24
26
|
export type { TruchetFieldConfig } from './runtime/truchet-field.js';
|
|
25
27
|
export type { PixelHorizonConfig } from './runtime/pixel-horizon.js';
|
|
26
28
|
export type { FlutedGlowConfig } from './runtime/fluted-glow.js';
|
|
29
|
+
export type { FluidFoldsConfig } from './runtime/fluid-folds.js';
|
|
30
|
+
export type { FlutedBokehConfig } from './runtime/fluted-bokeh.js';
|
|
27
31
|
export type { LightLeakConfig } from './runtime/light-leak.js';
|
|
28
32
|
export type { DitherFieldConfig } from './runtime/dither-field.js';
|
|
29
33
|
export type { CascadeGridConfig } from './runtime/cascade-grid.js';
|
|
@@ -32,6 +36,15 @@ export type { VoronoiMeshConfig } from './runtime/voronoi-mesh.js';
|
|
|
32
36
|
export type { KineticGridConfig } from './runtime/kinetic-grid.js';
|
|
33
37
|
export { glassGlyph } from './runtime/glass-glyph.js';
|
|
34
38
|
export type { GlassGlyphConfig } from './runtime/glass-glyph.js';
|
|
39
|
+
export { glassDrop } from './runtime/glass-drop.js';
|
|
40
|
+
export type { GlassDropConfig } from './runtime/glass-drop.js';
|
|
41
|
+
export { dropAt, dropCycle, dropLayout, DROP_PHASES, DROP_SIZE } from './runtime/glass-drop-plan.js';
|
|
42
|
+
export type { DropLayout, DropState, DropPlanConfig } from './runtime/glass-drop-plan.js';
|
|
43
|
+
export { glassStack, stackLayout, sliceTints } from './runtime/glass-stack.js';
|
|
44
|
+
export type { GlassStackConfig } from './runtime/glass-stack.js';
|
|
45
|
+
export { sliceRuns, runsTexture, slabGrowth } from './runtime/slab-runs.js';
|
|
46
|
+
export type { Run as SlabRun } from './runtime/slab-runs.js';
|
|
47
|
+
export { GLSL_STUDIO, lightVector } from './runtime/glass-optics.js';
|
|
35
48
|
export { flutedGlass } from './runtime/fluted-glass.js';
|
|
36
49
|
export type { FlutedGlassConfig } from './runtime/fluted-glass.js';
|
|
37
50
|
export { particleLogo } from './runtime/particle-logo.js';
|
package/src/index.js
CHANGED
|
@@ -27,8 +27,15 @@ export { ditherGradient, gradientStill } from './runtime/dither-gradient.js';
|
|
|
27
27
|
export { truchetField, truchetStill } from './runtime/truchet-field.js';
|
|
28
28
|
export { pixelHorizon, horizonStill } from './runtime/pixel-horizon.js';
|
|
29
29
|
export { flutedGlow, glowStill } from './runtime/fluted-glow.js';
|
|
30
|
+
export { fluidFolds, foldsStill } from './runtime/fluid-folds.js';
|
|
31
|
+
export { flutedBokeh, bokehStill } from './runtime/fluted-bokeh.js';
|
|
30
32
|
export { bayer, GLSL_BAYER } from './runtime/bayer.js';
|
|
31
33
|
export { glassGlyph } from './runtime/glass-glyph.js';
|
|
34
|
+
export { glassDrop } from './runtime/glass-drop.js';
|
|
35
|
+
export { dropAt, dropCycle, dropLayout, DROP_PHASES, DROP_SIZE } from './runtime/glass-drop-plan.js';
|
|
36
|
+
export { glassStack, stackLayout, sliceTints } from './runtime/glass-stack.js';
|
|
37
|
+
export { sliceRuns, runsTexture, slabGrowth } from './runtime/slab-runs.js';
|
|
38
|
+
export { GLSL_STUDIO, lightVector } from './runtime/glass-optics.js';
|
|
32
39
|
export { flutedGlass } from './runtime/fluted-glass.js';
|
|
33
40
|
export { particleLogo } from './runtime/particle-logo.js';
|
|
34
41
|
export { pointCloud } from './runtime/point-cloud.js';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { PaletteName } from './palettes.js';
|
|
2
2
|
|
|
3
3
|
/** The gradient's shapes. */
|
|
4
|
-
export type GradientShape = 'wave' | 'band' | 'swirl' | 'pinwheel' | 'steps';
|
|
4
|
+
export type GradientShape = 'wave' | 'band' | 'swirl' | 'pinwheel' | 'steps' | 'orb' | 'pill';
|
|
5
5
|
|
|
6
6
|
export interface DitherGradientConfig {
|
|
7
|
-
/** Two CSS hex colours
|
|
7
|
+
/** Two CSS hex colours, the dim one where the tone is low and the bright one where it is full, or three with a middle colour between them. Default a plum and a hot pink. */
|
|
8
8
|
colors?: string[];
|
|
9
9
|
/** A shared palette by name (`PALETTES`, any case), when there are no `colors`: its first and last colours. */
|
|
10
10
|
palette?: PaletteName | (string & {});
|
|
@@ -32,6 +32,8 @@ export interface DitherGradientConfig {
|
|
|
32
32
|
rate?: number;
|
|
33
33
|
/** The steps' block, in dots. Default 6. */
|
|
34
34
|
block?: number;
|
|
35
|
+
/** The orb's radius, and the pill's thickness's share, in widths. Default 0.3. */
|
|
36
|
+
size?: number;
|
|
35
37
|
/** Colour bands from dim to bright; 0 blends smoothly. Default 0. */
|
|
36
38
|
steps?: number;
|
|
37
39
|
/** The swirl's and pinwheel's centre, and the wave's and band's pivot, 0–1 from the top left. Default [0.5, 0.5]. */
|
|
@@ -45,7 +47,7 @@ export interface DitherGradientConfig {
|
|
|
45
47
|
}
|
|
46
48
|
|
|
47
49
|
/** The shapes, in the order the shader numbers them. */
|
|
48
|
-
export declare const GRADIENT_SHAPES: readonly ['wave', 'band', 'swirl', 'pinwheel', 'steps'];
|
|
50
|
+
export declare const GRADIENT_SHAPES: readonly ['wave', 'band', 'swirl', 'pinwheel', 'steps', 'orb', 'pill'];
|
|
49
51
|
|
|
50
52
|
/** The settings' defaults, shared by the shader and the JS twin. */
|
|
51
53
|
export declare const GRADIENT_DEFAULTS: {
|
|
@@ -60,6 +62,7 @@ export declare const GRADIENT_DEFAULTS: {
|
|
|
60
62
|
twist: number;
|
|
61
63
|
rate: number;
|
|
62
64
|
block: number;
|
|
65
|
+
size: number;
|
|
63
66
|
steps: number;
|
|
64
67
|
centre: [number, number];
|
|
65
68
|
};
|
|
@@ -81,6 +84,9 @@ export declare function gradientTone(s: GradientSettings, x: number, y: number,
|
|
|
81
84
|
/** One frame dot for dot on a target exactly `cols` by `rows` dots: each dot's tone after the quiet area, and whether a bayer dot is lit. */
|
|
82
85
|
export declare function gradientDots(config: DitherGradientConfig, cols: number, rows: number, time?: number): { tone: number; lit: boolean }[][];
|
|
83
86
|
|
|
87
|
+
/** The three colours the dots blend through, low to high: a middle one of their own when three or more are given, else halfway in Oklab. */
|
|
88
|
+
export declare function gradientRamp(config: DitherGradientConfig): [string, string, string];
|
|
89
|
+
|
|
84
90
|
/** The two colours as the shader takes them: the dim one and the bright one. */
|
|
85
91
|
export declare function gradientColors(config: DitherGradientConfig): [string, string];
|
|
86
92
|
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
* @module @arraypress/effects-astro/dither-gradient
|
|
3
3
|
*
|
|
4
4
|
* A soft colour gradient drawn only in dots: the tone of a slow, smooth
|
|
5
|
-
* shape (a wavy horizon, a glowing band, a swirl, a pinwheel,
|
|
6
|
-
* columns falling) decides at each dot of a fixed grid whether it shows
|
|
5
|
+
* shape (a wavy horizon, a glowing band, a swirl, a pinwheel, stepped
|
|
6
|
+
* columns falling, a soft orb or a glowing pill) decides at each dot of a fixed grid whether it shows
|
|
7
7
|
* (`mode: 'bayer'`, an 8×8 ordered dither: square dots that thin out as the
|
|
8
8
|
* tone falls) or how big it is (`mode: 'halftone'`: round dots that shrink),
|
|
9
|
-
* its colour blended from a dim one to a bright one in Oklab
|
|
9
|
+
* its colour blended from a dim one to a bright one in Oklab (through a
|
|
10
|
+
* middle colour when three are given). The dots keep
|
|
10
11
|
* their size in CSS px; the shapes are measured in widths, so a 330 px card
|
|
11
12
|
* and a 1280 px hero show the same picture.
|
|
12
13
|
*
|
|
@@ -29,10 +30,10 @@ import { watchColors } from './mount.js';
|
|
|
29
30
|
import { pickColors } from './palettes.js';
|
|
30
31
|
|
|
31
32
|
/**
|
|
32
|
-
* @typedef {'wave' | 'band' | 'swirl' | 'pinwheel' | 'steps'} GradientShape
|
|
33
|
+
* @typedef {'wave' | 'band' | 'swirl' | 'pinwheel' | 'steps' | 'orb' | 'pill'} GradientShape
|
|
33
34
|
*
|
|
34
35
|
* @typedef {object} DitherGradientConfig
|
|
35
|
-
* @property {string[]} [colors] Two CSS hex colours
|
|
36
|
+
* @property {string[]} [colors] Two CSS hex colours, the dim one where the tone is low and the bright one where it is full, or three with a middle colour between them. Default a plum and a hot pink.
|
|
36
37
|
* @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`: its first and last colours.
|
|
37
38
|
* @property {string} [background] A CSS hex colour to fill behind the dots; none leaves the canvas clear there.
|
|
38
39
|
* @property {GradientShape} [shape='wave'] The gradient's shape.
|
|
@@ -46,6 +47,7 @@ import { pickColors } from './palettes.js';
|
|
|
46
47
|
* @property {number} [twist=2] How tightly the swirl winds (per e-fold of radius) and the pinwheel bends (turns per width).
|
|
47
48
|
* @property {number} [rate=0.03] How fast it moves, cycles a second.
|
|
48
49
|
* @property {number} [block=6] The steps' block, in dots.
|
|
50
|
+
* @property {number} [size=0.3] The orb's radius, and the pill's thickness's share, in widths.
|
|
49
51
|
* @property {number} [steps=0] Colour bands from dim to bright; 0 blends smoothly.
|
|
50
52
|
* @property {[number, number]} [centre=[0.5, 0.5]] The swirl's and pinwheel's centre, and the wave's and band's pivot, 0–1 from the top left.
|
|
51
53
|
* @property {[number, number]} [offset=[0, 0]] Where the shapes' noise starts, so two cards differ.
|
|
@@ -55,7 +57,7 @@ import { pickColors } from './palettes.js';
|
|
|
55
57
|
*/
|
|
56
58
|
|
|
57
59
|
/** The shapes, in the order the shader numbers them. */
|
|
58
|
-
export const GRADIENT_SHAPES = /** @type {const} */ (['wave', 'band', 'swirl', 'pinwheel', 'steps']);
|
|
60
|
+
export const GRADIENT_SHAPES = /** @type {const} */ (['wave', 'band', 'swirl', 'pinwheel', 'steps', 'orb', 'pill']);
|
|
59
61
|
|
|
60
62
|
/** The settings' defaults, shared by the shader and the JS twin. */
|
|
61
63
|
export const GRADIENT_DEFAULTS = {
|
|
@@ -70,6 +72,7 @@ export const GRADIENT_DEFAULTS = {
|
|
|
70
72
|
twist: 2,
|
|
71
73
|
rate: 0.03,
|
|
72
74
|
block: 6,
|
|
75
|
+
size: 0.3,
|
|
73
76
|
steps: 0,
|
|
74
77
|
centre: /** @type {[number, number]} */ ([0.5, 0.5]),
|
|
75
78
|
};
|
|
@@ -91,6 +94,7 @@ uniform float uArms;
|
|
|
91
94
|
uniform float uTwist;
|
|
92
95
|
uniform float uRate;
|
|
93
96
|
uniform float uBlock;
|
|
97
|
+
uniform float uSizeW;
|
|
94
98
|
uniform vec2 uCentre;
|
|
95
99
|
uniform vec2 uOffset;
|
|
96
100
|
float gradientTone(vec2 c, float H, float t) {
|
|
@@ -99,6 +103,15 @@ float gradientTone(vec2 c, float H, float t) {
|
|
|
99
103
|
float u = p.x * k + p.y * s;
|
|
100
104
|
float v = p.y * k - p.x * s;
|
|
101
105
|
float ph = t * uRate;
|
|
106
|
+
if (uShape > 4.5) {
|
|
107
|
+
// the orb and the pill: a soft glow wandering slowly about the centre
|
|
108
|
+
vec2 w = vec2(gnoise(vec2(ph * 0.9 + uOffset.x, uOffset.y)), gnoise(vec2(uOffset.x, ph * 0.9 + uOffset.y))) - 0.5;
|
|
109
|
+
vec2 d = vec2(u, v) - w * 0.24;
|
|
110
|
+
if (uShape > 5.5) d.x = max(abs(d.x) - uSizeW * 1.1, 0.0);
|
|
111
|
+
float r0 = max(uShape > 5.5 ? uSizeW * 0.55 : uSizeW, 0.02) * (1.0 + 0.08 * sin(6.2831853 * ph));
|
|
112
|
+
float e = clamp(uSoft, 0.05, 1.0);
|
|
113
|
+
return exp(-pow(length(d) / r0, 2.0) * (1.2 / e));
|
|
114
|
+
}
|
|
102
115
|
if (uShape < 0.5) {
|
|
103
116
|
float h = uLevel + 0.07 * sin(6.2831853 * (u * 1.1 + ph)) + 0.22 * (gnoise(vec2(u * 2.2 + uOffset.x, ph * 0.8 + uOffset.y)) - 0.5);
|
|
104
117
|
return smoothstep(-uSoft * 0.5, uSoft * 0.5, v - h);
|
|
@@ -135,6 +148,7 @@ uniform float uMode;
|
|
|
135
148
|
uniform float uFill;
|
|
136
149
|
uniform float uSteps;
|
|
137
150
|
uniform vec3 uLow;
|
|
151
|
+
uniform vec3 uMid;
|
|
138
152
|
uniform vec3 uHigh;
|
|
139
153
|
uniform vec4 uBg;
|
|
140
154
|
${GLSL_OKLAB}
|
|
@@ -169,7 +183,7 @@ void main() {
|
|
|
169
183
|
}
|
|
170
184
|
|
|
171
185
|
float tq = uSteps > 0.5 ? floor(tone * uSteps + 0.5) / uSteps : tone;
|
|
172
|
-
vec3 col = fromOklab(mix(uLow, uHigh, tq));
|
|
186
|
+
vec3 col = fromOklab(tq < 0.5 ? mix(uLow, uMid, tq * 2.0) : mix(uMid, uHigh, tq * 2.0 - 1.0));
|
|
173
187
|
gl_FragColor = vec4(col * lit + uBg.rgb * uBg.a * (1.0 - lit), lit + uBg.a * (1.0 - lit));
|
|
174
188
|
}
|
|
175
189
|
`;
|
|
@@ -229,6 +243,16 @@ export function gradientTone(s, x, y, H, time = 0) {
|
|
|
229
243
|
const v = py * k - px * sn;
|
|
230
244
|
const ph = time * s.rate;
|
|
231
245
|
const [ox, oy] = s.offset;
|
|
246
|
+
if (s.shapeIndex >= 5) {
|
|
247
|
+
const wx = gnoise(ph * 0.9 + ox, oy) - 0.5;
|
|
248
|
+
const wy = gnoise(ox, ph * 0.9 + oy) - 0.5;
|
|
249
|
+
let dx = u - wx * 0.24;
|
|
250
|
+
const dy = v - wy * 0.24;
|
|
251
|
+
if (s.shapeIndex === 6) dx = Math.max(Math.abs(dx) - s.size * 1.1, 0);
|
|
252
|
+
const r0 = Math.max(s.shapeIndex === 6 ? s.size * 0.55 : s.size, 0.02) * (1 + 0.08 * Math.sin(2 * Math.PI * ph));
|
|
253
|
+
const e = Math.min(1, Math.max(0.05, s.soft));
|
|
254
|
+
return Math.exp(-((Math.hypot(dx, dy) / r0) ** 2) * (1.2 / e));
|
|
255
|
+
}
|
|
232
256
|
if (s.shapeIndex === 0) {
|
|
233
257
|
const h = s.level + 0.07 * Math.sin(2 * Math.PI * (u * 1.1 + ph)) + 0.22 * (gnoise(u * 2.2 + ox, ph * 0.8 + oy) - 0.5);
|
|
234
258
|
return smooth(-s.soft * 0.5, s.soft * 0.5, v - h);
|
|
@@ -281,6 +305,22 @@ export function gradientDots(config, cols, rows, time = 0) {
|
|
|
281
305
|
);
|
|
282
306
|
}
|
|
283
307
|
|
|
308
|
+
/**
|
|
309
|
+
* The three colours the dots are blended through, low to high: a middle
|
|
310
|
+
* colour of their own when three or more are given, else halfway in Oklab
|
|
311
|
+
* (so two colours blend exactly as before).
|
|
312
|
+
*
|
|
313
|
+
* @param {DitherGradientConfig} config The settings.
|
|
314
|
+
* @returns {[string, string, string]} The dim colour, the middle and the bright one.
|
|
315
|
+
*/
|
|
316
|
+
export function gradientRamp(config) {
|
|
317
|
+
const colors = pickColors(config, PINK);
|
|
318
|
+
const low = colors[0];
|
|
319
|
+
const high = colors[colors.length - 1];
|
|
320
|
+
const mid = colors.length >= 3 ? colors[Math.floor(colors.length / 2)] : toHex(mixOklab(parseColor(low), parseColor(high), 0.5));
|
|
321
|
+
return [low, mid, high];
|
|
322
|
+
}
|
|
323
|
+
|
|
284
324
|
/**
|
|
285
325
|
* The two colours as the shader takes them.
|
|
286
326
|
*
|
|
@@ -307,6 +347,8 @@ function shapeLayer(config, low, mid, high) {
|
|
|
307
347
|
const at = `${Math.round(cx * 100)}% ${Math.round(cy * 100)}%`;
|
|
308
348
|
// CSS angles point where a gradient runs to: 0deg starts at the bottom, as `angle` 0 rises from it
|
|
309
349
|
const to = Math.round(o.angle);
|
|
350
|
+
if (o.shape === 'orb') return `radial-gradient(circle at ${at}, ${high} 0%, ${mid} ${Math.round(o.size * 55)}%, ${low} ${Math.round(o.size * 95)}%, transparent ${Math.round(o.size * 150)}%)`;
|
|
351
|
+
if (o.shape === 'pill') return `radial-gradient(ellipse ${Math.round(o.size * 160)}% ${Math.round(o.size * 60)}% at ${at}, ${high} 0%, ${mid} 40%, ${low} 70%, transparent 100%)`;
|
|
310
352
|
if (o.shape === 'band') return `linear-gradient(${to}deg, transparent 22%, ${low} 36%, ${high} 50%, ${low} 64%, transparent 78%)`;
|
|
311
353
|
if (o.shape === 'swirl' || o.shape === 'pinwheel') {
|
|
312
354
|
const arm = 360 / Math.max(1, Math.round(o.arms));
|
|
@@ -325,10 +367,9 @@ function shapeLayer(config, low, mid, high) {
|
|
|
325
367
|
* @returns {string} The CSS background.
|
|
326
368
|
*/
|
|
327
369
|
export function gradientStill(config) {
|
|
328
|
-
const [low, high] =
|
|
370
|
+
const [low, mid, high] = gradientRamp(config);
|
|
329
371
|
const ground = config.background ?? '#000000';
|
|
330
372
|
const dot = Math.max(1, config.dot ?? GRADIENT_DEFAULTS.dot);
|
|
331
|
-
const mid = toHex(mixOklab(low, high, 0.5));
|
|
332
373
|
const pc = (/** @type {number} */ n) => `${Math.round(n * 100)}%`;
|
|
333
374
|
const quiet = config.quiet;
|
|
334
375
|
const r = pc((quiet?.radius ?? 0.8) * 0.55);
|
|
@@ -339,7 +380,7 @@ export function gradientStill(config) {
|
|
|
339
380
|
return [
|
|
340
381
|
quiet ? `radial-gradient(${r} ${r} at ${pc(quiet.x ?? 0.5)} ${pc(quiet.y ?? 0.5)}, ${ground} 55%, transparent 100%)` : '',
|
|
341
382
|
screen,
|
|
342
|
-
shapeLayer(config, toHex(low), mid, toHex(high)),
|
|
383
|
+
shapeLayer(config, toHex(parseColor(low)), toHex(parseColor(mid)), toHex(parseColor(high))),
|
|
343
384
|
ground,
|
|
344
385
|
]
|
|
345
386
|
.filter(Boolean)
|
|
@@ -357,7 +398,7 @@ export function gradientStill(config) {
|
|
|
357
398
|
export function ditherGradient(el, config) {
|
|
358
399
|
const speed = config.speed ?? 1;
|
|
359
400
|
const lab = (/** @type {string} */ c) => toOklab(parseColor(c));
|
|
360
|
-
let [low, high] =
|
|
401
|
+
let [low, mid, high] = gradientRamp(config).map(lab);
|
|
361
402
|
const bg = config.background ? [...parseColor(config.background), 1] : [0, 0, 0, 0];
|
|
362
403
|
const dot = Math.max(1, config.dot ?? GRADIENT_DEFAULTS.dot);
|
|
363
404
|
const start = performance.now();
|
|
@@ -387,6 +428,7 @@ export function ditherGradient(el, config) {
|
|
|
387
428
|
gl.uniform1f(uniform('uTwist'), s.twist);
|
|
388
429
|
gl.uniform1f(uniform('uRate'), s.rate);
|
|
389
430
|
gl.uniform1f(uniform('uBlock'), s.blockW);
|
|
431
|
+
gl.uniform1f(uniform('uSizeW'), s.size);
|
|
390
432
|
gl.uniform2f(uniform('uCentre'), s.centre[0], s.centre[1]);
|
|
391
433
|
gl.uniform2f(uniform('uOffset'), s.offset[0], s.offset[1]);
|
|
392
434
|
gl.uniform4f(uniform('uQuiet'), ...quietUniform(config.quiet, cols / rows));
|
|
@@ -394,13 +436,14 @@ export function ditherGradient(el, config) {
|
|
|
394
436
|
uniforms({ gl, uniform }, now) {
|
|
395
437
|
gl.uniform1f(uniform('uTime'), ((now - start) / 1000) * Math.max(0, speed));
|
|
396
438
|
gl.uniform3f(uniform('uLow'), low[0], low[1], low[2]);
|
|
439
|
+
gl.uniform3f(uniform('uMid'), mid[0], mid[1], mid[2]);
|
|
397
440
|
gl.uniform3f(uniform('uHigh'), high[0], high[1], high[2]);
|
|
398
441
|
},
|
|
399
442
|
});
|
|
400
443
|
if (!stage) return stop;
|
|
401
444
|
|
|
402
445
|
const unwatch = watchColors(el, (next) => {
|
|
403
|
-
[low, high] =
|
|
446
|
+
[low, mid, high] = gradientRamp({ colors: next.colors }).map(lab);
|
|
404
447
|
if (stage.still) stage.redraw();
|
|
405
448
|
});
|
|
406
449
|
return () => {
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { PaletteName } from './palettes.js';
|
|
2
|
+
|
|
3
|
+
/** The folds' styles: bending every way, or lying across the frame. */
|
|
4
|
+
export type FoldStyle = 'liquid' | 'dunes';
|
|
5
|
+
|
|
6
|
+
export interface FluidFoldsConfig {
|
|
7
|
+
/** Three CSS hex colours along the folds: deep, mid and hot. Default cobalt, violet and coral. */
|
|
8
|
+
colors?: string[];
|
|
9
|
+
/** A shared palette by name (`PALETTES`, any case), when there are no `colors`. */
|
|
10
|
+
palette?: PaletteName | (string & {});
|
|
11
|
+
/** The ground, painted everywhere (the folds' deepest shadow). Default '#050409'. */
|
|
12
|
+
background?: string;
|
|
13
|
+
/** Folds bending every way like poured enamel, or long folds lying across the frame like silk dunes. Default 'liquid'. */
|
|
14
|
+
style?: FoldStyle;
|
|
15
|
+
/** How many folds across the height. Default 1.6. */
|
|
16
|
+
scale?: number;
|
|
17
|
+
/** How far the noise bends the folds. Default 0.9. */
|
|
18
|
+
warp?: number;
|
|
19
|
+
/** How bright and tight the highlight along each crest is; 0 for none. Default 0.8. */
|
|
20
|
+
gloss?: number;
|
|
21
|
+
/** Where the light comes from, degrees from straight above (negative from the left). Default -30. */
|
|
22
|
+
light?: number;
|
|
23
|
+
/** How fast the colour runs across the folds (higher shows more of the ramp at once). Default 0.5. */
|
|
24
|
+
hue?: number;
|
|
25
|
+
/** How fast the folds move, cycles a second. Default 0.03. */
|
|
26
|
+
rate?: number;
|
|
27
|
+
/** For dunes, where the folds sit, a share of the height from the top (above it, the dark sky). Default 0.55. */
|
|
28
|
+
level?: number;
|
|
29
|
+
/** Fine grain over all of it; 0 for none. Default 0.03. */
|
|
30
|
+
grain?: number;
|
|
31
|
+
/** Where its noise starts, so two cards differ. Default 0. */
|
|
32
|
+
seed?: number;
|
|
33
|
+
/** Plays every clock faster or slower; 0 for one still frame. Default 1. */
|
|
34
|
+
speed?: number;
|
|
35
|
+
/** An area dimmed: centre (0–1 from the top left), radius (share of the height), depth (0–1). */
|
|
36
|
+
quiet?: { x?: number; y?: number; radius?: number; depth?: number } | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The styles, in the order the shader numbers them. */
|
|
40
|
+
export declare const FOLD_STYLES: readonly ['liquid', 'dunes'];
|
|
41
|
+
|
|
42
|
+
/** The settings' defaults, shared by the shader and the JS twin. */
|
|
43
|
+
export declare const FOLD_DEFAULTS: Required<Omit<FluidFoldsConfig, 'colors' | 'palette' | 'speed' | 'quiet'>>;
|
|
44
|
+
|
|
45
|
+
/** The folds' height at a point (heights from the top left), 0–1: a crest near 1, the hollow behind it near 0. */
|
|
46
|
+
export declare function foldHeight(config: FluidFoldsConfig, x: number, y: number, time?: number): number;
|
|
47
|
+
|
|
48
|
+
/** Where on the colour ramp a point is, 0–1 round deep, mid, hot and back. */
|
|
49
|
+
export declare function foldHue(config: FluidFoldsConfig, x: number, y: number, time?: number): number;
|
|
50
|
+
|
|
51
|
+
/** The three colours as the shader takes them: deep, mid and hot (fewer repeat). */
|
|
52
|
+
export declare function foldColors(config: FluidFoldsConfig): [string, string, string];
|
|
53
|
+
|
|
54
|
+
/** A CSS `background` that stands in for the folds before the shader starts and without WebGL. */
|
|
55
|
+
export declare function foldsStill(config: FluidFoldsConfig): string;
|
|
56
|
+
|
|
57
|
+
/** Starts the folds on an element (its first canvas). Returns a function that stops it. */
|
|
58
|
+
export declare function fluidFolds(el: HTMLElement, config: FluidFoldsConfig): () => void;
|