@arraypress/effects-astro 0.0.0-stage → 0.1.1

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.
Files changed (314) hide show
  1. package/AGENTS.md +85 -0
  2. package/COMPONENTS.md +1264 -0
  3. package/LICENSE +139 -0
  4. package/README.md +197 -2
  5. package/package.json +60 -4
  6. package/src/components/AsciiRain.astro +36 -0
  7. package/src/components/BorderSweep.astro +39 -0
  8. package/src/components/Caustics.astro +39 -0
  9. package/src/components/ColorPanels.astro +62 -0
  10. package/src/components/Cursor.astro +97 -0
  11. package/src/components/DotGrid.astro +34 -0
  12. package/src/components/DotSurface.astro +35 -0
  13. package/src/components/EffectCanvas.astro +152 -0
  14. package/src/components/FitText.astro +35 -0
  15. package/src/components/FlutedGlass.astro +36 -0
  16. package/src/components/Glass.astro +69 -0
  17. package/src/components/GlassGlyph.astro +38 -0
  18. package/src/components/GlowField.astro +177 -0
  19. package/src/components/Grain.astro +98 -0
  20. package/src/components/HaloRing.astro +38 -0
  21. package/src/components/HighlightSweep.astro +74 -0
  22. package/src/components/ImageRipple.astro +56 -0
  23. package/src/components/Ink.astro +37 -0
  24. package/src/components/InkField.astro +45 -0
  25. package/src/components/IsoCity.astro +54 -0
  26. package/src/components/LightField.astro +40 -0
  27. package/src/components/LiquidMetal.astro +41 -0
  28. package/src/components/Magnetic.astro +52 -0
  29. package/src/components/Marquee.astro +216 -0
  30. package/src/components/MosaicReveal.astro +196 -0
  31. package/src/components/NebulaLogo.astro +38 -0
  32. package/src/components/NeonSwarm.astro +38 -0
  33. package/src/components/Ocean.astro +40 -0
  34. package/src/components/OutlineWordmark.astro +222 -0
  35. package/src/components/PaperBackground.astro +40 -0
  36. package/src/components/PaperShader.astro +55 -0
  37. package/src/components/Parallax.astro +49 -0
  38. package/src/components/ParticleLogo.astro +37 -0
  39. package/src/components/PixelGlitchText.astro +70 -0
  40. package/src/components/PointCloud.astro +37 -0
  41. package/src/components/ProductStack.astro +298 -0
  42. package/src/components/PulseMark.astro +189 -0
  43. package/src/components/RadiantGlass.astro +38 -0
  44. package/src/components/RainOnGlass.astro +71 -0
  45. package/src/components/Reveal.astro +115 -0
  46. package/src/components/ScrambleText.astro +52 -0
  47. package/src/components/ScrollReveal.astro +38 -0
  48. package/src/components/ShaderBackground.astro +55 -0
  49. package/src/components/SignalLines.astro +41 -0
  50. package/src/components/SilkRibbon.astro +37 -0
  51. package/src/components/SpotlightText.astro +131 -0
  52. package/src/components/Tilt.astro +79 -0
  53. package/src/components/Topography.astro +38 -0
  54. package/src/components/Typewriter.astro +66 -0
  55. package/src/components/VariableType.astro +59 -0
  56. package/src/components/VoxelLogo.astro +46 -0
  57. package/src/components/WaveBars.astro +41 -0
  58. package/src/components/WorldRoutes.astro +41 -0
  59. package/src/components/style.js +19 -0
  60. package/src/index.d.ts +143 -0
  61. package/src/index.js +105 -0
  62. package/src/runtime/ascii-rain.d.ts +53 -0
  63. package/src/runtime/ascii-rain.js +355 -0
  64. package/src/runtime/audio-meter.d.ts +65 -0
  65. package/src/runtime/audio-meter.js +282 -0
  66. package/src/runtime/audio.d.ts +26 -0
  67. package/src/runtime/audio.js +453 -0
  68. package/src/runtime/blur.d.ts +2 -0
  69. package/src/runtime/blur.js +56 -0
  70. package/src/runtime/canvas2d.d.ts +23 -0
  71. package/src/runtime/canvas2d.js +105 -0
  72. package/src/runtime/caustics.d.ts +40 -0
  73. package/src/runtime/caustics.js +286 -0
  74. package/src/runtime/color.d.ts +33 -0
  75. package/src/runtime/color.js +213 -0
  76. package/src/runtime/curl.d.ts +5 -0
  77. package/src/runtime/curl.js +81 -0
  78. package/src/runtime/cursor.d.ts +9 -0
  79. package/src/runtime/cursor.js +80 -0
  80. package/src/runtime/device.d.ts +14 -0
  81. package/src/runtime/device.js +73 -0
  82. package/src/runtime/dot-grid.d.ts +27 -0
  83. package/src/runtime/dot-grid.js +245 -0
  84. package/src/runtime/dot-surface.d.ts +46 -0
  85. package/src/runtime/dot-surface.js +429 -0
  86. package/src/runtime/feedback.d.ts +18 -0
  87. package/src/runtime/feedback.js +131 -0
  88. package/src/runtime/fit-text.d.ts +5 -0
  89. package/src/runtime/fit-text.js +60 -0
  90. package/src/runtime/fluid.d.ts +55 -0
  91. package/src/runtime/fluid.js +504 -0
  92. package/src/runtime/fluted-glass.d.ts +27 -0
  93. package/src/runtime/fluted-glass.js +157 -0
  94. package/src/runtime/gl.d.ts +19 -0
  95. package/src/runtime/gl.js +104 -0
  96. package/src/runtime/glass-glyph.d.ts +49 -0
  97. package/src/runtime/glass-glyph.js +355 -0
  98. package/src/runtime/glass-sheen.d.ts +2 -0
  99. package/src/runtime/glass-sheen.js +30 -0
  100. package/src/runtime/glsl.d.ts +17 -0
  101. package/src/runtime/glsl.js +78 -0
  102. package/src/runtime/glyphs.d.ts +22 -0
  103. package/src/runtime/glyphs.js +107 -0
  104. package/src/runtime/halo-ring.d.ts +47 -0
  105. package/src/runtime/halo-ring.js +334 -0
  106. package/src/runtime/height-field.d.ts +50 -0
  107. package/src/runtime/height-field.js +176 -0
  108. package/src/runtime/image-ripple.d.ts +25 -0
  109. package/src/runtime/image-ripple.js +353 -0
  110. package/src/runtime/image.d.ts +11 -0
  111. package/src/runtime/image.js +81 -0
  112. package/src/runtime/in-view.d.ts +6 -0
  113. package/src/runtime/in-view.js +36 -0
  114. package/src/runtime/ink-field/shaders.js +258 -0
  115. package/src/runtime/ink-field/sim.js +582 -0
  116. package/src/runtime/ink-field.d.ts +39 -0
  117. package/src/runtime/ink-field.js +311 -0
  118. package/src/runtime/ink.d.ts +31 -0
  119. package/src/runtime/ink.js +109 -0
  120. package/src/runtime/instancing.d.ts +12 -0
  121. package/src/runtime/instancing.js +37 -0
  122. package/src/runtime/iso-camera.d.ts +35 -0
  123. package/src/runtime/iso-camera.js +85 -0
  124. package/src/runtime/iso-city/figures.d.ts +30 -0
  125. package/src/runtime/iso-city/figures.js +136 -0
  126. package/src/runtime/iso-city/look.d.ts +34 -0
  127. package/src/runtime/iso-city/look.js +105 -0
  128. package/src/runtime/iso-city/plan.d.ts +59 -0
  129. package/src/runtime/iso-city/plan.js +463 -0
  130. package/src/runtime/iso-city/roads.d.ts +64 -0
  131. package/src/runtime/iso-city/roads.js +320 -0
  132. package/src/runtime/iso-city/scene.d.ts +27 -0
  133. package/src/runtime/iso-city/scene.js +432 -0
  134. package/src/runtime/iso-city/shaders.d.ts +6 -0
  135. package/src/runtime/iso-city/shaders.js +233 -0
  136. package/src/runtime/iso-city/shadows.d.ts +13 -0
  137. package/src/runtime/iso-city/shadows.js +148 -0
  138. package/src/runtime/iso-city/traffic.d.ts +80 -0
  139. package/src/runtime/iso-city/traffic.js +457 -0
  140. package/src/runtime/iso-city.d.ts +37 -0
  141. package/src/runtime/iso-city.js +458 -0
  142. package/src/runtime/lens-map.d.ts +11 -0
  143. package/src/runtime/lens-map.js +146 -0
  144. package/src/runtime/light-field.d.ts +29 -0
  145. package/src/runtime/light-field.js +292 -0
  146. package/src/runtime/liquid-glass.d.ts +48 -0
  147. package/src/runtime/liquid-glass.js +423 -0
  148. package/src/runtime/liquid-metal/beads.js +217 -0
  149. package/src/runtime/liquid-metal/field.js +88 -0
  150. package/src/runtime/liquid-metal/look.js +64 -0
  151. package/src/runtime/liquid-metal/shaders.js +255 -0
  152. package/src/runtime/liquid-metal/wave.js +53 -0
  153. package/src/runtime/liquid-metal.d.ts +46 -0
  154. package/src/runtime/liquid-metal.js +366 -0
  155. package/src/runtime/loop.d.ts +7 -0
  156. package/src/runtime/loop.js +112 -0
  157. package/src/runtime/magnetic.d.ts +9 -0
  158. package/src/runtime/magnetic.js +46 -0
  159. package/src/runtime/marquee.d.ts +2 -0
  160. package/src/runtime/marquee.js +27 -0
  161. package/src/runtime/mesh.d.ts +30 -0
  162. package/src/runtime/mesh.js +217 -0
  163. package/src/runtime/mosaic-reveal.d.ts +34 -0
  164. package/src/runtime/mosaic-reveal.js +504 -0
  165. package/src/runtime/motion.d.ts +2 -0
  166. package/src/runtime/motion.js +21 -0
  167. package/src/runtime/mount.d.ts +13 -0
  168. package/src/runtime/mount.js +120 -0
  169. package/src/runtime/nebula-logo.d.ts +31 -0
  170. package/src/runtime/nebula-logo.js +282 -0
  171. package/src/runtime/neon-swarm.d.ts +31 -0
  172. package/src/runtime/neon-swarm.js +258 -0
  173. package/src/runtime/ocean/presets.d.ts +54 -0
  174. package/src/runtime/ocean/presets.js +184 -0
  175. package/src/runtime/ocean/shader.d.ts +14 -0
  176. package/src/runtime/ocean/shader.js +389 -0
  177. package/src/runtime/ocean/view.d.ts +24 -0
  178. package/src/runtime/ocean/view.js +98 -0
  179. package/src/runtime/ocean/waves.d.ts +29 -0
  180. package/src/runtime/ocean/waves.js +119 -0
  181. package/src/runtime/ocean.d.ts +31 -0
  182. package/src/runtime/ocean.js +173 -0
  183. package/src/runtime/palettes.d.ts +37 -0
  184. package/src/runtime/palettes.js +75 -0
  185. package/src/runtime/paper-look.d.ts +42 -0
  186. package/src/runtime/paper-look.js +91 -0
  187. package/src/runtime/paper-looks.d.ts +17 -0
  188. package/src/runtime/paper-looks.js +21 -0
  189. package/src/runtime/paper.d.ts +37 -0
  190. package/src/runtime/paper.js +303 -0
  191. package/src/runtime/particle-logo.d.ts +31 -0
  192. package/src/runtime/particle-logo.js +196 -0
  193. package/src/runtime/ping-pong.d.ts +43 -0
  194. package/src/runtime/ping-pong.js +175 -0
  195. package/src/runtime/pixel-glitch.d.ts +17 -0
  196. package/src/runtime/pixel-glitch.js +287 -0
  197. package/src/runtime/point-cloud.d.ts +33 -0
  198. package/src/runtime/point-cloud.js +287 -0
  199. package/src/runtime/pointer.d.ts +27 -0
  200. package/src/runtime/pointer.js +128 -0
  201. package/src/runtime/points.d.ts +25 -0
  202. package/src/runtime/points.js +130 -0
  203. package/src/runtime/pools.d.ts +2 -0
  204. package/src/runtime/pools.js +25 -0
  205. package/src/runtime/product-stack.d.ts +24 -0
  206. package/src/runtime/product-stack.js +210 -0
  207. package/src/runtime/radiant-glass.d.ts +29 -0
  208. package/src/runtime/radiant-glass.js +282 -0
  209. package/src/runtime/rain-on-glass/backdrop.d.ts +22 -0
  210. package/src/runtime/rain-on-glass/backdrop.js +185 -0
  211. package/src/runtime/rain-on-glass/shader.d.ts +2 -0
  212. package/src/runtime/rain-on-glass/shader.js +168 -0
  213. package/src/runtime/rain-on-glass/wipe.d.ts +16 -0
  214. package/src/runtime/rain-on-glass/wipe.js +65 -0
  215. package/src/runtime/rain-on-glass.d.ts +27 -0
  216. package/src/runtime/rain-on-glass.js +210 -0
  217. package/src/runtime/ramp.d.ts +2 -0
  218. package/src/runtime/ramp.js +30 -0
  219. package/src/runtime/random.d.ts +2 -0
  220. package/src/runtime/random.js +22 -0
  221. package/src/runtime/scroll-reveal.d.ts +22 -0
  222. package/src/runtime/scroll-reveal.js +73 -0
  223. package/src/runtime/shader-background.d.ts +42 -0
  224. package/src/runtime/shader-background.js +261 -0
  225. package/src/runtime/shader-backgrounds/band-lens.js +72 -0
  226. package/src/runtime/shader-backgrounds/common.js +53 -0
  227. package/src/runtime/shader-backgrounds/grain-gradient.js +87 -0
  228. package/src/runtime/shader-backgrounds/grid.js +33 -0
  229. package/src/runtime/shader-backgrounds/mesh-gradient.js +74 -0
  230. package/src/runtime/shader-backgrounds/silk.js +57 -0
  231. package/src/runtime/shader-backgrounds/waves.js +31 -0
  232. package/src/runtime/shape.d.ts +42 -0
  233. package/src/runtime/shape.js +313 -0
  234. package/src/runtime/silk-ribbon.d.ts +23 -0
  235. package/src/runtime/silk-ribbon.js +206 -0
  236. package/src/runtime/slideshow.d.ts +27 -0
  237. package/src/runtime/slideshow.js +234 -0
  238. package/src/runtime/spotlight.d.ts +9 -0
  239. package/src/runtime/spotlight.js +97 -0
  240. package/src/runtime/stack-poses.d.ts +53 -0
  241. package/src/runtime/stack-poses.js +273 -0
  242. package/src/runtime/stage.d.ts +47 -0
  243. package/src/runtime/stage.js +187 -0
  244. package/src/runtime/swarm.d.ts +49 -0
  245. package/src/runtime/swarm.js +199 -0
  246. package/src/runtime/text-motion.d.ts +41 -0
  247. package/src/runtime/text-motion.js +165 -0
  248. package/src/runtime/text.d.ts +11 -0
  249. package/src/runtime/text.js +90 -0
  250. package/src/runtime/tilt.d.ts +19 -0
  251. package/src/runtime/tilt.js +116 -0
  252. package/src/runtime/topography.d.ts +71 -0
  253. package/src/runtime/topography.js +650 -0
  254. package/src/runtime/trackers.d.ts +21 -0
  255. package/src/runtime/trackers.js +76 -0
  256. package/src/runtime/variable-type.d.ts +43 -0
  257. package/src/runtime/variable-type.js +358 -0
  258. package/src/runtime/voxel-logo.d.ts +31 -0
  259. package/src/runtime/voxel-logo.js +237 -0
  260. package/src/runtime/waves.d.ts +70 -0
  261. package/src/runtime/waves.js +799 -0
  262. package/src/runtime/world-labels.d.ts +29 -0
  263. package/src/runtime/world-labels.js +59 -0
  264. package/src/runtime/world-land.d.ts +8 -0
  265. package/src/runtime/world-land.js +105 -0
  266. package/src/runtime/world-map.d.ts +69 -0
  267. package/src/runtime/world-map.js +308 -0
  268. package/src/runtime/world-plan.d.ts +101 -0
  269. package/src/runtime/world-plan.js +333 -0
  270. package/src/runtime/world-routes.d.ts +75 -0
  271. package/src/runtime/world-routes.js +673 -0
  272. package/src/styles/border-sweep.css +82 -0
  273. package/src/styles/glass.css +104 -0
  274. package/src/styles/motion.css +218 -0
  275. package/src/styles/reveal.css +51 -0
  276. package/src/vendor/paper/LICENSE +201 -0
  277. package/src/vendor/paper/NOTICE +5 -0
  278. package/src/vendor/paper/README.md +8 -0
  279. package/src/vendor/paper/get-shader-color-from-string.js +100 -0
  280. package/src/vendor/paper/get-shader-noise-texture.js +17 -0
  281. package/src/vendor/paper/presets.js +3678 -0
  282. package/src/vendor/paper/shader-sizing.js +37 -0
  283. package/src/vendor/paper/shader-utils.js +130 -0
  284. package/src/vendor/paper/shaders/color-panels.js +223 -0
  285. package/src/vendor/paper/shaders/dithering.js +270 -0
  286. package/src/vendor/paper/shaders/dot-grid.js +109 -0
  287. package/src/vendor/paper/shaders/dot-orbit.js +122 -0
  288. package/src/vendor/paper/shaders/fluted-glass.js +360 -0
  289. package/src/vendor/paper/shaders/gem-smoke.js +572 -0
  290. package/src/vendor/paper/shaders/god-rays.js +132 -0
  291. package/src/vendor/paper/shaders/grain-gradient.js +300 -0
  292. package/src/vendor/paper/shaders/halftone-cmyk.js +294 -0
  293. package/src/vendor/paper/shaders/halftone-dots.js +320 -0
  294. package/src/vendor/paper/shaders/heatmap.js +383 -0
  295. package/src/vendor/paper/shaders/image-dithering.js +198 -0
  296. package/src/vendor/paper/shaders/lens-distortion.js +275 -0
  297. package/src/vendor/paper/shaders/liquid-metal.js +632 -0
  298. package/src/vendor/paper/shaders/mesh-gradient.js +130 -0
  299. package/src/vendor/paper/shaders/metaballs.js +110 -0
  300. package/src/vendor/paper/shaders/neuro-noise.js +76 -0
  301. package/src/vendor/paper/shaders/paper-texture.js +526 -0
  302. package/src/vendor/paper/shaders/perlin-noise.js +166 -0
  303. package/src/vendor/paper/shaders/pulsing-border.js +238 -0
  304. package/src/vendor/paper/shaders/simplex-noise.js +91 -0
  305. package/src/vendor/paper/shaders/smoke-ring.js +132 -0
  306. package/src/vendor/paper/shaders/spiral.js +82 -0
  307. package/src/vendor/paper/shaders/static-mesh-gradient.js +130 -0
  308. package/src/vendor/paper/shaders/static-radial-gradient.js +187 -0
  309. package/src/vendor/paper/shaders/swirl.js +103 -0
  310. package/src/vendor/paper/shaders/voronoi.js +138 -0
  311. package/src/vendor/paper/shaders/warp.js +129 -0
  312. package/src/vendor/paper/shaders/water.js +121 -0
  313. package/src/vendor/paper/shaders/waves.js +65 -0
  314. package/src/vendor/paper/vertex-shader.js +159 -0
@@ -0,0 +1,282 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/nebula-logo
3
+ *
4
+ * A logo or a word filled with drifting nebula gas: domain-warped clouds
5
+ * in the palette's colours, moving slowly inside the shape, brighter and
6
+ * denser towards its edges and cut with dark dust lanes deeper in. A
7
+ * glowing rim lines the edge, a soft halo of gas leaks a little past it,
8
+ * and faint stars twinkle inside. The pointer brightens the gas near it,
9
+ * and where it moves it stirs the gas round, a wake that settles again.
10
+ *
11
+ * The shape is a distance field (src/runtime/shape.js); the wake is a
12
+ * small fading feedback buffer (src/runtime/feedback.js) the pointer's
13
+ * path is drawn into. The gas is only worked out near the shape, so the
14
+ * cost follows the logo's size, not the canvas's.
15
+ *
16
+ * Opaque: the effect is the whole background of what it fills. Without
17
+ * WebGL it removes its canvas and the element's background shows.
18
+ */
19
+
20
+ import { createStage } from './stage.js';
21
+ import { createPoints } from './points.js';
22
+ import { createFeedback } from './feedback.js';
23
+ import { drawShape, distanceField, blurField } from './shape.js';
24
+ import { GLSL_NOISE, GLSL_PALETTE, paletteUniform } from './glsl.js';
25
+ import { parseColor } from './color.js';
26
+ import { canHover } from './device.js';
27
+ import { pointerIn, trail } from './pointer.js';
28
+ import { watchColors } from './mount.js';
29
+ import { pickColors } from './palettes.js';
30
+
31
+ /**
32
+ * @typedef {object} NebulaLogoConfig
33
+ * @property {string} [text] A word to fill with gas.
34
+ * @property {string} [font] Its CSS font, without the size (default: the page's, bold).
35
+ * @property {string} [src] An image (an SVG logo) to fill instead.
36
+ * @property {{ x: number, y: number, width: number, height: number }} [area]
37
+ * Where the shape sits, each 0–1 from the top left (default: the right half).
38
+ * @property {string[]} [colors] The gas's palette, three colours; the first, darkened, is also the thin gas's (default teal, amber, rose).
39
+ * @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`.
40
+ * @property {string} [background='#05070a'] The ground.
41
+ * @property {number} [speed=1] How fast the gas drifts.
42
+ * @property {number} [glow=1] The rim and the halo leaking past the edge; 0 for neither.
43
+ * @property {number} [stars=1] How many stars twinkle inside; 0 for none.
44
+ * @property {number} [stir=1] How much the pointer stirs and brightens the gas; 0 for not at all.
45
+ * @property {number} [scale=0.6] Share of the pixel ratio the gas is drawn at: it is soft, so a little below full costs nothing visible and saves most of the work.
46
+ */
47
+
48
+ const FRAG = `
49
+ precision highp float;
50
+ uniform vec2 uRes;
51
+ uniform float uTime;
52
+ uniform float uRatio;
53
+ uniform sampler2D uSdf;
54
+ uniform float uSpread;
55
+ uniform sampler2D uStir;
56
+ uniform vec2 uStirTexel;
57
+ uniform vec3 uGround;
58
+ uniform vec3 uPtr;
59
+ uniform float uGlow;
60
+ uniform float uStars;
61
+ uniform float uStirAmount;
62
+ ${GLSL_NOISE}
63
+ ${GLSL_PALETTE}
64
+
65
+ // The distance field: 0.5 at the shape's edge, more inside.
66
+ float field(vec2 uv) { return texture2D(uSdf, vec2(uv.x, 1.0 - uv.y)).r; }
67
+
68
+ // The stirred wake at a point.
69
+ float wake(vec2 uv) { return texture2D(uStir, uv).r; }
70
+
71
+ void main() {
72
+ vec2 uv = gl_FragCoord.xy / uRes;
73
+ float aspect = uRes.x / uRes.y;
74
+ // How far inside the edge, in heights; negative outside.
75
+ float d = (field(uv) - 0.5) * 2.0 * uSpread;
76
+ float out_ = max(-d, 0.0);
77
+ // Far outside: only the ground, and a faint glow that fades into it.
78
+ vec3 col = uGround;
79
+ if (d < -uSpread * 0.97) { gl_FragColor = vec4(col, 1.0); return; }
80
+
81
+ float px = 1.0 / uRes.y;
82
+ vec2 p = vec2(uv.x * aspect, uv.y);
83
+ vec2 toPtr = (uv - uPtr.xy) * vec2(aspect, 1.0);
84
+ float near = exp(-dot(toPtr, toPtr) / 0.018) * uPtr.z;
85
+ // The wake: the gas is pushed round the pointer's path, and lit by it.
86
+ float s = min(wake(uv), 1.0);
87
+ vec2 e = uStirTexel * 3.0;
88
+ vec2 g = vec2(wake(uv + vec2(e.x, 0.0)) - wake(uv - vec2(e.x, 0.0)), wake(uv + vec2(0.0, e.y)) - wake(uv - vec2(0.0, e.y)));
89
+ vec2 q0 = p * 2.6 + vec2(-g.y, g.x) * 1.8 * uStirAmount;
90
+
91
+ // The gas: fbm warped by fbm warped by fbm, each layer drifting its own way.
92
+ float t = uTime * 0.03;
93
+ vec2 q = vec2(fbm(q0 + vec2(0.0, t)), fbm(q0 + vec2(5.2, 1.3) - t * 0.8));
94
+ vec2 r = vec2(fbm(q0 + 3.4 * q + vec2(1.7, 9.2) + t * 1.4), fbm(q0 + 3.4 * q + vec2(8.3, 2.8) - t * 1.1));
95
+ float f = fbm(q0 + 3.0 * r);
96
+ float dens = smoothstep(0.22, 0.8, f);
97
+ // Thin gas is the first colour, deep and dark; thick gas glows in the palette.
98
+ vec3 bright = pal(f * 1.2 + q.x * 0.7 - r.y * 0.5 + t * 0.4);
99
+ vec3 hue = mix(pal(0.0) * 0.32, bright, smoothstep(0.05, 0.6, dens));
100
+ // What the pointer adds: its own light near it, and more where it has stirred.
101
+ float lift = (s * 1.2 + near * 0.5) * uStirAmount;
102
+
103
+ // Inside: densest at the edge, with dark lanes of dust deeper in.
104
+ float inside = smoothstep(-px, px, d);
105
+ float edge = exp(-max(d, 0.0) / 0.06);
106
+ float dust = smoothstep(0.45, 0.72, fbm(q0 * 1.7 + r * 2.0 + 7.0)) * (1.0 - edge * 0.6);
107
+ vec3 gas = hue * (dens * mix(0.4, 1.6, edge) + 0.1 + edge * 0.15);
108
+ gas += vec3(1.0, 0.96, 0.9) * pow(dens, 5.0) * 0.45 * (0.4 + edge);
109
+ gas *= 1.0 - dust * 0.7;
110
+ gas += bright * lift * (0.25 + dens * 0.6);
111
+
112
+ // Past the edge: wisps of gas leaking out, and a wide faint glow.
113
+ float leak = exp(-out_ / 0.024) * smoothstep(0.45, 0.8, f) * 1.2 + exp(-out_ / 0.08) * 0.05 * smoothstep(-uSpread, -uSpread * 0.5, d);
114
+ vec3 halo = hue * leak * uGlow * (1.0 + lift);
115
+
116
+ // The rim: a thin line of light round the edge, lit where the gas is thick and
117
+ // fading where it thins, in the gas's colour.
118
+ float rim = (exp(-abs(d) / (px * 1.2 * uRatio)) * 0.7 + exp(-abs(d) / 0.006) * 0.3) * uGlow;
119
+ vec3 lit = mix(pal(f * 1.2 + 0.2 + t * 0.4), vec3(1.0), 0.35) * rim * (0.1 + dens * dens * 1.4);
120
+
121
+ // Stars: one at most in each small cell, a few cells in a hundred, twinkling.
122
+ vec2 sp = gl_FragCoord.xy / (uRatio * 8.0);
123
+ vec2 cell = floor(sp);
124
+ float h = hash(cell);
125
+ vec2 at = vec2(hash(cell + 3.1), hash(cell + 7.7)) * 0.7 + 0.15;
126
+ float dist = length(fract(sp) - at) * 8.0;
127
+ float twinkle = 0.45 + 0.55 * sin(uTime * (0.8 + h * 2.5) + h * 60.0);
128
+ float star = step(1.0 - 0.06 * uStars, h) * exp(-dist * dist * 1.4) * twinkle * (inside * (1.0 - dust * 0.6) + exp(-out_ / 0.03) * 0.4);
129
+
130
+ vec3 light = mix(halo, gas, inside) + lit + vec3(0.9, 0.95, 1.0) * star;
131
+ col += 1.0 - exp(-light * 1.25);
132
+ gl_FragColor = vec4(col, 1.0);
133
+ }
134
+ `;
135
+
136
+ /** The pointer's path, drawn into the wake: each point a soft dot. */
137
+ const STROKE = `
138
+ precision highp float;
139
+ attribute vec4 p;
140
+ uniform float uSize;
141
+ varying vec3 vColour;
142
+ varying float vAlpha;
143
+ void main() {
144
+ gl_Position = vec4(p.xy * 2.0 - 1.0, 0.0, 1.0);
145
+ gl_PointSize = uSize;
146
+ vColour = vec3(1.0);
147
+ vAlpha = p.z;
148
+ }
149
+ `;
150
+
151
+ /** A splat of the wake: a gaussian, so the push it gives the gas has no edge. */
152
+ const SPLAT = `
153
+ precision highp float;
154
+ varying vec3 vColour;
155
+ varying float vAlpha;
156
+ void main() {
157
+ vec2 d = gl_PointCoord - 0.5;
158
+ float r = dot(d, d) * 4.0;
159
+ float a = exp(-r * 5.0) * max(1.0 - r, 0.0) * vAlpha;
160
+ gl_FragColor = vec4(vColour * a, a);
161
+ }
162
+ `;
163
+
164
+ /** The defaults: teal, amber and rose. */
165
+ const COLORS = ['#13cbbd', '#ffb238', '#ff4f7e'];
166
+ /** Where the shape sits by default: the right half, so copy can sit on the left. */
167
+ const AREA = { x: 0.46, y: 0.08, width: 0.5, height: 0.84 };
168
+ /** The wake's size, a share of the canvas's: it is soft, so a quarter is plenty. */
169
+ const WAKE_SCALE = 0.25;
170
+
171
+ /**
172
+ * Starts a nebula logo on an element: an opaque canvas inside it, filling it.
173
+ *
174
+ * @param {HTMLElement} el The element (its first canvas is drawn into).
175
+ * @param {NebulaLogoConfig} config The settings.
176
+ * @returns {() => void} Stops it.
177
+ */
178
+ export function nebulaLogo(el, config) {
179
+ let palette = paletteUniform(pickColors(config, COLORS));
180
+ const start = performance.now();
181
+ const stir = config.stir ?? 1;
182
+ const ptr = { x: 0.5, y: 0.5 };
183
+ let active = 0;
184
+ /** Bumped on each resize, so a slow shape drawn for an old size is dropped. */
185
+ let generation = 0;
186
+ /** @type {import('./points.js').Points | null} */
187
+ let strokes = null;
188
+ /** @type {import('./feedback.js').Feedback | null} */
189
+ let wake = null;
190
+ const path = trail(el, { step: 0.012 });
191
+
192
+ const { stage, stop } = createStage(el, {
193
+ fragment: FRAG,
194
+ alpha: false,
195
+ scale: config.scale ?? 0.6,
196
+ setup({ gl, uniform }) {
197
+ strokes = createPoints(gl, STROKE, SPLAT);
198
+ wake = createFeedback(gl, { scale: WAKE_SCALE, precise: true });
199
+ if (!strokes || !wake) return false;
200
+ gl.uniform1i(uniform('uSdf'), 1);
201
+ gl.uniform1i(uniform('uStir'), 2);
202
+ gl.uniform1f(uniform('uGlow'), config.glow ?? 1);
203
+ gl.uniform1f(uniform('uStars'), config.stars ?? 1);
204
+ gl.uniform1f(uniform('uStirAmount'), stir);
205
+ gl.uniform3fv(uniform('uGround'), parseColor(config.background ?? '#05070a'));
206
+ const texture = gl.createTexture();
207
+ gl.activeTexture(gl.TEXTURE1);
208
+ gl.bindTexture(gl.TEXTURE_2D, texture);
209
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
210
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
211
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
212
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
213
+ // Empty until the shape is drawn: all outside.
214
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, 1, 1, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, new Uint8Array([0]));
215
+ gl.uniform1f(uniform('uSpread'), 0.1);
216
+ return () => {
217
+ wake?.dispose();
218
+ gl.deleteTexture(texture);
219
+ };
220
+ },
221
+ resize({ gl, uniform, canvas, program }) {
222
+ wake?.resize(canvas.width, canvas.height);
223
+ const size = wake?.size() ?? { width: 1, height: 1 };
224
+ gl.uniform2f(uniform('uStirTexel'), 1 / size.width, 1 / size.height);
225
+ const width = Math.min(1024, canvas.width);
226
+ const height = Math.max(1, Math.round((width * canvas.height) / canvas.width));
227
+ const mine = ++generation;
228
+ drawShape({ text: config.text, font: config.font, src: config.src, area: config.area ?? AREA, padding: 0.06 }, width, height)
229
+ .then((mask) => {
230
+ if (mine !== generation) return;
231
+ // Reaching far enough out for the halo; blurred a touch, so the rim is smooth.
232
+ const spread = Math.round(height / 7);
233
+ const sdf = blurField(distanceField(mask, spread), width, height, 1);
234
+ gl.activeTexture(gl.TEXTURE1);
235
+ gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);
236
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, width, height, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, sdf);
237
+ gl.useProgram(program);
238
+ gl.uniform1f(uniform('uSpread'), spread / height);
239
+ if (stage?.still) stage.redraw();
240
+ })
241
+ .catch((error) => console.warn('[effects-astro]', error));
242
+ },
243
+ update({ gl, still }, now, dt) {
244
+ if (!strokes || !wake) return;
245
+ const lines = still || stir <= 0 ? [] : path.read(dt);
246
+ const marks = new Float32Array(lines.length * 4);
247
+ lines.forEach((point, i) => marks.set([point.x, point.y, Math.min(1, Math.hypot(point.dx, point.dy) * 0.5) * 0.12, 0], i * 4));
248
+ const { height } = wake.size();
249
+ const dots = strokes;
250
+ wake.draw(still ? 0 : 0.98 ** ((dt || 1 / 60) * 60), () => {
251
+ if (!marks.length) return;
252
+ dots.upload(marks);
253
+ dots.passes(0, () => gl.uniform1f(dots.program.uniform('uSize'), height * 0.24));
254
+ });
255
+ gl.activeTexture(gl.TEXTURE2);
256
+ gl.bindTexture(gl.TEXTURE_2D, wake.texture());
257
+ },
258
+ uniforms({ gl, uniform, ratio, still }, now) {
259
+ const p = !still && stir > 0 && canHover() ? pointerIn(el) : null;
260
+ if (p?.inside) {
261
+ ptr.x += (p.x - ptr.x) * 0.15;
262
+ ptr.y += (p.y - ptr.y) * 0.15;
263
+ }
264
+ active += ((p?.inside ? 1 : 0) - active) * 0.05;
265
+ // A still frame is taken a little way in, where the gas has some shape.
266
+ gl.uniform1f(uniform('uTime'), ((now - start) / 1000 + 40) * (config.speed ?? 1));
267
+ gl.uniform1f(uniform('uRatio'), ratio);
268
+ gl.uniform3f(uniform('uPtr'), ptr.x, ptr.y, active);
269
+ gl.uniform3fv(uniform('uPal'), palette);
270
+ },
271
+ });
272
+ if (!stage) return stop;
273
+
274
+ const unwatch = watchColors(el, (next) => {
275
+ palette = paletteUniform(next.colors);
276
+ if (stage.still) stage.redraw();
277
+ });
278
+ return () => {
279
+ stop();
280
+ unwatch();
281
+ };
282
+ }
@@ -0,0 +1,31 @@
1
+ import type { PaletteName } from './palettes.js';
2
+
3
+ export interface NeonSwarmConfig {
4
+ /** A word (or a character) to gather the swarm into. */
5
+ text?: string;
6
+ /** Its CSS font, without the size. Default: the page's, bold. */
7
+ font?: string;
8
+ /** An image (an SVG logo, a PNG) to gather it into instead. */
9
+ src?: string;
10
+ /** Where the shape sits, each 0–1 from the top left. Default the right half. */
11
+ area?: { x: number; y: number; width: number; height: number };
12
+ /** The palette across the swarm, three colours. Default neon cyan, lime, magenta. */
13
+ colors?: string[];
14
+ /** A shared palette by name (`PALETTES`, any case), when there are no `colors`. */
15
+ palette?: PaletteName | (string & {});
16
+ /** The ground. Default `#030406`. */
17
+ background?: string;
18
+ /** How many particles (half on phones). Default 6000. */
19
+ count?: number;
20
+ /** A particle's glowing core, CSS px. Default 2.4. */
21
+ size?: number;
22
+ /** How long the trails are, 0 (none) to 0.95. Default 0.82. */
23
+ trail?: number;
24
+ /** How far the swarm drifts and breathes round the shape; 0 holds it still. Default 1. */
25
+ flow?: number;
26
+ /** How hard the pointer scatters them; 0 for not at all. Default 1. */
27
+ scatter?: number;
28
+ }
29
+
30
+ /** Starts a neon swarm in `el`'s canvas. Returns a function that stops it. */
31
+ export function neonSwarm(el: HTMLElement, config: NeonSwarmConfig): () => void;
@@ -0,0 +1,258 @@
1
+ /**
2
+ * @module @arraypress/effects-astro/neon-swarm
3
+ *
4
+ * A logo or a word held by a swarm of glowing particles. Each has a home
5
+ * on the shape and a spring to it, and drifts on a curl-noise flow, so the
6
+ * mark shimmers and breathes; now and then two neighbours trade homes
7
+ * and streak past each other. They leave short neon trails and glow where they crowd, in
8
+ * bands of the palette across the mark. The pointer scatters them: they
9
+ * flee it, swirling, and stream back behind it. On arrival they gather
10
+ * from a loose cloud.
11
+ *
12
+ * The flock is stepped on the CPU (src/runtime/swarm.js) and drawn as
13
+ * points into a fading feedback buffer (src/runtime/feedback.js), which
14
+ * the final pass tone-maps over the ground with a little bloom.
15
+ *
16
+ * Opaque: the effect is the whole background of what it fills. Without
17
+ * WebGL it removes its canvas and the element's background shows.
18
+ */
19
+
20
+ import { createStage } from './stage.js';
21
+ import { createPoints } from './points.js';
22
+ import { createFeedback } from './feedback.js';
23
+ import { drawShape, samplePoints, edgePoints } from './shape.js';
24
+ import { createSwarm, disperse, setHomes, settle, stepSwarm } from './swarm.js';
25
+ import { GLSL_PALETTE, paletteUniform } from './glsl.js';
26
+ import { parseColor } from './color.js';
27
+ import { canHover, isMobileGpu } from './device.js';
28
+ import { pointerIn } from './pointer.js';
29
+ import { watchColors } from './mount.js';
30
+ import { pickColors } from './palettes.js';
31
+
32
+ /**
33
+ * @typedef {object} NeonSwarmConfig
34
+ * @property {string} [text] A word to gather the swarm into.
35
+ * @property {string} [font] Its CSS font, without the size (default: the page's, bold).
36
+ * @property {string} [src] An image (an SVG logo) to gather it into instead.
37
+ * @property {{ x: number, y: number, width: number, height: number }} [area]
38
+ * Where the shape sits, each 0–1 from the top left (default: the right half).
39
+ * @property {string[]} [colors] The palette across the swarm, three colours (default neon cyan, lime, magenta).
40
+ * @property {string} [palette] A shared palette by name (PALETTES; any case), when there are no `colors`.
41
+ * @property {string} [background='#030406'] The ground.
42
+ * @property {number} [count=6000] How many particles (half on phones).
43
+ * @property {number} [size=2.4] A particle's glowing core, CSS px.
44
+ * @property {number} [trail=0.82] How long the trails are, 0 (none) to 0.95.
45
+ * @property {number} [flow=1] How far the swarm drifts and breathes round the shape; 0 holds it still.
46
+ * @property {number} [scatter=1] How hard the pointer scatters them; 0 for not at all.
47
+ */
48
+
49
+ /** The final pass: the trails, tone-mapped with a soft bloom, over the ground. */
50
+ const FRAG = `
51
+ precision highp float;
52
+ uniform vec2 uRes;
53
+ uniform float uTime;
54
+ uniform float uRatio;
55
+ uniform sampler2D uTrails;
56
+ uniform vec3 uGround;
57
+ uniform vec3 uCentre;
58
+ ${GLSL_PALETTE}
59
+ void main() {
60
+ vec2 uv = gl_FragCoord.xy / uRes;
61
+ float aspect = uRes.x / uRes.y;
62
+ vec3 light = texture2D(uTrails, uv).rgb;
63
+ // Bloom: two rings of taps round the pixel, so the swarm glows into the dark,
64
+ // turned a different way at every pixel so the taps leave grain, not ghosts.
65
+ vec2 px = uRatio / uRes;
66
+ vec3 bloom = vec3(0.0);
67
+ float spin = fract(sin(dot(gl_FragCoord.xy, vec2(12.9898, 78.233))) * 43758.5453) * 6.2832;
68
+ for (int i = 0; i < 6; i++) {
69
+ float a = float(i) * 1.0472 + spin;
70
+ vec2 o = vec2(cos(a), sin(a)) * px;
71
+ bloom += texture2D(uTrails, uv + o * 7.0).rgb + texture2D(uTrails, uv - o.yx * 18.0).rgb * 0.7;
72
+ }
73
+ bloom /= 6.0;
74
+ // A faint wash of the palette behind the shape.
75
+ vec2 d = (uv - uCentre.xy) * vec2(aspect, 1.0);
76
+ vec3 col = uGround + pal(uTime * 0.02 + 0.3) * exp(-dot(d, d) / (uCentre.z * uCentre.z)) * 0.045;
77
+ col += 1.0 - exp(-(light * 1.5 + bloom * 0.7));
78
+ gl_FragColor = vec4(col, 1.0);
79
+ }
80
+ `;
81
+
82
+ /** Each particle: where it is (in heights, y up), a seed, its speed. */
83
+ const VERTEX = `
84
+ precision highp float;
85
+ attribute vec4 p;
86
+ uniform vec2 uRes;
87
+ uniform float uTime;
88
+ uniform float uRatio;
89
+ uniform vec2 uShift;
90
+ uniform float uSize;
91
+ uniform float uGain;
92
+ varying vec3 vColour;
93
+ varying float vAlpha;
94
+ ${GLSL_PALETTE}
95
+ void main() {
96
+ float aspect = uRes.x / uRes.y;
97
+ gl_Position = vec4(p.x / aspect * 2.0 - 1.0 + uShift.x, p.y * 2.0 - 1.0, 0.0, 1.0);
98
+ float s = p.z;
99
+ // Fast particles run hot: brighter, and whiter.
100
+ float hot = clamp(p.w * 1.6, 0.0, 1.0);
101
+ // Each particle is one of the palette's colours, never a blend (neon does not
102
+ // come in muddy in-betweens): which one runs in bands across the mark, drifting
103
+ // slowly, with the seed dithering the borders between them.
104
+ float band = (p.x * 0.5 + p.y * 0.36) * 1.6 + uTime * 0.02;
105
+ vec3 c = pal(floor(band * 3.0 + fract(s * 5.31) * 0.9) / 3.0);
106
+ vColour = mix(c, vec3(1.0), hot * 0.5);
107
+ float twinkle = 0.65 + 0.35 * sin(uTime * (1.5 + s * 3.0) + s * 50.0);
108
+ vAlpha = uGain * twinkle * (1.2 + hot * 1.8);
109
+ // The sprite is three times the core, for its halo.
110
+ gl_PointSize = uSize * uRatio * 3.0 * (0.7 + 0.6 * fract(s * 7.13));
111
+ }
112
+ `;
113
+
114
+ /** A neon sprite: a hot core and a faint halo round it. */
115
+ const SPRITE = `
116
+ precision highp float;
117
+ varying vec3 vColour;
118
+ varying float vAlpha;
119
+ void main() {
120
+ vec2 d = gl_PointCoord - 0.5;
121
+ float r = dot(d, d) * 4.0;
122
+ float a = (exp(-r * 16.0) + 0.16 * exp(-r * 4.0)) * (1.0 - r);
123
+ gl_FragColor = vec4(vColour * max(a, 0.0) * vAlpha, 0.0);
124
+ }
125
+ `;
126
+
127
+ /** The defaults: neon cyan, lime and magenta. */
128
+ const COLORS = ['#00e5ff', '#b4ff1f', '#ff2bd1'];
129
+ /** Where the shape sits by default: the right half, so copy can sit on the left. */
130
+ const AREA = { x: 0.46, y: 0.08, width: 0.5, height: 0.84 };
131
+ /** How many times each particle is drawn along its path a frame. */
132
+ const STAMPS = 3;
133
+ /** The share of particles homed on the edge rather than the fill: the outline reads bright and crisp. */
134
+ const EDGE = 0.3;
135
+
136
+ /**
137
+ * Starts a neon swarm on an element: an opaque canvas inside it, filling it.
138
+ *
139
+ * @param {HTMLElement} el The element (its first canvas is drawn into).
140
+ * @param {NeonSwarmConfig} config The settings.
141
+ * @returns {() => void} Stops it.
142
+ */
143
+ export function neonSwarm(el, config) {
144
+ let palette = paletteUniform(pickColors(config, COLORS));
145
+ const area = config.area ?? AREA;
146
+ const start = performance.now();
147
+ const count = Math.round((config.count ?? 6000) * (isMobileGpu() ? 0.5 : 1));
148
+ const swarm = createSwarm(count);
149
+ const data = new Float32Array(count * STAMPS * 4);
150
+ for (let i = 0; i < count * STAMPS; i++) data[i * 4 + 2] = (Math.floor(i / STAMPS) * 0.618034) % 1;
151
+ const trail = Math.min(0.95, Math.max(0, config.trail ?? 0.82));
152
+ const flow = config.flow ?? 1;
153
+ const scatter = config.scatter ?? 1;
154
+ let homed = false;
155
+ /** Bumped on each resize, so a slow shape drawn for an old size is dropped. */
156
+ let generation = 0;
157
+ /** @type {import('./points.js').Points | null} */
158
+ let points = null;
159
+ /** @type {import('./feedback.js').Feedback | null} */
160
+ let trails = null;
161
+
162
+ const { stage, stop } = createStage(el, {
163
+ fragment: FRAG,
164
+ alpha: false,
165
+ setup({ gl, uniform }) {
166
+ points = createPoints(gl, VERTEX, SPRITE);
167
+ trails = createFeedback(gl, { precise: true });
168
+ if (!points || !trails) return false;
169
+ gl.uniform1i(uniform('uTrails'), 0);
170
+ gl.uniform3fv(uniform('uGround'), parseColor(config.background ?? '#030406'));
171
+ return () => trails?.dispose();
172
+ },
173
+ resize({ canvas, still }) {
174
+ trails?.resize(canvas.width, canvas.height);
175
+ const aspect = canvas.width / canvas.height;
176
+ const mine = ++generation;
177
+ const width = Math.min(1024, canvas.width);
178
+ const height = Math.max(1, Math.round((width * canvas.height) / canvas.width));
179
+ drawShape({ text: config.text, font: config.font, src: config.src, area, padding: 0.06 }, width, height)
180
+ .then((mask) => {
181
+ if (mine !== generation) return;
182
+ const edge = Math.round(count * EDGE);
183
+ const homes = new Float32Array(count * 2);
184
+ homes.set(samplePoints(mask, count - edge));
185
+ homes.set(edgePoints(mask, edge), (count - edge) * 2);
186
+ // In heights of the canvas, so the flow's swirls are round.
187
+ for (let i = 0; i < count * 2; i += 2) homes[i] *= aspect;
188
+ setHomes(swarm, homes);
189
+ if (still) settle(swarm);
190
+ else if (!homed) disperse(swarm, (area.x + area.width / 2) * aspect, 1 - area.y - area.height / 2, 0.45);
191
+ homed = true;
192
+ if (still) stage?.redraw();
193
+ })
194
+ .catch((error) => console.warn('[effects-astro]', error));
195
+ },
196
+ update({ gl, canvas, ratio, still }, now, dt) {
197
+ if (!points || !trails) return;
198
+ const t = (now - start) / 1000;
199
+ const aspect = canvas.width / canvas.height;
200
+ if (homed && !still) {
201
+ const p = scatter > 0 && canHover() ? pointerIn(el) : null;
202
+ stepSwarm(swarm, dt, {
203
+ flow: 0.5 * flow,
204
+ wander: 0.05 * Math.min(1, flow),
205
+ pointer: p?.inside ? { x: p.x * aspect, y: p.y, radius: 0.15, force: 70 * scatter } : null,
206
+ });
207
+ }
208
+ // Each particle stamped along the way it came this frame, so a fast one draws a line, not dots.
209
+ const step = (dt || 1 / 60) / STAMPS;
210
+ for (let i = 0; i < count; i++) {
211
+ const vx = swarm.vel[i * 2];
212
+ const vy = swarm.vel[i * 2 + 1];
213
+ const speed = Math.hypot(vx, vy);
214
+ for (let k = 0; k < STAMPS; k++) {
215
+ const at = (i * STAMPS + k) * 4;
216
+ data[at] = swarm.pos[i * 2] - vx * step * k;
217
+ data[at + 1] = swarm.pos[i * 2 + 1] - vy * step * k;
218
+ data[at + 3] = speed;
219
+ }
220
+ }
221
+ if (homed) points.upload(data);
222
+ // The fade a frame, kept the same whatever the frame rate; a still frame has no trail.
223
+ const fade = still ? 0 : trail ** ((dt || 1 / 60) * 60);
224
+ const u = points.program.uniform;
225
+ const sprites = points;
226
+ trails.draw(fade, () => {
227
+ if (!homed) return;
228
+ sprites.passes(0, () => {
229
+ gl.uniform2f(u('uRes'), canvas.width, canvas.height);
230
+ gl.uniform1f(u('uTime'), t);
231
+ gl.uniform1f(u('uRatio'), ratio);
232
+ gl.uniform1f(u('uSize'), config.size ?? 2.4);
233
+ gl.uniform1f(u('uGain'), (1 - fade) / STAMPS);
234
+ gl.uniform3fv(u('uPal'), palette);
235
+ });
236
+ });
237
+ gl.activeTexture(gl.TEXTURE0);
238
+ gl.bindTexture(gl.TEXTURE_2D, trails.texture());
239
+ },
240
+ uniforms({ gl, uniform, canvas, ratio }, now) {
241
+ const aspect = canvas.width / canvas.height;
242
+ gl.uniform1f(uniform('uTime'), (now - start) / 1000);
243
+ gl.uniform1f(uniform('uRatio'), ratio);
244
+ gl.uniform3f(uniform('uCentre'), area.x + area.width / 2, 1 - area.y - area.height / 2, (Math.min(area.width * aspect, area.height) * 0.6));
245
+ gl.uniform3fv(uniform('uPal'), palette);
246
+ },
247
+ });
248
+ if (!stage) return stop;
249
+
250
+ const unwatch = watchColors(el, (next) => {
251
+ palette = paletteUniform(next.colors);
252
+ if (stage.still) stage.redraw();
253
+ });
254
+ return () => {
255
+ stop();
256
+ unwatch();
257
+ };
258
+ }
@@ -0,0 +1,54 @@
1
+ /** A time of day for the ocean. */
2
+ export type OceanTime = 'dawn' | 'noon' | 'sunset' | 'night';
3
+
4
+ /** A time of day's sun, sky and water. Colours are CSS hex. */
5
+ export interface OceanLook {
6
+ time: OceanTime;
7
+ /** Where the sun sits across the frame, 0–1 from the left (beyond it, off to the side). */
8
+ x: number;
9
+ /** Its height above the horizon, degrees. */
10
+ elevation: number;
11
+ /** Its apparent radius, radians. */
12
+ size: number;
13
+ /** The colour of its light on the water. */
14
+ light: string;
15
+ /** How strong that light is. */
16
+ power: number;
17
+ /** The sky overhead. */
18
+ zenith: string;
19
+ /** The sky along the horizon, and the haze. */
20
+ horizon: string;
21
+ /** The glow round the sun. */
22
+ glow: string;
23
+ /** The deep water's own colour. */
24
+ deep: string;
25
+ /** The colour light takes through a thin crest. */
26
+ scatter: string;
27
+ /** The clouds' shaded side. */
28
+ cloud: string;
29
+ /** How far, in metres, the air takes to hide the sea. */
30
+ haze: number;
31
+ /** The camera's exposure. */
32
+ exposure: number;
33
+ /** How bright the stars are, 0 for none. */
34
+ stars: number;
35
+ }
36
+
37
+ /** The times of day. */
38
+ export const OCEAN_TIMES: Readonly<Record<OceanTime, OceanLook>>;
39
+
40
+ /** The default time of day: `sunset`. */
41
+ export const OCEAN_TIME: OceanTime;
42
+
43
+ /** Moves a colour's hue and chroma towards a tint's in Oklab (`amount` 0–1, default 0.6), keeping its lightness. Throws a TypeError for a colour that is not hex. */
44
+ export function tintColor(color: string, tint: string, amount?: number): string;
45
+
46
+ /**
47
+ * A time of day (default `sunset`; an unknown one is warned about),
48
+ * tinted by `colors` or `palette`: the first tints the sky, the second the
49
+ * water, the third the light, each keeping its lightness.
50
+ */
51
+ export function oceanLook(config: { time?: string; colors?: string[]; palette?: string }): OceanLook;
52
+
53
+ /** The scene as a CSS `background` for a browser without WebGL; `horizon` 0–1 up the frame (default 0.3). */
54
+ export function oceanBackdrop(look: OceanLook, horizon?: number): string;