@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,355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @arraypress/effects-astro/ascii-rain
|
|
3
|
+
*
|
|
4
|
+
* A data readout drawn in text characters, in one of two patterns:
|
|
5
|
+
*
|
|
6
|
+
* - `cloud` (the default): streams of data, short dashes and blocks of
|
|
7
|
+
* glyphs gathered into a loose cloud with dark space around it, each
|
|
8
|
+
* row sliding sideways at its own pace, glyphs flickering as they
|
|
9
|
+
* pass. `speed={0}` holds one frame, and then no loop runs at all.
|
|
10
|
+
* - `waves`: data rain on a rippling surface. Streaks of
|
|
11
|
+
* light run along lanes on a surface seen in perspective (each lane at its
|
|
12
|
+
* own pace, bright at the head and fading behind), the surface rolls in
|
|
13
|
+
* slow waves that bend the lanes and are lit along their slopes, and the
|
|
14
|
+
* whole is rasterised into character cells, a brighter glyph for a
|
|
15
|
+
* brighter cell. Each streak fades out at both ends through hollow bars to
|
|
16
|
+
* faint ones. Blue bleeds out to the left of every glyph and red to the
|
|
17
|
+
* right, so a bar shades blue, white, red across, like a cheap lens.
|
|
18
|
+
*
|
|
19
|
+
* Each cell's ray is marched onto the wave surface (16 steps, refined), so
|
|
20
|
+
* the waves occlude and foreshorten as a real surface would.
|
|
21
|
+
*
|
|
22
|
+
* In `waves`, the pointer sends ripples through the surface and a click
|
|
23
|
+
* drops a ring that runs outward. A quiet area keeps either off the copy.
|
|
24
|
+
*
|
|
25
|
+
* Clear where there is no rain, so it lays over any background. Without
|
|
26
|
+
* WebGL nothing is drawn; with prefers-reduced-motion it is one still frame.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { createStage } from './stage.js';
|
|
30
|
+
import { GLSL_NOISE, GLSL_PALETTE, GLSL_QUIET, paletteUniform, quietUniform } from './glsl.js';
|
|
31
|
+
import { GLSL_GLYPHS, createGlyphs } from './glyphs.js';
|
|
32
|
+
import { canHover } from './device.js';
|
|
33
|
+
import { pointerIn, pressAt } from './pointer.js';
|
|
34
|
+
import { watchColors } from './mount.js';
|
|
35
|
+
import { pickColors } from './palettes.js';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {object} AsciiRainConfig
|
|
39
|
+
* @property {string[]} [colors] Three CSS hex colours the glyphs take, the brightest nearly white. Default a cool cyan and green.
|
|
40
|
+
* @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`.
|
|
41
|
+
* @property {number} [glitch=1] How often rows jump sideways for a moment, their colours splitting wider; 0 for never.
|
|
42
|
+
* @property {string} [glyphs='data'] A character set (`data`: hollow and solid bars; `bars`, `ascii`,
|
|
43
|
+
* `blocks`, `binary`, `boxes`) or the characters themselves, darkest first.
|
|
44
|
+
* @property {number} [cell=14] A character cell's height in CSS px.
|
|
45
|
+
* @property {number} [aspect] A cell's width over its height (default 1 for `data`, 0.6 for type).
|
|
46
|
+
* @property {number} [angle=0] Which way the streaks run, in degrees: 0 rightwards, 90 down, 180 left, 270 up.
|
|
47
|
+
* @property {number} [lines=40] Streak lanes across the surface.
|
|
48
|
+
* @property {number} [trail=0.3] A streak's length, as a share of the gap between them (0–1).
|
|
49
|
+
* @property {number} [density=0.7] How many lanes have a streak at any time, 0–1.
|
|
50
|
+
* @property {number} [width=0.9] A lane's streak width, as a share of the lane (0–1).
|
|
51
|
+
* @property {'cloud' | 'waves'} [pattern='cloud'] A still cloud of data, or streaks running on a rippling surface.
|
|
52
|
+
* @property {number} [speed=1] How fast it moves: the rows stream, or the streaks run; 0 for one still frame.
|
|
53
|
+
* @property {number} [variance=0.6] How much each lane's speed differs (0 all alike, 1 very different).
|
|
54
|
+
* @property {number} [ripple=1] How tall the surface's waves are; 0 for flat.
|
|
55
|
+
* @property {number} [waves=1] How close together the waves are.
|
|
56
|
+
* @property {number} [tilt=58] How far the surface leans back, in degrees (0 face-on, 80 nearly edge-on).
|
|
57
|
+
* @property {number} [zoom=1] How much of the surface fills the frame (larger is closer).
|
|
58
|
+
* @property {number} [lighting=1] How strongly the waves are lit and shaded; 0 for flat.
|
|
59
|
+
* @property {number} [aberration=3] How far blue bleeds left and red right of each glyph, in CSS px; 0 for none.
|
|
60
|
+
* @property {boolean} [interactive=true] With `waves`, whether the pointer ripples the surface and a click drops a ring.
|
|
61
|
+
* @property {{ x?: number, y?: number, radius?: number, depth?: number } | null} [quiet=null]
|
|
62
|
+
* An area kept clear: centre (0–1 from the top left), radius (share of the height), depth (0–1).
|
|
63
|
+
* @property {string} [font] The font the glyphs are drawn in (a monospace stack by default).
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
const FRAG = `
|
|
67
|
+
precision highp float;
|
|
68
|
+
uniform vec2 uRes;
|
|
69
|
+
uniform vec2 uCell;
|
|
70
|
+
uniform float uTime;
|
|
71
|
+
uniform vec2 uPtr;
|
|
72
|
+
uniform float uActive;
|
|
73
|
+
uniform vec3 uClick;
|
|
74
|
+
uniform vec2 uDir;
|
|
75
|
+
uniform float uLines;
|
|
76
|
+
uniform float uTrail;
|
|
77
|
+
uniform float uDensity;
|
|
78
|
+
uniform float uWidth;
|
|
79
|
+
uniform float uVariance;
|
|
80
|
+
uniform float uRipple;
|
|
81
|
+
uniform float uWaves;
|
|
82
|
+
uniform float uTilt;
|
|
83
|
+
uniform float uZoom;
|
|
84
|
+
uniform float uLighting;
|
|
85
|
+
uniform float uAberration;
|
|
86
|
+
uniform float uPattern;
|
|
87
|
+
uniform float uGlitch;
|
|
88
|
+
${GLSL_NOISE}
|
|
89
|
+
${GLSL_PALETTE}
|
|
90
|
+
${GLSL_QUIET}
|
|
91
|
+
${GLSL_GLYPHS}
|
|
92
|
+
|
|
93
|
+
// The camera: above the surface, leaning back by uTilt, looking at its middle.
|
|
94
|
+
vec3 camPos() { return vec3(0.0, 2.6 * sin(uTilt), -2.6 * cos(uTilt)) / uZoom; }
|
|
95
|
+
vec3 camDir(vec2 s) {
|
|
96
|
+
vec3 forward = normalize(-camPos());
|
|
97
|
+
vec3 right = normalize(cross(vec3(0.0, 1.0, 0.0), forward));
|
|
98
|
+
vec3 up = cross(forward, right);
|
|
99
|
+
return normalize(forward * 1.6 + right * s.x + up * s.y);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Where the pointer and the last click are on the surface (where their rays meet y = 0).
|
|
103
|
+
vec2 onSurface(vec2 px) {
|
|
104
|
+
vec2 s = (px - 0.5 * uRes) / uRes.y;
|
|
105
|
+
vec3 o = camPos();
|
|
106
|
+
vec3 d = camDir(s);
|
|
107
|
+
return (o + d * (-o.y / min(d.y, -1e-3))).xz;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// The surface's height: two rolling swells, the pointer's ripples and the click's ring.
|
|
111
|
+
float height(vec2 q, vec2 ptr, vec2 click) {
|
|
112
|
+
float f = uWaves * 1.6;
|
|
113
|
+
float h = sin(q.x * f + uTime * 0.6) * cos(q.y * f * 0.8 - uTime * 0.45) * 0.6
|
|
114
|
+
+ sin((q.x + q.y) * f * 1.7 + uTime * 0.9) * 0.22;
|
|
115
|
+
float d = length(q - ptr);
|
|
116
|
+
h += uActive * sin(d * 10.0 - uTime * 6.0) * exp(-d * 2.2) * 0.8;
|
|
117
|
+
float age = uTime - uClick.z;
|
|
118
|
+
float ring = length(q - click) - age * 1.3;
|
|
119
|
+
h += step(0.0, age) * exp(-ring * ring * 20.0) * exp(-age * 0.8) * 1.4;
|
|
120
|
+
return h * 0.18 * uRipple;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// The streaks on the surface: lanes across uDir, each with its own speed
|
|
124
|
+
// and phase; bright at the head, fading along the trail.
|
|
125
|
+
float streaks(vec2 q) {
|
|
126
|
+
float u = dot(q, vec2(-uDir.y, uDir.x));
|
|
127
|
+
float v = dot(q, uDir);
|
|
128
|
+
float lane = floor(u * uLines);
|
|
129
|
+
float local = fract(u * uLines);
|
|
130
|
+
float r = hash(vec2(lane, 7.1));
|
|
131
|
+
float pace = 1.0 + (r - 0.5) * uVariance * 2.0;
|
|
132
|
+
float flow = v * 0.6 - fract(uTime * 0.25 * pace) - hash(vec2(lane, 2.3));
|
|
133
|
+
float along = fract(flow);
|
|
134
|
+
// Each pass of a streak is there or not, so whole lanes sit empty for a while.
|
|
135
|
+
float on = step(1.0 - uDensity, hash(vec2(lane, floor(flow))));
|
|
136
|
+
float x = along / max(uTrail, 1e-3);
|
|
137
|
+
// A run of full brightness with soft ends, so it fades out through
|
|
138
|
+
// outlines both ways; some runs are dimmer and never reach solid.
|
|
139
|
+
float body = smoothstep(0.0, 0.22, x) * (1.0 - smoothstep(0.72, 1.0, x));
|
|
140
|
+
float strength = 0.6 + 1.0 * hash(vec2(lane, floor(flow) + 3.7));
|
|
141
|
+
float wide = 1.0 - smoothstep(uWidth * 0.5 - 0.06, uWidth * 0.5, abs(local - 0.5));
|
|
142
|
+
return step(x, 1.0) * on * wide * body * strength;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// How bright the rain is where a pixel's ray meets the surface: marched
|
|
146
|
+
// through the band the waves can reach, then refined.
|
|
147
|
+
float rain(vec2 px) {
|
|
148
|
+
vec2 s = (px - 0.5 * uRes) / uRes.y;
|
|
149
|
+
vec3 o = camPos();
|
|
150
|
+
vec3 d = camDir(s);
|
|
151
|
+
if (d.y > -0.02) return 0.0;
|
|
152
|
+
vec2 ptr = onSurface(uPtr);
|
|
153
|
+
vec2 click = onSurface(uClick.xy);
|
|
154
|
+
float top = 0.25 * uRipple + 0.05;
|
|
155
|
+
float t0 = (top - o.y) / d.y;
|
|
156
|
+
float t1 = (-top - o.y) / d.y;
|
|
157
|
+
float t = t0;
|
|
158
|
+
float dt = (t1 - t0) / 16.0;
|
|
159
|
+
float lo = t0;
|
|
160
|
+
for (int i = 0; i < 16; i++) {
|
|
161
|
+
vec3 p = o + d * t;
|
|
162
|
+
if (p.y < height(p.xz, ptr, click)) break;
|
|
163
|
+
lo = t;
|
|
164
|
+
t += dt;
|
|
165
|
+
}
|
|
166
|
+
float hi = t;
|
|
167
|
+
for (int i = 0; i < 5; i++) {
|
|
168
|
+
float mid = (lo + hi) * 0.5;
|
|
169
|
+
vec3 p = o + d * mid;
|
|
170
|
+
if (p.y < height(p.xz, ptr, click)) hi = mid; else lo = mid;
|
|
171
|
+
}
|
|
172
|
+
vec3 hit = o + d * hi;
|
|
173
|
+
// Lit by the slope: light from the upper left, a sheen on the crests.
|
|
174
|
+
float e = 0.02;
|
|
175
|
+
float hx = height(hit.xz + vec2(e, 0.0), ptr, click) - height(hit.xz - vec2(e, 0.0), ptr, click);
|
|
176
|
+
float hz = height(hit.xz + vec2(0.0, e), ptr, click) - height(hit.xz - vec2(0.0, e), ptr, click);
|
|
177
|
+
vec3 n = normalize(vec3(-hx, 2.0 * e, -hz));
|
|
178
|
+
float diffuse = max(dot(n, normalize(vec3(-0.5, 0.8, 0.3))), 0.0);
|
|
179
|
+
// Strongly lit: crests catch the light (solid bars), troughs fall away.
|
|
180
|
+
float lit = mix(1.0, 0.2 + 1.5 * diffuse * diffuse, uLighting);
|
|
181
|
+
// Further away is dimmer.
|
|
182
|
+
float fog = exp(-max(hi - 1.5, 0.0) * 0.35);
|
|
183
|
+
return clamp(streaks(hit.xz) * lit * fog, 0.0, 1.0);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// The cloud: data gathered where a slow, large noise is high, and within
|
|
187
|
+
// that, noise squashed along the rows so it reads as short dashes and
|
|
188
|
+
// blocks rather than texture. Each row streams sideways at its own pace;
|
|
189
|
+
// the cloud itself drifts far more slowly.
|
|
190
|
+
float cloud(vec2 px) {
|
|
191
|
+
vec2 uv = px / uRes.y;
|
|
192
|
+
float pace = 0.6 + 0.8 * hash(vec2(floor(px.y / uCell.y), 3.7));
|
|
193
|
+
float gather = smoothstep(0.32, 0.6, fbm(uv * 1.0 + vec2(3.1 - uTime * 0.02, 7.7)));
|
|
194
|
+
float dashes = smoothstep(0.5, 0.78, fbm(vec2((uv.x - uTime * 0.35 * pace) * 3.2, uv.y * 20.0)));
|
|
195
|
+
// Gaps: some cells stay dark however bright the cloud is there.
|
|
196
|
+
float gap = step(0.08, hash(floor(px / uCell) + 17.0));
|
|
197
|
+
// Faint cells only where a run is ending, not scattered over the dark.
|
|
198
|
+
return smoothstep(0.12, 0.85, clamp(gather * dashes * gap * 2.4, 0.0, 1.0));
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// A cell's brightness: the pattern where its centre is, flickering
|
|
202
|
+
// a little as a readout refreshes. The quiet area lowers it before a glyph
|
|
203
|
+
// is chosen, so the rain thins out there rather than turning grey.
|
|
204
|
+
float level(vec2 cell) {
|
|
205
|
+
vec2 centre = (cell + 0.5) * uCell;
|
|
206
|
+
float open = mix(1.0 - uQuiet.w, 1.0, quietOpen((centre - 0.5 * uRes) / uRes.y));
|
|
207
|
+
float b = uPattern > 0.5 ? rain(centre) : cloud(centre);
|
|
208
|
+
return b * (0.9 + 0.2 * hash(cell + floor(uTime * 12.0))) * open * open;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// How much light the glyph under a pixel gives, given the brightness of
|
|
212
|
+
// the pixel's own cell and its neighbours either side (lv.x left, lv.y
|
|
213
|
+
// own, lv.z right). Faint glyphs are dim; outlines and solids are full.
|
|
214
|
+
float ink(vec2 px, float column, vec3 lv) {
|
|
215
|
+
float dx = floor(px.x / uCell.x) - column;
|
|
216
|
+
float b = dx < -0.5 ? lv.x : (dx > 0.5 ? lv.z : lv.y);
|
|
217
|
+
return glyph(fract(px / uCell), b) * (b < 0.5 ? b * 0.9 : 1.0);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
void main() {
|
|
221
|
+
// Glitches: now and then a row jumps a few cells sideways for a moment,
|
|
222
|
+
// its colours split wider while it does.
|
|
223
|
+
float row = floor(gl_FragCoord.y / uCell.y);
|
|
224
|
+
float tick = floor(uTime * 6.0);
|
|
225
|
+
float jolt = step(1.0 - 0.02 * uGlitch, hash(vec2(row, tick)));
|
|
226
|
+
float cells = floor((hash(vec2(row + 7.0, tick)) - 0.5) * 8.0);
|
|
227
|
+
vec2 px = gl_FragCoord.xy + vec2(cells * uCell.x * jolt, 0.0);
|
|
228
|
+
vec2 cell = floor(px / uCell);
|
|
229
|
+
vec3 lv = vec3(level(cell - vec2(1.0, 0.0)), level(cell), level(cell + vec2(1.0, 0.0)));
|
|
230
|
+
if (max(lv.x, max(lv.y, lv.z)) < 0.01) {
|
|
231
|
+
gl_FragColor = vec4(0.0);
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
// Each channel softened a little; red moved right and blue left, so a
|
|
235
|
+
// bar shades blue, cyan, white, yellow, red across, and an outline's
|
|
236
|
+
// inside fills purple.
|
|
237
|
+
vec2 shift = vec2(uAberration * (1.0 + 2.0 * jolt), 0.0);
|
|
238
|
+
float r = 0.0;
|
|
239
|
+
float g = 0.0;
|
|
240
|
+
float bl = 0.0;
|
|
241
|
+
float sum = 0.0;
|
|
242
|
+
for (int i = -2; i <= 2; i++) {
|
|
243
|
+
float w = 3.0 - abs(float(i));
|
|
244
|
+
vec2 k = vec2(float(i) * uAberration * 0.35, 0.0);
|
|
245
|
+
r += w * ink(px - shift + k, cell.x, lv);
|
|
246
|
+
g += w * ink(px + k, cell.x, lv);
|
|
247
|
+
bl += w * ink(px + shift + k, cell.x, lv);
|
|
248
|
+
sum += w;
|
|
249
|
+
}
|
|
250
|
+
vec2 centre = (cell + 0.5) * uCell;
|
|
251
|
+
// Dim cells take the palette; the brightest go nearly white, keeping a cast of it.
|
|
252
|
+
vec3 tint = mix(pal(hash(cell.yy) * 0.4 + centre.x / uRes.x * 0.4 + uTime * 0.02), vec3(1.0), smoothstep(0.3, 0.9, lv.y) * 0.7);
|
|
253
|
+
vec3 col = tint * vec3(r, g, bl) / sum;
|
|
254
|
+
gl_FragColor = vec4(col, clamp(max(col.r, max(col.g, col.b)), 0.0, 1.0));
|
|
255
|
+
}
|
|
256
|
+
`;
|
|
257
|
+
|
|
258
|
+
/** The default palette: a cool readout, cyan and green, near white where it is brightest. */
|
|
259
|
+
const COOL = ['#7ef9e3', '#9df3b0', '#a5e8ff'];
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Starts ASCII rain on an element: a transparent canvas inside it, filling it.
|
|
263
|
+
*
|
|
264
|
+
* @param {HTMLElement} el The element (its first canvas is drawn into).
|
|
265
|
+
* @param {AsciiRainConfig} config The settings.
|
|
266
|
+
* @returns {() => void} Stops it.
|
|
267
|
+
*/
|
|
268
|
+
export function asciiRain(el, config) {
|
|
269
|
+
const waves = config.pattern === 'waves';
|
|
270
|
+
const speed = config.speed ?? 1;
|
|
271
|
+
// A still cloud needs no loop at all: one frame, drawn again only on a resize.
|
|
272
|
+
const moving = waves || speed > 0;
|
|
273
|
+
const glyphs = config.glyphs ?? 'data';
|
|
274
|
+
// Shapes sit in square cells; type in the usual tall ones.
|
|
275
|
+
const aspect = config.aspect ?? (glyphs === 'data' ? 1 : 0.6);
|
|
276
|
+
let palette = paletteUniform(pickColors(config, COOL));
|
|
277
|
+
const start = performance.now();
|
|
278
|
+
const ptr = { x: 0, y: 0 };
|
|
279
|
+
let active = 0;
|
|
280
|
+
/** The last click: where (canvas px, y up) and when (shader seconds); long ago at first. */
|
|
281
|
+
const click = { x: 0, y: 0, t: -100 };
|
|
282
|
+
/**
|
|
283
|
+
* The shader's clock.
|
|
284
|
+
*
|
|
285
|
+
* @param {number} now The time, ms.
|
|
286
|
+
* @returns {number} Seconds since the start, at the rain's speed.
|
|
287
|
+
*/
|
|
288
|
+
const clock = (now) => ((now - start) / 1000) * speed;
|
|
289
|
+
|
|
290
|
+
const { stage, stop } = createStage(el, {
|
|
291
|
+
fragment: FRAG,
|
|
292
|
+
still: !moving,
|
|
293
|
+
setup({ gl, uniform, still }) {
|
|
294
|
+
gl.uniform1f(uniform('uPattern'), waves ? 1 : 0);
|
|
295
|
+
gl.uniform1f(uniform('uGlitch'), Math.max(0, config.glitch ?? 1));
|
|
296
|
+
const { count } = createGlyphs(gl, glyphs, { unit: 0, font: config.font, aspect });
|
|
297
|
+
gl.uniform1i(uniform('uGlyphs'), 0);
|
|
298
|
+
gl.uniform1f(uniform('uGlyphCount'), count);
|
|
299
|
+
const angle = ((config.angle ?? 0) * Math.PI) / 180;
|
|
300
|
+
gl.uniform2f(uniform('uDir'), Math.cos(angle), -Math.sin(angle));
|
|
301
|
+
gl.uniform1f(uniform('uLines'), config.lines ?? 40);
|
|
302
|
+
gl.uniform1f(uniform('uTrail'), Math.min(1, Math.max(0.02, config.trail ?? 0.3)));
|
|
303
|
+
gl.uniform1f(uniform('uDensity'), Math.min(1, Math.max(0, config.density ?? 0.7)));
|
|
304
|
+
gl.uniform1f(uniform('uWidth'), Math.min(1, Math.max(0.05, config.width ?? 0.9)));
|
|
305
|
+
gl.uniform1f(uniform('uVariance'), config.variance ?? 0.6);
|
|
306
|
+
gl.uniform1f(uniform('uRipple'), config.ripple ?? 1);
|
|
307
|
+
gl.uniform1f(uniform('uWaves'), config.waves ?? 1);
|
|
308
|
+
gl.uniform1f(uniform('uTilt'), (Math.min(80, Math.max(0, config.tilt ?? 58)) * Math.PI) / 180);
|
|
309
|
+
gl.uniform1f(uniform('uZoom'), config.zoom ?? 1);
|
|
310
|
+
gl.uniform1f(uniform('uLighting'), config.lighting ?? 1);
|
|
311
|
+
if (!waves || config.interactive === false || still) return;
|
|
312
|
+
/**
|
|
313
|
+
* Drops a ring where the element is pressed.
|
|
314
|
+
*
|
|
315
|
+
* @param {PointerEvent} e The press.
|
|
316
|
+
*/
|
|
317
|
+
const drop = (e) => {
|
|
318
|
+
const at = pressAt(el, e);
|
|
319
|
+
if (at && stage) Object.assign(click, { x: at.x * stage.canvas.width, y: at.y * stage.canvas.height, t: clock(performance.now()) });
|
|
320
|
+
};
|
|
321
|
+
document.addEventListener('pointerdown', drop);
|
|
322
|
+
return () => document.removeEventListener('pointerdown', drop);
|
|
323
|
+
},
|
|
324
|
+
resize({ gl, uniform, canvas, ratio }) {
|
|
325
|
+
const h = (config.cell ?? 14) * ratio;
|
|
326
|
+
gl.uniform2f(uniform('uCell'), Math.round(h * aspect), Math.round(h));
|
|
327
|
+
gl.uniform1f(uniform('uAberration'), (config.aberration ?? 3) * ratio);
|
|
328
|
+
gl.uniform4f(uniform('uQuiet'), ...quietUniform(config.quiet, canvas.width / canvas.height));
|
|
329
|
+
},
|
|
330
|
+
uniforms({ gl, uniform, canvas, still }, now) {
|
|
331
|
+
// The ripples follow the pointer while it is over the element.
|
|
332
|
+
const p = waves && config.interactive !== false && !still && canHover() ? pointerIn(el) : null;
|
|
333
|
+
if (p?.inside) {
|
|
334
|
+
ptr.x += (p.x * canvas.width - ptr.x) * 0.15;
|
|
335
|
+
ptr.y += (p.y * canvas.height - ptr.y) * 0.15;
|
|
336
|
+
}
|
|
337
|
+
active += ((p?.inside ? 1 : 0) - active) * 0.05;
|
|
338
|
+
gl.uniform1f(uniform('uTime'), clock(now));
|
|
339
|
+
gl.uniform2f(uniform('uPtr'), ptr.x, ptr.y);
|
|
340
|
+
gl.uniform1f(uniform('uActive'), active);
|
|
341
|
+
gl.uniform3f(uniform('uClick'), click.x, click.y, click.t);
|
|
342
|
+
gl.uniform3fv(uniform('uPal'), palette);
|
|
343
|
+
},
|
|
344
|
+
});
|
|
345
|
+
if (!stage) return stop;
|
|
346
|
+
|
|
347
|
+
const unwatch = watchColors(el, (next) => {
|
|
348
|
+
palette = paletteUniform(next.colors);
|
|
349
|
+
if (stage.still) stage.redraw();
|
|
350
|
+
});
|
|
351
|
+
return () => {
|
|
352
|
+
stop();
|
|
353
|
+
unwatch();
|
|
354
|
+
};
|
|
355
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** The bands, Hz: bass, mid and treble, and the low end where kicks live. */
|
|
2
|
+
export const BANDS: {
|
|
3
|
+
bass: [number, number];
|
|
4
|
+
mid: [number, number];
|
|
5
|
+
treble: [number, number];
|
|
6
|
+
kick: [number, number];
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/** Bins in a meter's `spectrum`. */
|
|
10
|
+
export const SPECTRUM: number;
|
|
11
|
+
|
|
12
|
+
/** Points in a meter's `waveform`. */
|
|
13
|
+
export const WAVEFORM: number;
|
|
14
|
+
|
|
15
|
+
/** What a meter reports each frame. The arrays are the meter's own, filled again each frame. */
|
|
16
|
+
export interface Reading {
|
|
17
|
+
/** How loud, 0–1 (`loudness`, eased). */
|
|
18
|
+
level: number;
|
|
19
|
+
/** The bass band, 0–1, eased. */
|
|
20
|
+
bass: number;
|
|
21
|
+
/** The mid band, 0–1, eased. */
|
|
22
|
+
mid: number;
|
|
23
|
+
/** The treble band, 0–1, eased. */
|
|
24
|
+
treble: number;
|
|
25
|
+
/** A kick's light: 1 (or its strength) on a kick in the low end, fading over a fifth of a second. */
|
|
26
|
+
kick: number;
|
|
27
|
+
/** Kicks heard so far: an effect does something once each time it goes up. */
|
|
28
|
+
beats: number;
|
|
29
|
+
/** `SPECTRUM` log-spaced bins, 0–1, lowest first, eased. */
|
|
30
|
+
spectrum: Float32Array;
|
|
31
|
+
/** `WAVEFORM` points of the trace (`scope`), -1–1, eased and scaled to its own recent peak. */
|
|
32
|
+
waveform: Float32Array;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** A meter: the analyser's bytes each frame in, an eased reading out. */
|
|
36
|
+
export interface Meter {
|
|
37
|
+
/** The latest reading. */
|
|
38
|
+
reading: Reading;
|
|
39
|
+
/** Reads a frame of the analyser's spectrum and waveform `dt` seconds after the last. */
|
|
40
|
+
update(freq: ArrayLike<number>, time: ArrayLike<number>, binHz: number, dt: number): Reading;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The mean of a spectrum's bins (bytes 0–255, bin 0 at 0 Hz, `binHz` apart) between two frequencies, 0–1. */
|
|
44
|
+
export function bandLevel(freq: ArrayLike<number>, binHz: number, lo: number, hi: number): number;
|
|
45
|
+
|
|
46
|
+
/** How loud a waveform (bytes centred on 128) is: its RMS in decibels, mapped to 0–1. */
|
|
47
|
+
export function loudness(time: ArrayLike<number>): number;
|
|
48
|
+
|
|
49
|
+
/** Resamples a spectrum into `out`'s log-spaced bins between `lo` and `hi` Hz (default 40–16000), 0–1, tilted so the treble reads. Returns `out`. */
|
|
50
|
+
export function logSpectrum(freq: ArrayLike<number>, binHz: number, out: Float32Array, lo?: number, hi?: number): Float32Array;
|
|
51
|
+
|
|
52
|
+
/** The waveform as an oscilloscope draws it, from a rising zero crossing, averaged down to `out`'s length, -1–1. Returns `out`. */
|
|
53
|
+
export function scope(time: ArrayLike<number>, out: Float32Array): Float32Array;
|
|
54
|
+
|
|
55
|
+
/** A value read between an array's entries, as a texture reads: `u` 0 is the first, 1 the last (clamped), linearly blended between. */
|
|
56
|
+
export function sampleAt(values: ArrayLike<number>, u: number): number;
|
|
57
|
+
|
|
58
|
+
/** Resamples values (at least two) onto `out` along a smooth Catmull-Rom curve through them, its ends on the first and last. Returns `out`. */
|
|
59
|
+
export function smoothInto(values: ArrayLike<number>, out: Float32Array): Float32Array;
|
|
60
|
+
|
|
61
|
+
/** Eases a value towards a target over `dt` seconds: time constant `rise` going up, `fall` going down. */
|
|
62
|
+
export function follow(value: number, target: number, dt: number, rise: number, fall: number): number;
|
|
63
|
+
|
|
64
|
+
/** A meter, reading silence. */
|
|
65
|
+
export function createMeter(): Meter;
|