@arraypress/effects-astro 0.0.0-stage → 0.1.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 +85 -0
- package/COMPONENTS.md +1264 -0
- package/LICENSE +139 -0
- package/README.md +197 -2
- package/package.json +60 -4
- package/src/components/AsciiRain.astro +36 -0
- package/src/components/BorderSweep.astro +39 -0
- package/src/components/Caustics.astro +39 -0
- package/src/components/ColorPanels.astro +62 -0
- package/src/components/Cursor.astro +97 -0
- package/src/components/DotGrid.astro +34 -0
- package/src/components/DotSurface.astro +35 -0
- package/src/components/EffectCanvas.astro +152 -0
- package/src/components/FitText.astro +35 -0
- package/src/components/FlutedGlass.astro +36 -0
- package/src/components/Glass.astro +69 -0
- package/src/components/GlassGlyph.astro +38 -0
- package/src/components/GlowField.astro +177 -0
- package/src/components/Grain.astro +98 -0
- package/src/components/HaloRing.astro +38 -0
- package/src/components/HighlightSweep.astro +74 -0
- package/src/components/ImageRipple.astro +56 -0
- package/src/components/Ink.astro +37 -0
- package/src/components/InkField.astro +45 -0
- package/src/components/IsoCity.astro +54 -0
- package/src/components/LightField.astro +40 -0
- package/src/components/LiquidMetal.astro +41 -0
- package/src/components/Magnetic.astro +52 -0
- package/src/components/Marquee.astro +216 -0
- package/src/components/MosaicReveal.astro +196 -0
- package/src/components/NebulaLogo.astro +38 -0
- package/src/components/NeonSwarm.astro +38 -0
- package/src/components/Ocean.astro +40 -0
- package/src/components/OutlineWordmark.astro +222 -0
- package/src/components/PaperBackground.astro +40 -0
- package/src/components/PaperShader.astro +55 -0
- package/src/components/Parallax.astro +49 -0
- package/src/components/ParticleLogo.astro +37 -0
- package/src/components/PixelGlitchText.astro +70 -0
- package/src/components/PointCloud.astro +37 -0
- package/src/components/ProductStack.astro +298 -0
- package/src/components/PulseMark.astro +189 -0
- package/src/components/RadiantGlass.astro +38 -0
- package/src/components/RainOnGlass.astro +71 -0
- package/src/components/Reveal.astro +115 -0
- package/src/components/ScrambleText.astro +52 -0
- package/src/components/ScrollReveal.astro +38 -0
- package/src/components/ShaderBackground.astro +55 -0
- package/src/components/SignalLines.astro +41 -0
- package/src/components/SilkRibbon.astro +37 -0
- package/src/components/SpotlightText.astro +131 -0
- package/src/components/Tilt.astro +79 -0
- package/src/components/Topography.astro +38 -0
- package/src/components/Typewriter.astro +66 -0
- package/src/components/VariableType.astro +59 -0
- package/src/components/VoxelLogo.astro +46 -0
- package/src/components/WaveBars.astro +41 -0
- package/src/components/WorldRoutes.astro +41 -0
- package/src/components/style.js +19 -0
- package/src/index.d.ts +143 -0
- package/src/index.js +105 -0
- package/src/runtime/ascii-rain.d.ts +53 -0
- package/src/runtime/ascii-rain.js +355 -0
- package/src/runtime/audio-meter.d.ts +65 -0
- package/src/runtime/audio-meter.js +282 -0
- package/src/runtime/audio.d.ts +26 -0
- package/src/runtime/audio.js +453 -0
- package/src/runtime/blur.d.ts +2 -0
- package/src/runtime/blur.js +56 -0
- package/src/runtime/canvas2d.d.ts +23 -0
- package/src/runtime/canvas2d.js +105 -0
- package/src/runtime/caustics.d.ts +40 -0
- package/src/runtime/caustics.js +286 -0
- package/src/runtime/color.d.ts +33 -0
- package/src/runtime/color.js +213 -0
- package/src/runtime/curl.d.ts +5 -0
- package/src/runtime/curl.js +81 -0
- package/src/runtime/cursor.d.ts +9 -0
- package/src/runtime/cursor.js +80 -0
- package/src/runtime/device.d.ts +14 -0
- package/src/runtime/device.js +73 -0
- package/src/runtime/dot-grid.d.ts +27 -0
- package/src/runtime/dot-grid.js +245 -0
- package/src/runtime/dot-surface.d.ts +46 -0
- package/src/runtime/dot-surface.js +429 -0
- package/src/runtime/feedback.d.ts +18 -0
- package/src/runtime/feedback.js +131 -0
- package/src/runtime/fit-text.d.ts +5 -0
- package/src/runtime/fit-text.js +60 -0
- package/src/runtime/fluid.d.ts +55 -0
- package/src/runtime/fluid.js +504 -0
- package/src/runtime/fluted-glass.d.ts +27 -0
- package/src/runtime/fluted-glass.js +157 -0
- package/src/runtime/gl.d.ts +19 -0
- package/src/runtime/gl.js +104 -0
- package/src/runtime/glass-glyph.d.ts +49 -0
- package/src/runtime/glass-glyph.js +355 -0
- package/src/runtime/glass-sheen.d.ts +2 -0
- package/src/runtime/glass-sheen.js +30 -0
- package/src/runtime/glsl.d.ts +17 -0
- package/src/runtime/glsl.js +78 -0
- package/src/runtime/glyphs.d.ts +22 -0
- package/src/runtime/glyphs.js +107 -0
- package/src/runtime/halo-ring.d.ts +47 -0
- package/src/runtime/halo-ring.js +334 -0
- package/src/runtime/height-field.d.ts +50 -0
- package/src/runtime/height-field.js +176 -0
- package/src/runtime/image-ripple.d.ts +25 -0
- package/src/runtime/image-ripple.js +353 -0
- package/src/runtime/image.d.ts +11 -0
- package/src/runtime/image.js +81 -0
- package/src/runtime/in-view.d.ts +6 -0
- package/src/runtime/in-view.js +36 -0
- package/src/runtime/ink-field/shaders.js +258 -0
- package/src/runtime/ink-field/sim.js +582 -0
- package/src/runtime/ink-field.d.ts +39 -0
- package/src/runtime/ink-field.js +311 -0
- package/src/runtime/ink.d.ts +31 -0
- package/src/runtime/ink.js +109 -0
- package/src/runtime/instancing.d.ts +12 -0
- package/src/runtime/instancing.js +37 -0
- package/src/runtime/iso-camera.d.ts +35 -0
- package/src/runtime/iso-camera.js +85 -0
- package/src/runtime/iso-city/figures.d.ts +30 -0
- package/src/runtime/iso-city/figures.js +136 -0
- package/src/runtime/iso-city/look.d.ts +34 -0
- package/src/runtime/iso-city/look.js +105 -0
- package/src/runtime/iso-city/plan.d.ts +59 -0
- package/src/runtime/iso-city/plan.js +463 -0
- package/src/runtime/iso-city/roads.d.ts +64 -0
- package/src/runtime/iso-city/roads.js +320 -0
- package/src/runtime/iso-city/scene.d.ts +27 -0
- package/src/runtime/iso-city/scene.js +432 -0
- package/src/runtime/iso-city/shaders.d.ts +6 -0
- package/src/runtime/iso-city/shaders.js +233 -0
- package/src/runtime/iso-city/shadows.d.ts +13 -0
- package/src/runtime/iso-city/shadows.js +148 -0
- package/src/runtime/iso-city/traffic.d.ts +80 -0
- package/src/runtime/iso-city/traffic.js +457 -0
- package/src/runtime/iso-city.d.ts +37 -0
- package/src/runtime/iso-city.js +458 -0
- package/src/runtime/lens-map.d.ts +11 -0
- package/src/runtime/lens-map.js +146 -0
- package/src/runtime/light-field.d.ts +29 -0
- package/src/runtime/light-field.js +292 -0
- package/src/runtime/liquid-glass.d.ts +48 -0
- package/src/runtime/liquid-glass.js +423 -0
- package/src/runtime/liquid-metal/beads.js +217 -0
- package/src/runtime/liquid-metal/field.js +88 -0
- package/src/runtime/liquid-metal/look.js +64 -0
- package/src/runtime/liquid-metal/shaders.js +255 -0
- package/src/runtime/liquid-metal/wave.js +53 -0
- package/src/runtime/liquid-metal.d.ts +46 -0
- package/src/runtime/liquid-metal.js +366 -0
- package/src/runtime/loop.d.ts +7 -0
- package/src/runtime/loop.js +112 -0
- package/src/runtime/magnetic.d.ts +9 -0
- package/src/runtime/magnetic.js +46 -0
- package/src/runtime/marquee.d.ts +2 -0
- package/src/runtime/marquee.js +27 -0
- package/src/runtime/mesh.d.ts +30 -0
- package/src/runtime/mesh.js +217 -0
- package/src/runtime/mosaic-reveal.d.ts +34 -0
- package/src/runtime/mosaic-reveal.js +504 -0
- package/src/runtime/motion.d.ts +2 -0
- package/src/runtime/motion.js +21 -0
- package/src/runtime/mount.d.ts +13 -0
- package/src/runtime/mount.js +120 -0
- package/src/runtime/nebula-logo.d.ts +31 -0
- package/src/runtime/nebula-logo.js +282 -0
- package/src/runtime/neon-swarm.d.ts +31 -0
- package/src/runtime/neon-swarm.js +258 -0
- package/src/runtime/ocean/presets.d.ts +54 -0
- package/src/runtime/ocean/presets.js +184 -0
- package/src/runtime/ocean/shader.d.ts +14 -0
- package/src/runtime/ocean/shader.js +389 -0
- package/src/runtime/ocean/view.d.ts +24 -0
- package/src/runtime/ocean/view.js +98 -0
- package/src/runtime/ocean/waves.d.ts +29 -0
- package/src/runtime/ocean/waves.js +119 -0
- package/src/runtime/ocean.d.ts +31 -0
- package/src/runtime/ocean.js +173 -0
- package/src/runtime/palettes.d.ts +37 -0
- package/src/runtime/palettes.js +75 -0
- package/src/runtime/paper-look.d.ts +42 -0
- package/src/runtime/paper-look.js +91 -0
- package/src/runtime/paper-looks.d.ts +17 -0
- package/src/runtime/paper-looks.js +21 -0
- package/src/runtime/paper.d.ts +37 -0
- package/src/runtime/paper.js +285 -0
- package/src/runtime/particle-logo.d.ts +31 -0
- package/src/runtime/particle-logo.js +196 -0
- package/src/runtime/ping-pong.d.ts +43 -0
- package/src/runtime/ping-pong.js +175 -0
- package/src/runtime/pixel-glitch.d.ts +17 -0
- package/src/runtime/pixel-glitch.js +287 -0
- package/src/runtime/point-cloud.d.ts +33 -0
- package/src/runtime/point-cloud.js +287 -0
- package/src/runtime/pointer.d.ts +27 -0
- package/src/runtime/pointer.js +128 -0
- package/src/runtime/points.d.ts +25 -0
- package/src/runtime/points.js +130 -0
- package/src/runtime/pools.d.ts +2 -0
- package/src/runtime/pools.js +25 -0
- package/src/runtime/product-stack.d.ts +24 -0
- package/src/runtime/product-stack.js +210 -0
- package/src/runtime/radiant-glass.d.ts +29 -0
- package/src/runtime/radiant-glass.js +282 -0
- package/src/runtime/rain-on-glass/backdrop.d.ts +22 -0
- package/src/runtime/rain-on-glass/backdrop.js +185 -0
- package/src/runtime/rain-on-glass/shader.d.ts +2 -0
- package/src/runtime/rain-on-glass/shader.js +168 -0
- package/src/runtime/rain-on-glass/wipe.d.ts +16 -0
- package/src/runtime/rain-on-glass/wipe.js +65 -0
- package/src/runtime/rain-on-glass.d.ts +27 -0
- package/src/runtime/rain-on-glass.js +210 -0
- package/src/runtime/ramp.d.ts +2 -0
- package/src/runtime/ramp.js +30 -0
- package/src/runtime/random.d.ts +2 -0
- package/src/runtime/random.js +22 -0
- package/src/runtime/scroll-reveal.d.ts +22 -0
- package/src/runtime/scroll-reveal.js +73 -0
- package/src/runtime/shader-background.d.ts +42 -0
- package/src/runtime/shader-background.js +261 -0
- package/src/runtime/shader-backgrounds/band-lens.js +72 -0
- package/src/runtime/shader-backgrounds/common.js +53 -0
- package/src/runtime/shader-backgrounds/grain-gradient.js +87 -0
- package/src/runtime/shader-backgrounds/grid.js +33 -0
- package/src/runtime/shader-backgrounds/mesh-gradient.js +74 -0
- package/src/runtime/shader-backgrounds/silk.js +57 -0
- package/src/runtime/shader-backgrounds/waves.js +31 -0
- package/src/runtime/shape.d.ts +42 -0
- package/src/runtime/shape.js +313 -0
- package/src/runtime/silk-ribbon.d.ts +23 -0
- package/src/runtime/silk-ribbon.js +206 -0
- package/src/runtime/slideshow.d.ts +27 -0
- package/src/runtime/slideshow.js +234 -0
- package/src/runtime/spotlight.d.ts +9 -0
- package/src/runtime/spotlight.js +97 -0
- package/src/runtime/stack-poses.d.ts +53 -0
- package/src/runtime/stack-poses.js +273 -0
- package/src/runtime/stage.d.ts +47 -0
- package/src/runtime/stage.js +187 -0
- package/src/runtime/swarm.d.ts +49 -0
- package/src/runtime/swarm.js +199 -0
- package/src/runtime/text-motion.d.ts +41 -0
- package/src/runtime/text-motion.js +165 -0
- package/src/runtime/text.d.ts +11 -0
- package/src/runtime/text.js +90 -0
- package/src/runtime/tilt.d.ts +19 -0
- package/src/runtime/tilt.js +116 -0
- package/src/runtime/topography.d.ts +71 -0
- package/src/runtime/topography.js +650 -0
- package/src/runtime/trackers.d.ts +21 -0
- package/src/runtime/trackers.js +76 -0
- package/src/runtime/variable-type.d.ts +43 -0
- package/src/runtime/variable-type.js +358 -0
- package/src/runtime/voxel-logo.d.ts +31 -0
- package/src/runtime/voxel-logo.js +237 -0
- package/src/runtime/waves.d.ts +70 -0
- package/src/runtime/waves.js +799 -0
- package/src/runtime/world-labels.d.ts +29 -0
- package/src/runtime/world-labels.js +59 -0
- package/src/runtime/world-land.d.ts +8 -0
- package/src/runtime/world-land.js +105 -0
- package/src/runtime/world-map.d.ts +69 -0
- package/src/runtime/world-map.js +308 -0
- package/src/runtime/world-plan.d.ts +101 -0
- package/src/runtime/world-plan.js +333 -0
- package/src/runtime/world-routes.d.ts +75 -0
- package/src/runtime/world-routes.js +673 -0
- package/src/styles/border-sweep.css +82 -0
- package/src/styles/glass.css +104 -0
- package/src/styles/motion.css +218 -0
- package/src/styles/reveal.css +51 -0
- package/src/vendor/paper/LICENSE +201 -0
- package/src/vendor/paper/NOTICE +5 -0
- package/src/vendor/paper/README.md +8 -0
- package/src/vendor/paper/get-shader-color-from-string.js +100 -0
- package/src/vendor/paper/get-shader-noise-texture.js +17 -0
- package/src/vendor/paper/presets.js +3678 -0
- package/src/vendor/paper/shader-sizing.js +37 -0
- package/src/vendor/paper/shader-utils.js +130 -0
- package/src/vendor/paper/shaders/color-panels.js +223 -0
- package/src/vendor/paper/shaders/dithering.js +270 -0
- package/src/vendor/paper/shaders/dot-grid.js +109 -0
- package/src/vendor/paper/shaders/dot-orbit.js +122 -0
- package/src/vendor/paper/shaders/fluted-glass.js +360 -0
- package/src/vendor/paper/shaders/gem-smoke.js +572 -0
- package/src/vendor/paper/shaders/god-rays.js +132 -0
- package/src/vendor/paper/shaders/grain-gradient.js +300 -0
- package/src/vendor/paper/shaders/halftone-cmyk.js +294 -0
- package/src/vendor/paper/shaders/halftone-dots.js +320 -0
- package/src/vendor/paper/shaders/heatmap.js +383 -0
- package/src/vendor/paper/shaders/image-dithering.js +198 -0
- package/src/vendor/paper/shaders/lens-distortion.js +275 -0
- package/src/vendor/paper/shaders/liquid-metal.js +632 -0
- package/src/vendor/paper/shaders/mesh-gradient.js +130 -0
- package/src/vendor/paper/shaders/metaballs.js +110 -0
- package/src/vendor/paper/shaders/neuro-noise.js +76 -0
- package/src/vendor/paper/shaders/paper-texture.js +526 -0
- package/src/vendor/paper/shaders/perlin-noise.js +166 -0
- package/src/vendor/paper/shaders/pulsing-border.js +238 -0
- package/src/vendor/paper/shaders/simplex-noise.js +91 -0
- package/src/vendor/paper/shaders/smoke-ring.js +132 -0
- package/src/vendor/paper/shaders/spiral.js +82 -0
- package/src/vendor/paper/shaders/static-mesh-gradient.js +130 -0
- package/src/vendor/paper/shaders/static-radial-gradient.js +187 -0
- package/src/vendor/paper/shaders/swirl.js +103 -0
- package/src/vendor/paper/shaders/voronoi.js +138 -0
- package/src/vendor/paper/shaders/warp.js +129 -0
- package/src/vendor/paper/shaders/water.js +121 -0
- package/src/vendor/paper/shaders/waves.js +65 -0
- package/src/vendor/paper/vertex-shader.js +159 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/ocean/view
|
|
3
|
+
*
|
|
4
|
+
* The camera over the sea: a pinhole a few metres above the water,
|
|
5
|
+
* pitched slightly down, its lens shifted (as an architect's camera
|
|
6
|
+
* shifts) so the horizon lands where the copy needs it while the horizon
|
|
7
|
+
* stays level and straight. Also where a point on the frame looks, and
|
|
8
|
+
* where the sun sits for a time of day or a `sun` override.
|
|
9
|
+
*
|
|
10
|
+
* World space: x right, y up, z ahead; metres. Frame space: x 0–1 from
|
|
11
|
+
* the left, y 0–1 from the bottom, as `pointerIn` gives them.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** How far the camera looks down, radians. */
|
|
15
|
+
const PITCH = (3 * Math.PI) / 180;
|
|
16
|
+
/** The lens: focal length in units of the frame's height (about a 42° view top to bottom). */
|
|
17
|
+
const FOCAL = 1.3;
|
|
18
|
+
/** The narrowest frame (width over height) the lens keeps its focal length for; narrower frames widen it so a phone still sees the sea. */
|
|
19
|
+
const NARROW = 1.15;
|
|
20
|
+
/** The lowest the sun may sit, radians: just clear of the horizon. */
|
|
21
|
+
const LOWEST = (0.4 * Math.PI) / 180;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @typedef {[number, number, number]} Vec3
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {object} OceanView
|
|
29
|
+
* @property {Vec3} eye Where the camera is, metres.
|
|
30
|
+
* @property {Vec3} right The camera's right, a unit vector.
|
|
31
|
+
* @property {Vec3} up Its up.
|
|
32
|
+
* @property {Vec3} forward Where it looks.
|
|
33
|
+
* @property {number} focal Focal length, in units of the frame's height.
|
|
34
|
+
* @property {number} shift How far the lens is shifted down, in units of the frame's height.
|
|
35
|
+
* @property {number} aspect The frame's width over its height.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The camera for a frame.
|
|
40
|
+
*
|
|
41
|
+
* @param {object} options The camera.
|
|
42
|
+
* @param {number} options.height How high above the sea, metres.
|
|
43
|
+
* @param {number} options.horizon Where the horizon sits, 0–1 up the frame.
|
|
44
|
+
* @param {number} options.aspect The frame's width over its height.
|
|
45
|
+
* @param {number} [options.x=0] How far to the side it has moved, metres (parallax).
|
|
46
|
+
* @param {number} [options.lift=0] How far it has risen, metres.
|
|
47
|
+
* @returns {OceanView} The camera.
|
|
48
|
+
*/
|
|
49
|
+
export function oceanView({ height, horizon, aspect, x = 0, lift = 0 }) {
|
|
50
|
+
const focal = FOCAL * Math.min(1, aspect / NARROW);
|
|
51
|
+
const c = Math.cos(PITCH);
|
|
52
|
+
const s = Math.sin(PITCH);
|
|
53
|
+
return {
|
|
54
|
+
eye: [x, height + lift, 0],
|
|
55
|
+
right: [1, 0, 0],
|
|
56
|
+
up: [0, c, s],
|
|
57
|
+
forward: [0, -s, c],
|
|
58
|
+
focal,
|
|
59
|
+
// A level ray has y 0: -focal·sin + (v - shift)·cos = 0 at v = horizon - 0.5.
|
|
60
|
+
shift: horizon - 0.5 - focal * Math.tan(PITCH),
|
|
61
|
+
aspect,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Where a point on the frame looks.
|
|
67
|
+
*
|
|
68
|
+
* @param {OceanView} view The camera.
|
|
69
|
+
* @param {number} x Across the frame, 0 (left) to 1.
|
|
70
|
+
* @param {number} y Up it, 0 (bottom) to 1.
|
|
71
|
+
* @returns {Vec3} The direction, a unit vector.
|
|
72
|
+
*/
|
|
73
|
+
export function viewRay(view, x, y) {
|
|
74
|
+
const u = (x - 0.5) * view.aspect;
|
|
75
|
+
const v = y - 0.5 - view.shift;
|
|
76
|
+
const d = /** @type {Vec3} */ ([0, 1, 2].map((i) => view.right[i] * u + view.up[i] * v + view.forward[i] * view.focal));
|
|
77
|
+
const length = Math.hypot(...d);
|
|
78
|
+
return /** @type {Vec3} */ (d.map((c) => c / length));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Where the sun is: above the point `x` across the horizon at `elevation`
|
|
83
|
+
* degrees, or, with an override, behind the point on the frame it names.
|
|
84
|
+
* It is kept just clear of the horizon.
|
|
85
|
+
*
|
|
86
|
+
* @param {OceanView} view The camera (its parallax ignored: the sun is far away).
|
|
87
|
+
* @param {number} horizon Where the horizon sits, 0–1 up the frame.
|
|
88
|
+
* @param {{ x: number, elevation: number }} look The time of day's sun.
|
|
89
|
+
* @param {{ x?: number, y?: number } | null} [override] Where to put it instead: x 0–1 across, y 0–1 up the frame.
|
|
90
|
+
* @returns {Vec3} The direction towards it, a unit vector.
|
|
91
|
+
*/
|
|
92
|
+
export function sunDirection(view, horizon, look, override) {
|
|
93
|
+
const x = override?.x ?? look.x;
|
|
94
|
+
const ray = viewRay(view, x, override?.y ?? horizon);
|
|
95
|
+
const across = Math.hypot(ray[0], ray[2]);
|
|
96
|
+
const elevation = Math.max(LOWEST, override?.y === undefined ? (look.elevation * Math.PI) / 180 : Math.asin(ray[1]));
|
|
97
|
+
return [(ray[0] / across) * Math.cos(elevation), Math.sin(elevation), (ray[2] / across) * Math.cos(elevation)];
|
|
98
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** The sea's waves, longest first, as the shader takes them. */
|
|
2
|
+
export interface WaveSet {
|
|
3
|
+
/** How many waves. */
|
|
4
|
+
count: number;
|
|
5
|
+
/** Four floats a wave: direction (x, z), wavenumber (rad/m) and height (m). */
|
|
6
|
+
shape: Float32Array;
|
|
7
|
+
/** Two floats a wave: its phase now (rad, 0 to 2π) and how sharp its crest is. */
|
|
8
|
+
motion: Float32Array;
|
|
9
|
+
/** Each wave's angular speed, rad/s: √(g·k), as deep water runs. */
|
|
10
|
+
speed: Float32Array;
|
|
11
|
+
/** Each wave's phase at time 0. */
|
|
12
|
+
start: Float32Array;
|
|
13
|
+
/** The highest the long waves can lift the sea, metres. */
|
|
14
|
+
crest: number;
|
|
15
|
+
/** How steep the long waves get (twice their rms slope): how far a march may stride. */
|
|
16
|
+
slope: number;
|
|
17
|
+
/** Where the wind drives the sea: a unit vector (x, z). */
|
|
18
|
+
wind: [number, number];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Makes the waves for a sea state (0 glassy to 2 rough) running towards
|
|
23
|
+
* `wind` degrees (0 towards the viewer, 90 left to right): `count` of
|
|
24
|
+
* them from a long swell to ripples, the first `geometry` shaping the surface.
|
|
25
|
+
*/
|
|
26
|
+
export function waveSet(sea: number, wind: number, count: number, geometry: number): WaveSet;
|
|
27
|
+
|
|
28
|
+
/** Moves every wave on to `time` seconds, writing the phases into `set.motion` (returned). */
|
|
29
|
+
export function wavePhases(set: WaveSet, time: number): Float32Array;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/ocean/waves
|
|
3
|
+
*
|
|
4
|
+
* The sea's waves: a set of directional, steep-crested waves from a long
|
|
5
|
+
* swell down to ripples a few centimetres long, made once on the CPU and
|
|
6
|
+
* handed to the shader as uniforms.
|
|
7
|
+
*
|
|
8
|
+
* Wavelengths fall by a steady ratio, each jittered so no two line up and
|
|
9
|
+
* the sum never repeats. Each runs near the wind's direction, the long
|
|
10
|
+
* ones closely and the short ones spread wider, as a wind-driven sea
|
|
11
|
+
* does, with one long swell crossing from another quarter. Heights follow
|
|
12
|
+
* a steady steepness (height times wavenumber), so every scale is as
|
|
13
|
+
* rough as real water is. Each runs at its deep-water speed (ω = √(g·k)),
|
|
14
|
+
* which is what gives the sea its scale: a twenty-metre swell rolls by at
|
|
15
|
+
* about five and a half metres a second, ripples dance.
|
|
16
|
+
*
|
|
17
|
+
* The phases advance on the CPU each frame and are wrapped to one turn,
|
|
18
|
+
* so the shader's sums keep their precision however long the page is open.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/** Gravity, m/s². */
|
|
22
|
+
const G = 9.81;
|
|
23
|
+
/** The shortest wave, metres. */
|
|
24
|
+
const SHORTEST = 0.04;
|
|
25
|
+
/** The longest wave at a moderate sea, metres. */
|
|
26
|
+
const LONGEST = 38;
|
|
27
|
+
/** One turn. */
|
|
28
|
+
const TAU = Math.PI * 2;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {object} WaveSet
|
|
32
|
+
* @property {number} count How many waves.
|
|
33
|
+
* @property {Float32Array} shape Four floats a wave: direction (x, z), wavenumber k (rad/m) and height (m).
|
|
34
|
+
* @property {Float32Array} motion Two floats a wave: its phase now (rad) and how sharp its crest is.
|
|
35
|
+
* @property {Float32Array} speed One float a wave: its angular speed ω (rad/s).
|
|
36
|
+
* @property {Float32Array} start One float a wave: its phase at time 0.
|
|
37
|
+
* @property {number} crest The highest the long waves can lift the sea, metres: the bracket the shader marches in.
|
|
38
|
+
* @property {number} slope How steep the long waves get (twice their rms slope): how far the shader may stride.
|
|
39
|
+
* @property {[number, number]} wind Where the wind drives the sea: a unit vector (x, z).
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A repeatable number in -1–1 for a wave, so the sea is the same on every load.
|
|
44
|
+
*
|
|
45
|
+
* @param {number} i The wave.
|
|
46
|
+
* @param {number} salt Which number for it.
|
|
47
|
+
* @returns {number} The number.
|
|
48
|
+
*/
|
|
49
|
+
function jitter(i, salt) {
|
|
50
|
+
const s = Math.sin(i * 127.1 + salt * 311.7) * 43758.5453;
|
|
51
|
+
return (s - Math.floor(s)) * 2 - 1;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Makes the sea's waves.
|
|
56
|
+
*
|
|
57
|
+
* @param {number} sea The sea state, 0 glassy to 2 rough.
|
|
58
|
+
* @param {number} wind Where the waves run, degrees: 0 straight towards the viewer, 90 from left to right.
|
|
59
|
+
* @param {number} count How many waves, at least 2.
|
|
60
|
+
* @param {number} geometry How many of the longest shape the surface (the rest only light it).
|
|
61
|
+
* @returns {WaveSet} The waves, longest first.
|
|
62
|
+
*/
|
|
63
|
+
export function waveSet(sea, wind, count, geometry) {
|
|
64
|
+
const state = Math.min(2, Math.max(0, sea));
|
|
65
|
+
const n = Math.max(2, Math.round(count));
|
|
66
|
+
const longest = LONGEST * (0.55 + 0.45 * state);
|
|
67
|
+
const ratio = (SHORTEST / longest) ** (1 / (n - 1));
|
|
68
|
+
// Towards the viewer is -z (the camera looks down +z); left to right is +x.
|
|
69
|
+
const heading = ((180 - wind) * Math.PI) / 180;
|
|
70
|
+
const shape = new Float32Array(n * 4);
|
|
71
|
+
const motion = new Float32Array(n * 2);
|
|
72
|
+
const speed = new Float32Array(n);
|
|
73
|
+
const start = new Float32Array(n);
|
|
74
|
+
let crest = 0;
|
|
75
|
+
let slope2 = 0;
|
|
76
|
+
for (let i = 0; i < n; i++) {
|
|
77
|
+
const t = i / (n - 1);
|
|
78
|
+
const length = longest * ratio ** (i + 0.35 * jitter(i, 1));
|
|
79
|
+
const k = TAU / length;
|
|
80
|
+
// The long waves follow the wind closely; the short spread wide. The
|
|
81
|
+
// second is a swell from another quarter, so the crests cross.
|
|
82
|
+
const spread = 0.3 + 1.1 * Math.sqrt(t);
|
|
83
|
+
const angle = heading + (i === 1 ? 0.9 : jitter(i, 2) * spread);
|
|
84
|
+
// Steepness: the long waves build with the sea state, ripples less so.
|
|
85
|
+
const build = i < geometry ? 0.08 + 0.92 * state : 0.35 + 0.65 * Math.min(1, state) + 0.2 * Math.max(0, state - 1);
|
|
86
|
+
const steep = (0.034 + 0.036 * Math.sin(Math.PI * t ** 0.8) - 0.01 * t + 0.01 * jitter(i, 3)) * build;
|
|
87
|
+
const height = steep / k;
|
|
88
|
+
shape.set([Math.sin(angle), Math.cos(angle), k, height], i * 4);
|
|
89
|
+
// Sharper crests on the bigger waves of a rougher sea.
|
|
90
|
+
motion[i * 2 + 1] = (0.8 + 1.2 * Math.sin(Math.PI * Math.min(1, t * 1.4))) * Math.min(1.4, 0.5 + 0.6 * state);
|
|
91
|
+
speed[i] = Math.sqrt(G * k);
|
|
92
|
+
start[i] = (jitter(i, 4) + 1) * Math.PI;
|
|
93
|
+
if (i < geometry) {
|
|
94
|
+
crest += height;
|
|
95
|
+
// Mean square slope: (a·k)² · 0.4·S for this profile.
|
|
96
|
+
slope2 += steep * steep * 0.4 * motion[i * 2 + 1];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** @type {[number, number]} */
|
|
100
|
+
const toward = [Math.sin(heading), Math.cos(heading)];
|
|
101
|
+
const set = { count: n, shape, motion, speed, start, crest, slope: 2 * Math.sqrt(slope2) + 0.02, wind: toward };
|
|
102
|
+
wavePhases(set, 0);
|
|
103
|
+
return set;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Moves every wave on to a time, writing its phase into `set.motion`.
|
|
108
|
+
*
|
|
109
|
+
* @param {WaveSet} set The waves.
|
|
110
|
+
* @param {number} time The sea's clock, seconds.
|
|
111
|
+
* @returns {Float32Array} `set.motion`, updated.
|
|
112
|
+
*/
|
|
113
|
+
export function wavePhases(set, time) {
|
|
114
|
+
for (let i = 0; i < set.count; i++) {
|
|
115
|
+
const phase = (set.start[i] - set.speed[i] * time) % TAU;
|
|
116
|
+
set.motion[i * 2] = phase < 0 ? phase + TAU : phase;
|
|
117
|
+
}
|
|
118
|
+
return set.motion;
|
|
119
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { PaletteName } from './palettes.js';
|
|
2
|
+
|
|
3
|
+
export interface OceanConfig {
|
|
4
|
+
/** The time of day: the sun, the sky's colours and the water's (`night` has a moon and stars). Default `sunset`. */
|
|
5
|
+
time?: 'dawn' | 'noon' | 'sunset' | 'night';
|
|
6
|
+
/** The sea state: 0 glassy, 1 a fresh breeze, 2 rough with whitecaps. Default 1. */
|
|
7
|
+
waves?: number;
|
|
8
|
+
/** Where the waves run, degrees 0–360: 0 straight towards the viewer, 90 from left to right. Default 30. */
|
|
9
|
+
wind?: number;
|
|
10
|
+
/** How fast the sea moves; 0 holds it still. Default 1. */
|
|
11
|
+
speed?: number;
|
|
12
|
+
/** How high the camera is above the water, metres, 1–20 (raised as far as the waves need). Default 4. */
|
|
13
|
+
height?: number;
|
|
14
|
+
/** Where the horizon sits, 0–1 up the frame. Default 0.3. */
|
|
15
|
+
horizon?: number;
|
|
16
|
+
/** Soft high cloud in the sky and its reflection. Default true. */
|
|
17
|
+
clouds?: boolean;
|
|
18
|
+
/** Where the sun (or moon) sits instead of the time's place: 0–1 across and up the frame. Default none. */
|
|
19
|
+
sun?: { x?: number; y?: number } | null;
|
|
20
|
+
/** Tints, kept to each part's lightness: the sky, the water and the light. */
|
|
21
|
+
colors?: string[];
|
|
22
|
+
/** A shared palette by name (`PALETTES`, any case) to tint with, when there are no `colors`. */
|
|
23
|
+
palette?: PaletteName | (string & {});
|
|
24
|
+
/** Whether the camera drifts with the pointer. Default true. */
|
|
25
|
+
interactive?: boolean;
|
|
26
|
+
/** An area dimmed behind copy: centre (0–1 from the top left), radius (a share of the height), depth (0–1). Default none; `{}` for the middle. */
|
|
27
|
+
quiet?: { x?: number; y?: number; radius?: number; depth?: number } | null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Starts the ocean in `el`'s canvas. Returns a function that stops it. */
|
|
31
|
+
export function ocean(el: HTMLElement, config: OceanConfig): () => void;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/ocean
|
|
3
|
+
*
|
|
4
|
+
* Open sea to the horizon, as a hero background: the camera a few metres
|
|
5
|
+
* above the water looking out, a sky with the sun (or the moon) low over
|
|
6
|
+
* it, and the light doing what it does on real water. Wind-driven waves
|
|
7
|
+
* at every scale from a long swell to ripples, sunlight glowing through
|
|
8
|
+
* thin crests, a glittering path under the sun, whitecaps on a rough sea,
|
|
9
|
+
* high cloud in the sky and in its reflection, and haze into a soft,
|
|
10
|
+
* true horizon. `time` sets the hour: dawn, noon, sunset or a moonlit
|
|
11
|
+
* night.
|
|
12
|
+
*
|
|
13
|
+
* One fragment shader (./ocean/shader.js) over waves made once on the CPU
|
|
14
|
+
* (./ocean/waves.js); each frame only moves their phases on, eases the
|
|
15
|
+
* camera and sets a few uniforms. The pointer moves the camera a few
|
|
16
|
+
* metres, so the near water slides past the far (parallax). It draws at
|
|
17
|
+
* most one and a half pixels per CSS pixel; phones get fewer waves, march
|
|
18
|
+
* steps and pixels; the stage lowers the resolution while frames run slow. With prefers-reduced-motion, one still frame.
|
|
19
|
+
*
|
|
20
|
+
* Opaque: the effect is the whole background of what it fills. Without
|
|
21
|
+
* WebGL it removes its canvas and the element's background (the scene as
|
|
22
|
+
* a gradient, `oceanBackdrop`) shows.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { createStage } from './stage.js';
|
|
26
|
+
import { parseColor } from './color.js';
|
|
27
|
+
import { canHover, isMobileGpu, pixelRatio } from './device.js';
|
|
28
|
+
import { quietUniform } from './glsl.js';
|
|
29
|
+
import { watchColors } from './mount.js';
|
|
30
|
+
import { pointerIn } from './pointer.js';
|
|
31
|
+
import { oceanLook } from './ocean/presets.js';
|
|
32
|
+
import { oceanShader } from './ocean/shader.js';
|
|
33
|
+
import { oceanView, sunDirection } from './ocean/view.js';
|
|
34
|
+
import { wavePhases, waveSet } from './ocean/waves.js';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {object} OceanConfig
|
|
38
|
+
* @property {'dawn' | 'noon' | 'sunset' | 'night'} [time='sunset'] The time of day: the sun, the sky's colours and the water's (`night` has a moon and stars).
|
|
39
|
+
* @property {number} [waves=1] The sea state: 0 glassy, 1 a fresh breeze, 2 rough with whitecaps.
|
|
40
|
+
* @property {number} [wind=30] Where the waves run, degrees 0–360: 0 straight towards the viewer, 90 from left to right.
|
|
41
|
+
* @property {number} [speed=1] How fast the sea moves; 0 holds it still.
|
|
42
|
+
* @property {number} [height=4] How high the camera is above the water, metres, 1–20 (raised as far as the waves need).
|
|
43
|
+
* @property {number} [horizon=0.3] Where the horizon sits, 0–1 up the frame.
|
|
44
|
+
* @property {boolean} [clouds=true] Soft high cloud in the sky and its reflection.
|
|
45
|
+
* @property {{ x?: number, y?: number } | null} [sun=null] Where the sun (or moon) sits instead of the time's place: 0–1 across and up the frame.
|
|
46
|
+
* @property {string[]} [colors] Tints, kept to each part's lightness: the sky, the water and the light.
|
|
47
|
+
* @property {string} [palette] A shared palette by name (PALETTES; any case) to tint with, when there are no `colors`.
|
|
48
|
+
* @property {boolean} [interactive=true] Whether the camera drifts with the pointer.
|
|
49
|
+
* @property {{ x?: number, y?: number, radius?: number, depth?: number } | null} [quiet=null]
|
|
50
|
+
* An area dimmed behind copy: centre (0–1 from the top left), radius (a
|
|
51
|
+
* share of the height) and depth (0–1). The middle with `{}`.
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
/** The full budget, and a phone's: waves, those that shape the surface, march and false-position steps, and the most pixels per CSS pixel drawn. */
|
|
55
|
+
const DESKTOP = { waves: 28, geometry: 8, steps: 14, refine: 6, ratio: 1.5 };
|
|
56
|
+
const MOBILE = { waves: 18, geometry: 6, steps: 10, refine: 3, ratio: 1.05 };
|
|
57
|
+
/** How far the camera moves with the pointer at the frame's edge: metres sideways and up. */
|
|
58
|
+
const SWAY = 6;
|
|
59
|
+
const RISE = 0.7;
|
|
60
|
+
/** How quickly the camera follows the pointer, per second. */
|
|
61
|
+
const EASE = 1.4;
|
|
62
|
+
/** Where the sea's clock starts, seconds: the waves already built up (the still frame too). */
|
|
63
|
+
const START = 40;
|
|
64
|
+
/** How fast the clouds drift with the wind, sky units a second. */
|
|
65
|
+
const DRIFT = 0.004;
|
|
66
|
+
/** How much high cloud there is with `clouds`, 0–1. */
|
|
67
|
+
const COVER = 0.8;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Starts the ocean on an element (its first canvas is drawn into).
|
|
71
|
+
*
|
|
72
|
+
* @param {HTMLElement} el The element.
|
|
73
|
+
* @param {OceanConfig} config The settings.
|
|
74
|
+
* @returns {() => void} Stops it.
|
|
75
|
+
*/
|
|
76
|
+
export function ocean(el, config) {
|
|
77
|
+
const quality = isMobileGpu() ? MOBILE : DESKTOP;
|
|
78
|
+
const sea = Math.min(2, Math.max(0, config.waves ?? 1));
|
|
79
|
+
const waves = waveSet(sea, config.wind ?? 30, quality.waves, quality.geometry);
|
|
80
|
+
const horizon = Math.min(0.95, Math.max(0.05, config.horizon ?? 0.3));
|
|
81
|
+
const height = Math.max(config.height ?? 4, waves.crest * 2 + 0.6);
|
|
82
|
+
const speed = config.speed ?? 1;
|
|
83
|
+
const interactive = config.interactive !== false;
|
|
84
|
+
let look = oceanLook(config);
|
|
85
|
+
let aspect = 1;
|
|
86
|
+
let time = START;
|
|
87
|
+
/** Where the pointer has moved the camera, -1–1 each way. */
|
|
88
|
+
const pan = { x: 0, y: 0 };
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Sets the uniforms that only change with the colours or the frame's shape.
|
|
92
|
+
*
|
|
93
|
+
* @param {import('./stage.js').Stage} stage The stage, its program bound.
|
|
94
|
+
*/
|
|
95
|
+
const setLook = ({ gl, uniform: u }) => {
|
|
96
|
+
for (const [name, key] of /** @type {const} */ ([
|
|
97
|
+
['uZenith', 'zenith'],
|
|
98
|
+
['uHorizon', 'horizon'],
|
|
99
|
+
['uGlow', 'glow'],
|
|
100
|
+
['uLight', 'light'],
|
|
101
|
+
['uDeep', 'deep'],
|
|
102
|
+
['uScatter', 'scatter'],
|
|
103
|
+
['uCloud', 'cloud'],
|
|
104
|
+
])) {
|
|
105
|
+
gl.uniform3fv(u(name), parseColor(look[key]));
|
|
106
|
+
}
|
|
107
|
+
gl.uniform1f(u('uPower'), look.power);
|
|
108
|
+
gl.uniform1f(u('uSize'), look.size);
|
|
109
|
+
gl.uniform1f(u('uHaze'), look.haze);
|
|
110
|
+
gl.uniform1f(u('uExposure'), look.exposure);
|
|
111
|
+
gl.uniform1f(u('uStars'), look.stars);
|
|
112
|
+
gl.uniform3fv(u('uSun'), sunDirection(oceanView({ height, horizon, aspect }), horizon, look, config.sun));
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Eases the camera towards where the pointer is taking it, and back to the middle when it leaves.
|
|
117
|
+
*
|
|
118
|
+
* @param {number} dt Seconds since the last frame.
|
|
119
|
+
*/
|
|
120
|
+
const follow = (dt) => {
|
|
121
|
+
const p = pointerIn(el);
|
|
122
|
+
const k = 1 - Math.exp(-dt * EASE);
|
|
123
|
+
pan.x += ((p.inside ? p.x * 2 - 1 : 0) - pan.x) * k;
|
|
124
|
+
pan.y += ((p.inside ? p.y * 2 - 1 : 0) - pan.y) * k;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const { stage, stop } = createStage(el, {
|
|
128
|
+
fragment: oceanShader(quality),
|
|
129
|
+
alpha: false,
|
|
130
|
+
scale: Math.min(1, quality.ratio / pixelRatio()),
|
|
131
|
+
setup(stage) {
|
|
132
|
+
const { gl, uniform: u } = stage;
|
|
133
|
+
gl.uniform4fv(u('uShape'), waves.shape);
|
|
134
|
+
gl.uniform1f(u('uCrest'), waves.crest);
|
|
135
|
+
gl.uniform1f(u('uSlope'), waves.slope);
|
|
136
|
+
gl.uniform1f(u('uClouds'), config.clouds === false ? 0 : COVER);
|
|
137
|
+
gl.uniform1f(u('uFoam'), Math.min(1, Math.max(0, (sea - 0.8) / 1.2)));
|
|
138
|
+
gl.uniform2fv(u('uWind'), waves.wind);
|
|
139
|
+
},
|
|
140
|
+
resize(stage) {
|
|
141
|
+
aspect = stage.canvas.width / stage.canvas.height;
|
|
142
|
+
setLook(stage);
|
|
143
|
+
stage.gl.uniform4f(stage.uniform('uQuiet'), ...quietUniform(config.quiet, aspect));
|
|
144
|
+
},
|
|
145
|
+
uniforms({ gl, uniform: u, still }, _now, dt) {
|
|
146
|
+
if (!still) {
|
|
147
|
+
time += dt * speed;
|
|
148
|
+
if (interactive && canHover()) follow(dt);
|
|
149
|
+
}
|
|
150
|
+
const view = oceanView({ height, horizon, aspect, x: pan.x * SWAY, lift: pan.y * RISE });
|
|
151
|
+
gl.uniform3fv(u('uEye'), view.eye);
|
|
152
|
+
gl.uniform3fv(u('uRight'), view.right);
|
|
153
|
+
gl.uniform3fv(u('uUp'), view.up);
|
|
154
|
+
gl.uniform3fv(u('uFwd'), view.forward);
|
|
155
|
+
gl.uniform2f(u('uLens'), view.focal, view.shift);
|
|
156
|
+
gl.uniform2fv(u('uMotion'), wavePhases(waves, time));
|
|
157
|
+
gl.uniform1f(u('uTime'), time);
|
|
158
|
+
gl.uniform2f(u('uDrift'), waves.wind[0] * time * DRIFT, waves.wind[1] * time * DRIFT);
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
if (!stage) return stop;
|
|
162
|
+
|
|
163
|
+
const unwatch = watchColors(el, (next) => {
|
|
164
|
+
look = oceanLook({ ...config, colors: next.colors });
|
|
165
|
+
stage.gl.useProgram(stage.program);
|
|
166
|
+
setLook(stage);
|
|
167
|
+
if (stage.still) stage.redraw();
|
|
168
|
+
});
|
|
169
|
+
return () => {
|
|
170
|
+
stop();
|
|
171
|
+
unwatch();
|
|
172
|
+
};
|
|
173
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** A palette's name. */
|
|
2
|
+
export type PaletteName =
|
|
3
|
+
| 'Lumetri'
|
|
4
|
+
| 'Forest'
|
|
5
|
+
| 'Cadmium'
|
|
6
|
+
| 'Peacock'
|
|
7
|
+
| 'Vermillion'
|
|
8
|
+
| 'Barbie'
|
|
9
|
+
| 'Uranium'
|
|
10
|
+
| 'Azure'
|
|
11
|
+
| 'Ruby'
|
|
12
|
+
| 'Ultramarine'
|
|
13
|
+
| 'Saffron'
|
|
14
|
+
| 'Crimson'
|
|
15
|
+
| 'Ember'
|
|
16
|
+
| 'Lagoon'
|
|
17
|
+
| 'Citrus'
|
|
18
|
+
| 'Glacier'
|
|
19
|
+
| 'Rosewater'
|
|
20
|
+
| 'Mono';
|
|
21
|
+
|
|
22
|
+
/** A palette: three colours and a highlight. */
|
|
23
|
+
export interface Palette {
|
|
24
|
+
/** Three colours, as CSS hex. */
|
|
25
|
+
colors: [string, string, string];
|
|
26
|
+
/** A highlight colour. */
|
|
27
|
+
glint: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** The palettes by name (Lumetri, Forest, Cadmium, Peacock, Vermillion, Barbie, Uranium, Azure, Ruby, Ultramarine, Saffron, Crimson, Ember, Lagoon, Citrus, Glacier, Rosewater, Mono), in the order a switcher should cycle them. */
|
|
31
|
+
export const PALETTES: Readonly<Record<PaletteName, Palette>>;
|
|
32
|
+
|
|
33
|
+
/** A palette by name, in any case; undefined when there is none by that name. */
|
|
34
|
+
export function findPalette(name: string | undefined): Palette | undefined;
|
|
35
|
+
|
|
36
|
+
/** An effect's colours: its own `colors`, else its `palette` shaped to what it takes, else `fallback`. */
|
|
37
|
+
export function pickColors(config: { colors?: string[]; palette?: string }, fallback: string[], shape?: (palette: Palette) => string[]): string[];
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/palettes
|
|
3
|
+
*
|
|
4
|
+
* Named colour sets every colour-taking effect accepts as `palette`:
|
|
5
|
+
* Trirat's twelve from the LumiThemes ink, then a few more. Each is three
|
|
6
|
+
* colours and a glint (a highlight some effects use). An effect's own
|
|
7
|
+
* `colors` always win; a `palette` fills in when there are none, shaped
|
|
8
|
+
* to what that effect takes (three colours, a light and a glint, an ink
|
|
9
|
+
* and a paper…).
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @typedef {object} Palette
|
|
14
|
+
* @property {[string, string, string]} colors Three colours, as CSS hex.
|
|
15
|
+
* @property {string} glint A highlight colour.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The palettes by name, in the order a switcher should cycle them.
|
|
20
|
+
*
|
|
21
|
+
* @type {Readonly<Record<string, Palette>>}
|
|
22
|
+
*/
|
|
23
|
+
export const PALETTES = Object.freeze({
|
|
24
|
+
// Trirat's twelve, from the LumiThemes ink.
|
|
25
|
+
Lumetri: { colors: ['#2532ef', '#0957ff', '#f69d03'], glint: '#FFFDCF' },
|
|
26
|
+
Forest: { colors: ['#2c824a', '#4e3a3a', '#31625a'], glint: '#5d8d61' },
|
|
27
|
+
Cadmium: { colors: ['#f15025', '#c9783a', '#303030'], glint: '#FF6B35' },
|
|
28
|
+
Peacock: { colors: ['#18d2e3', '#092eff', '#03f6b9'], glint: '#5f7eee' },
|
|
29
|
+
Vermillion: { colors: ['#e31818', '#931168', '#bd5d0e'], glint: '#ff0000' },
|
|
30
|
+
Barbie: { colors: ['#ff0bce', '#1bfefe', '#2d026e'], glint: '#ff00ff' },
|
|
31
|
+
Uranium: { colors: ['#aaff0b', '#4d7a60', '#1b1b1b'], glint: '#04ff00' },
|
|
32
|
+
Azure: { colors: ['#066aff', '#0095ff', '#0062ff'], glint: '#0080ff' },
|
|
33
|
+
Ruby: { colors: ['#ff0000', '#870000', '#3b475e'], glint: '#ff0000' },
|
|
34
|
+
Ultramarine: { colors: ['#0044ff', '#561616', '#005fc4'], glint: '#0037ff' },
|
|
35
|
+
Saffron: { colors: ['#ffb700', '#521212', '#ffcb53'], glint: '#ff8c00' },
|
|
36
|
+
Crimson: { colors: ['#ff0000', '#173a71', '#4f0000'], glint: '#ff0000' },
|
|
37
|
+
// And a few more.
|
|
38
|
+
Ember: { colors: ['#ff5a1f', '#ffb347', '#7a1c0c'], glint: '#ffe2b8' },
|
|
39
|
+
Lagoon: { colors: ['#00c2a8', '#0a7ea4', '#f2d49b'], glint: '#d6fff6' },
|
|
40
|
+
Citrus: { colors: ['#c6f432', '#ffd400', '#ff7a00'], glint: '#fffbd1' },
|
|
41
|
+
Glacier: { colors: ['#bfe6ff', '#4aa8ff', '#1b3a5c'], glint: '#ffffff' },
|
|
42
|
+
Rosewater: { colors: ['#ff7aa2', '#ffc2a8', '#3d1d2b'], glint: '#fff0f4' },
|
|
43
|
+
Mono: { colors: ['#f4f4f5', '#a1a1aa', '#3f3f46'], glint: '#ffffff' },
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A palette by name, in any case.
|
|
48
|
+
*
|
|
49
|
+
* @param {string | undefined} name The name.
|
|
50
|
+
* @returns {Palette | undefined} The palette, or undefined when there is none by that name.
|
|
51
|
+
*/
|
|
52
|
+
export function findPalette(name) {
|
|
53
|
+
if (!name) return undefined;
|
|
54
|
+
const key = Object.keys(PALETTES).find((k) => k.toLowerCase() === String(name).toLowerCase());
|
|
55
|
+
return key ? PALETTES[key] : undefined;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The colours an effect draws with: its own `colors` if it has them,
|
|
60
|
+
* else its `palette` shaped to what it takes, else its defaults. An
|
|
61
|
+
* unknown palette name is warned about and the defaults used.
|
|
62
|
+
*
|
|
63
|
+
* @param {{ colors?: string[], palette?: string }} config The effect's settings.
|
|
64
|
+
* @param {string[]} fallback Its default colours.
|
|
65
|
+
* @param {(palette: Palette) => string[]} [shape] Turns a palette into the colours it takes (default the palette's three).
|
|
66
|
+
* @returns {string[]} The colours.
|
|
67
|
+
*/
|
|
68
|
+
export function pickColors(config, fallback, shape = (palette) => [...palette.colors]) {
|
|
69
|
+
if (config.colors?.length) return config.colors;
|
|
70
|
+
if (!config.palette) return fallback;
|
|
71
|
+
const palette = findPalette(config.palette);
|
|
72
|
+
if (palette) return shape(palette);
|
|
73
|
+
console.warn('[effects-astro]', `No palette "${config.palette}"`);
|
|
74
|
+
return fallback;
|
|
75
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { PaperConfig } from './paper.js';
|
|
2
|
+
import type { PaletteName } from './palettes.js';
|
|
3
|
+
import type { PaperLookName } from './paper-looks.js';
|
|
4
|
+
|
|
5
|
+
/** What every Paper look takes besides its own props (src/runtime/paper-looks.js). */
|
|
6
|
+
export interface PaperLookOptions {
|
|
7
|
+
/** A shared palette by name (`PALETTES`, any case), when there are no `colors`. */
|
|
8
|
+
palette?: PaletteName | (string & {});
|
|
9
|
+
/** Dims it towards its `background` behind the copy: the centre (`x` across, `y` down, 0–1), the `radius` (of the height) and the `depth`, 0–1. Default none. */
|
|
10
|
+
quiet?: { x?: number; y?: number; radius?: number; depth?: number };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** A Paper look and its props: the shared ones and its own, each over its preset's setting. */
|
|
14
|
+
export interface PaperLookConfig extends PaperLookOptions {
|
|
15
|
+
/** The look. */
|
|
16
|
+
look: PaperLookName;
|
|
17
|
+
/** One of its shader's presets, by name, to start from. Default the look's. */
|
|
18
|
+
preset?: string;
|
|
19
|
+
/** Its colours. */
|
|
20
|
+
colors?: string[];
|
|
21
|
+
/** The colour behind it. */
|
|
22
|
+
background?: string;
|
|
23
|
+
/** How fast it moves (0 holds). */
|
|
24
|
+
speed?: number;
|
|
25
|
+
/** How large it is drawn. */
|
|
26
|
+
zoom?: number;
|
|
27
|
+
/** Its turn, degrees. */
|
|
28
|
+
rotation?: number;
|
|
29
|
+
/** Where its centre sits, `[x, y]`, -1–1. */
|
|
30
|
+
offset?: [number, number];
|
|
31
|
+
/** The look's own props. */
|
|
32
|
+
[prop: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A look's props as a Paper shader's config: its shader, preset and settings. Throws for an unknown look. */
|
|
36
|
+
export function paperLookSettings(config: PaperLookConfig): PaperConfig;
|
|
37
|
+
|
|
38
|
+
/** The CSS mask that dims a canvas behind copy, sized in the element's height. */
|
|
39
|
+
export function quietMask(quiet: NonNullable<PaperLookOptions['quiet']>): string;
|
|
40
|
+
|
|
41
|
+
/** Starts a Paper look in `el`'s canvas. Returns a function that stops it. */
|
|
42
|
+
export function paperLook(el: HTMLElement, config: PaperLookConfig): () => void;
|