Merge branch 'shaders'

63b9ceb · gmorell · 2026-12-03 22:31

41 files +2563 -71

Files changed

modified assets/css/app.css
+92 −0
@@ -362,3 +362,95 @@
362 362
363 363 /* Make LiveView wrapper divs transparent for layout */
364 364 [data-phx-session], [data-phx-teleported-src] { display: contents }
365 +
366 +/* ── Shader background ──────────────────────────────────────────────────────
367 + assets/js/shader_background.js. The canvas sits behind everything; while
368 + a pattern is on, <html data-shader> clears the page's own ground so it
369 + shows through, and the cards and panels become sea glass: the theme's
370 + base-100 at 72% over a 10px blur (neiam-org's .neiam-glass, recourse's
371 + focus panel), so the pattern reads as soft colour behind them rather than
372 + detail under the text. */
373 +#site-shader {
374 + position: fixed;
375 + inset: 0;
376 + width: 100vw;
377 + height: 100vh;
378 + z-index: -1;
379 + pointer-events: none;
380 +}
381 +html[data-shader] body {
382 + background-color: transparent;
383 +}
384 +/* The nav bar is already translucent with a blur of its own; a touch
385 + thicker over a pattern. */
386 +html[data-shader] body > header.navbar {
387 + background-color: color-mix(in oklab, var(--color-base-100) 82%, transparent);
388 +}
389 +/* Vigil's cards and panels are bordered rounded boxes, some filled and
390 + some not. The outermost of each gets the glass; ones inside keep their
391 + own surfaces (opaque fills read fine on glass). Positioned ones are left
392 + alone: tooltips and dropdowns stay opaque, and the sticky filter bar
393 + carries its own blur.
394 + The glass is on a ::before layer, not the box: a backdrop-filter makes
395 + its element the containing block for position:fixed descendants, which
396 + would pin a modal or overlay inside the card. */
397 +html[data-shader] main .rounded-box.border:not(.absolute, .fixed, .sticky, .dropdown-content, .menu, .rounded-box.border .rounded-box.border, .shader-glass .rounded-box.border) {
398 + position: relative;
399 + isolation: isolate;
400 + background-color: transparent;
401 +}
402 +html[data-shader] main .rounded-box.border:not(.absolute, .fixed, .sticky, .dropdown-content, .menu, .rounded-box.border .rounded-box.border, .shader-glass .rounded-box.border)::before {
403 + content: "";
404 + position: absolute;
405 + inset: 0;
406 + z-index: -1;
407 + border-radius: inherit;
408 + pointer-events: none;
409 + background-color: color-mix(in oklab, var(--color-base-100) 72%, transparent);
410 + -webkit-backdrop-filter: blur(10px) saturate(1.1);
411 + backdrop-filter: blur(10px) saturate(1.1);
412 +}
413 +/* Pages that are a form or a few lines on the bare ground (log in,
414 + register, the signed-out front page, an invite) are marked
415 + .shader-glass: over a pattern they become one glass panel, as
416 + recourse's focus pages do. Without one they look as they always have. */
417 +html[data-shader] .shader-glass {
418 + position: relative;
419 + isolation: isolate;
420 + padding: 1.5rem;
421 + border-radius: var(--radius-box);
422 + box-shadow: 0 1.5rem 4rem rgb(0 0 0 / 0.25);
423 +}
424 +@media (min-width: 640px) {
425 + html[data-shader] .shader-glass {
426 + padding: 2rem;
427 + }
428 +}
429 +html[data-shader] .shader-glass::before {
430 + content: "";
431 + position: absolute;
432 + inset: 0;
433 + z-index: -1;
434 + border-radius: inherit;
435 + pointer-events: none;
436 + background-color: color-mix(in oklab, var(--color-base-100) 72%, transparent);
437 + -webkit-backdrop-filter: blur(10px) saturate(1.1);
438 + backdrop-filter: blur(10px) saturate(1.1);
439 +}
440 +/* What's left on the bare ground (page titles, a project's tabs) gets a
441 + soft halo of the ground's colour, so a pattern passing under it doesn't
442 + take the letters with it. Nothing on a surface of its own needs one. */
443 +html[data-shader] main {
444 + text-shadow: 0 0 0.5rem var(--color-base-100), 0 0 0.15rem var(--color-base-100);
445 +}
446 +html[data-shader] main :is(.rounded-box, .shader-glass, .btn:not(.btn-ghost), .badge, .alert, .input, .select, .textarea, .kbd, .menu, .dropdown-content, table) {
447 + text-shadow: none;
448 +}
449 +/* /shaders: the card in use. */
450 +[data-shader-card][data-active] {
451 + outline: 3px solid var(--color-primary);
452 + outline-offset: 3px;
453 +}
454 +.shader-unsupported canvas {
455 + visibility: hidden;
456 +}
modified assets/js/app.js
+2 −1
@@ -24,12 +24,13 @@ import {Socket} from "phoenix"
24 24 import {LiveSocket} from "phoenix_live_view"
25 25 import {hooks as colocatedHooks} from "phoenix-colocated/vigil"
26 26 import topbar from "../vendor/topbar"
27 +import {ShaderPreview, ShaderControls} from "./shader_background"
27 28
28 29 const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content")
29 30 const liveSocket = new LiveSocket("/live", Socket, {
30 31 longPollFallbackMs: 2500,
31 32 params: {_csrf_token: csrfToken},
32 − hooks: {...colocatedHooks},
33 + hooks: {...colocatedHooks, ShaderPreview, ShaderControls},
33 34 })
34 35
35 36 // JS.dispatch("phx:copy", to: "#some-input") copies that input's value (or
added assets/js/shader_background.js
+129 −0
@@ -0,0 +1,129 @@
1 +// The site-wide shader background, and the hooks behind /shaders.
2 +//
3 +// The choice lives in localStorage under "shader", like the theme: a
4 +// pattern ("off" for none) and the effect settings, which the /shaders
5 +// previews share. Until a visitor chooses, the background is eyes, with
6 +// neiam-org's eye defaults. While a pattern is on, a fixed canvas sits
7 +// behind the page and <html data-shader> makes the page clear over it
8 +// and its cards glass (see app.css). The colours follow the site theme.
9 +
10 +import { createField, DEFAULTS } from "./shader_field"
11 +
12 +const KEY = "shader"
13 +const EVENT = "vigil:shader-settings"
14 +
15 +const DEFAULT_PATTERN = "eyes"
16 +let current = load()
17 +let background = null
18 +
19 +function load() {
20 + try {
21 + return { ...DEFAULTS, pattern: DEFAULT_PATTERN, ...JSON.parse(localStorage.getItem(KEY) || "{}") }
22 + } catch {
23 + return { ...DEFAULTS, pattern: DEFAULT_PATTERN }
24 + }
25 +}
26 +
27 +export const shaderSettings = () => current
28 +
29 +function apply() {
30 + const on = current.pattern && current.pattern !== "off"
31 + if (on && !background) {
32 + const canvas = document.createElement("canvas")
33 + canvas.id = "site-shader"
34 + canvas.setAttribute("aria-hidden", "true")
35 + document.body.prepend(canvas)
36 + let field = null
37 + try {
38 + field = createField(canvas, () => current, { fps: 30, maxScale: 1 })
39 + } catch (e) {
40 + console.error("shader background:", e)
41 + }
42 + if (!field) {
43 + canvas.remove()
44 + return
45 + }
46 + background = { canvas, field }
47 + } else if (!on && background) {
48 + background.field.destroy()
49 + background.canvas.remove()
50 + background = null
51 + }
52 + document.documentElement.toggleAttribute("data-shader", !!background)
53 +}
54 +
55 +// Merge `patch` into the settings, save, and apply. Global, like
56 +// setTheme, so plain onclick handlers can use it.
57 +window.setShader = function (patch) {
58 + current = { ...current, ...patch }
59 + try {
60 + localStorage.setItem(KEY, JSON.stringify(current))
61 + } catch {}
62 + apply()
63 + window.dispatchEvent(new CustomEvent(EVENT, { detail: current }))
64 +}
65 +
66 +document.addEventListener("DOMContentLoaded", apply)
67 +
68 +// <canvas phx-hook="ShaderPreview" data-pattern="bokeh">: that pattern,
69 +// with the shared effect settings, in the site theme.
70 +export const ShaderPreview = {
71 + mounted() {
72 + try {
73 + this.field = createField(this.el, () => ({ ...current, pattern: this.el.dataset.pattern }))
74 + } catch (e) {
75 + console.error("shader preview:", e)
76 + }
77 + if (!this.field) this.el.closest("[data-shader-card]")?.classList.add("shader-unsupported")
78 + },
79 + destroyed() {
80 + this.field && this.field.destroy()
81 + },
82 +}
83 +
84 +// The /shaders controls. Inside the hook's element:
85 +// [data-use="pattern"] buttons that set the background
86 +// input[type=checkbox][data-setting="name"] boolean settings
87 +// input[type=range][data-setting="name"] numeric settings
88 +// [data-shader-card="pattern"] cards, given data-active when in use
89 +// [data-shader-current] filled with the current pattern's name
90 +// [data-shader-when="pattern"] shown only while that pattern is in use
91 +export const ShaderControls = {
92 + mounted() {
93 + this.el.addEventListener("click", e => {
94 + const use = e.target.closest("[data-use]")
95 + if (use) window.setShader({ pattern: use.dataset.use })
96 + })
97 + this.el.addEventListener("input", e => {
98 + const name = e.target.dataset.setting
99 + if (!name) return
100 + const value = e.target.type === "checkbox" ? e.target.checked : Number(e.target.value)
101 + window.setShader({ [name]: value })
102 + })
103 + this.sync = () => {
104 + for (const input of this.el.querySelectorAll("[data-setting]")) {
105 + const v = current[input.dataset.setting]
106 + if (input.type === "checkbox") input.checked = !!v
107 + else input.value = v
108 + }
109 + for (const card of this.el.querySelectorAll("[data-shader-card]")) {
110 + card.toggleAttribute("data-active", card.dataset.shaderCard === current.pattern)
111 + }
112 + for (const out of this.el.querySelectorAll("[data-shader-current]")) {
113 + const card = this.el.querySelector(`[data-shader-card="${current.pattern}"]`)
114 + out.textContent = card ? card.dataset.name : "Off"
115 + }
116 + for (const el of this.el.querySelectorAll("[data-shader-when]")) {
117 + el.hidden = el.dataset.shaderWhen !== current.pattern
118 + }
119 + for (const out of this.el.querySelectorAll("[data-shader-value]")) {
120 + out.textContent = current[out.dataset.shaderValue]
121 + }
122 + }
123 + window.addEventListener(EVENT, this.sync)
124 + this.sync()
125 + },
126 + destroyed() {
127 + window.removeEventListener(EVENT, this.sync)
128 + },
129 +}
added assets/js/shader_balls.js
+191 −0
@@ -0,0 +1,191 @@
1 +// The moving parts of the Bubbles and Absorbing spheres patterns. Both
2 +// keep their discs in units of the canvas's shorter side (as the
3 +// shaders do), step them with the field's clock, and hand them over as
4 +// vec4 uniforms ball0 to ball47 (x, y, radius, and a fourth value of
5 +// their own; unused ones zero): separate uniforms rather than an array,
6 +// because Qt's ShaderEffect, for neiam-device, can't pass arrays.
7 +
8 +export const MAX_BALLS = 48
9 +
10 +const rand = (lo, hi) => lo + Math.random() * (hi - lo)
11 +const TAU = 2 * Math.PI
12 +
13 +// Off the walls: back inside, heading away.
14 +function walls(b, [w, h]) {
15 + if (b.x - b.r < 0) (b.x = b.r), (b.vx = Math.abs(b.vx))
16 + if (b.x + b.r > w) (b.x = w - b.r), (b.vx = -Math.abs(b.vx))
17 + if (b.y - b.r < 0) (b.y = b.r), (b.vy = Math.abs(b.vy))
18 + if (b.y + b.r > h) (b.y = h - b.r), (b.vy = -Math.abs(b.vy))
19 +}
20 +
21 +function launch(extent, r, speed) {
22 + const a = Math.random() * TAU
23 + return {
24 + x: rand(r, Math.max(r, extent[0] - r)),
25 + y: rand(r, Math.max(r, extent[1] - r)),
26 + r,
27 + vx: speed * Math.cos(a),
28 + vy: speed * Math.sin(a),
29 + }
30 +}
31 +
32 +function pack(list, extra) {
33 + const out = {}
34 + for (let i = 0; i < MAX_BALLS; i++) {
35 + const b = list[i]
36 + out[`ball${i}`] = b ? [b.x, b.y, b.r, extra(b)] : [0, 0, 0, 0]
37 + }
38 + return out
39 +}
40 +
41 +// Soap bubbles drifting about, bouncing off the walls and each other
42 +// (elastic, with mass by area). The fourth value is the phase their
43 +// film's colours swirl through.
44 +export class Bubbles {
45 + constructor() {
46 + this.list = []
47 + }
48 +
49 + step(dt, extent, n) {
50 + n = Math.min(MAX_BALLS, Math.max(1, Math.round(n)))
51 + while (this.list.length > n) this.list.pop()
52 + while (this.list.length < n) {
53 + const b = launch(extent, rand(0.035, 0.1), rand(0.009, 0.024))
54 + b.phase = Math.random()
55 + b.swirl = rand(0.02, 0.06) * (Math.random() < 0.5 ? -1 : 1)
56 + this.list.push(b)
57 + }
58 +
59 + for (const b of this.list) {
60 + b.x += b.vx * dt
61 + b.y += b.vy * dt
62 + b.phase = (b.phase + b.swirl * dt + 1) % 1
63 + walls(b, extent)
64 + }
65 + for (let i = 0; i < this.list.length; i++) {
66 + for (let j = i + 1; j < this.list.length; j++) {
67 + const a = this.list[i]
68 + const b = this.list[j]
69 + const dx = b.x - a.x
70 + const dy = b.y - a.y
71 + const dist = Math.hypot(dx, dy) || 1e-6
72 + const overlap = a.r + b.r - dist
73 + if (overlap <= 0) continue
74 + const nx = dx / dist
75 + const ny = dy / dist
76 + const ma = a.r * a.r
77 + const mb = b.r * b.r
78 + // Apart, the lighter one moving further.
79 + a.x -= (nx * overlap * mb) / (ma + mb)
80 + a.y -= (ny * overlap * mb) / (ma + mb)
81 + b.x += (nx * overlap * ma) / (ma + mb)
82 + b.y += (ny * overlap * ma) / (ma + mb)
83 + // And bounce, if they're closing.
84 + const closing = (a.vx - b.vx) * nx + (a.vy - b.vy) * ny
85 + if (closing > 0) {
86 + const ja = (2 * mb * closing) / (ma + mb)
87 + const jb = (2 * ma * closing) / (ma + mb)
88 + a.vx -= ja * nx
89 + a.vy -= ja * ny
90 + b.vx += jb * nx
91 + b.vy += jb * ny
92 + }
93 + }
94 + }
95 + }
96 +
97 + pack() {
98 + return { ...pack(this.list, b => b.phase), count: this.list.length }
99 + }
100 +}
101 +
102 +// Spheres launched in every direction at their own speeds. They bounce
103 +// off the walls, but where two meet the larger eats into the smaller:
104 +// the area the smaller loses the larger gains, with the momentum that
105 +// came with it, the two just touching, until the smaller is gone. With
106 +// three left, they hold a moment, fade, and a new set is launched.
107 +// The fourth value picks each sphere's colour.
108 +export class Absorbers {
109 + constructor() {
110 + this.list = []
111 + this.state = "in"
112 + this.fade = 0
113 + this.timer = 0
114 + this.n = 0
115 + }
116 +
117 + launchAll(extent, n) {
118 + this.n = n
119 + this.list = Array.from({ length: n }, () => {
120 + const b = launch(extent, rand(0.012, 0.045), rand(0.009, 0.03))
121 + b.shade = Math.random()
122 + return b
123 + })
124 + }
125 +
126 + step(dt, extent, n) {
127 + n = Math.min(MAX_BALLS, Math.max(4, Math.round(n)))
128 + if (!this.list.length || (n !== this.n && this.state !== "out")) {
129 + this.launchAll(extent, n)
130 + this.state = "in"
131 + }
132 +
133 + for (const b of this.list) {
134 + b.x += b.vx * dt
135 + b.y += b.vy * dt
136 + walls(b, extent)
137 + }
138 + this.absorb()
139 +
140 + if (this.state === "in") {
141 + this.fade = Math.min(1, this.fade + dt / 1.5)
142 + if (this.fade >= 1) this.state = "live"
143 + } else if (this.state === "live" && this.list.length <= 3) {
144 + this.state = "hold"
145 + this.timer = 4
146 + } else if (this.state === "hold" && (this.timer -= dt) <= 0) {
147 + this.state = "out"
148 + } else if (this.state === "out") {
149 + this.fade = Math.max(0, this.fade - dt / 2)
150 + if (this.fade <= 0) {
151 + this.launchAll(extent, n)
152 + this.state = "in"
153 + }
154 + }
155 + }
156 +
157 + absorb() {
158 + const list = this.list
159 + for (let i = 0; i < list.length; i++) {
160 + for (let j = i + 1; j < list.length; j++) {
161 + const a = list[i]
162 + const b = list[j]
163 + if (a.gone || b.gone) continue
164 + const dist = Math.hypot(b.x - a.x, b.y - a.y)
165 + if (dist >= a.r + b.r) continue
166 + const [big, small] = a.r >= b.r ? [a, b] : [b, a]
167 + const area = big.r * big.r + small.r * small.r
168 + // The radii that keep the area and just touch: big + small = dist.
169 + let grown = (dist + Math.sqrt(Math.max(0, 2 * area - dist * dist))) / 2
170 + let left = dist - grown
171 + if (left < 0.003 || grown >= dist) {
172 + grown = Math.sqrt(area)
173 + left = 0
174 + small.gone = true
175 + }
176 + const before = big.r * big.r
177 + const after = grown * grown
178 + const taken = after - before
179 + big.vx = (before * big.vx + taken * small.vx) / after
180 + big.vy = (before * big.vy + taken * small.vy) / after
181 + big.r = grown
182 + small.r = left
183 + }
184 + }
185 + this.list = list.filter(b => !b.gone)
186 + }
187 +
188 + pack() {
189 + return { ...pack(this.list, b => b.shade), count: this.list.length, fade: this.fade }
190 + }
191 +}
added assets/js/shader_eyes.js
+241 −0
@@ -0,0 +1,241 @@
1 +// The moving parts of the Eyes pattern. Each eye lives a cycle: it
2 +// picks a free spot and a size, appears there as a line (its closed
3 +// lids' seam), opens, stays open 10 to 60 s blinking and looking about,
4 +// slowly closes back to a line, and the line fades. Then it starts over
5 +// somewhere else. While open it sometimes looks at the pointer, in
6 +// spells, rather than always.
7 +//
8 +// Times are in the field's clock (seconds times the speed setting),
9 +// positions in units of the canvas's shorter side, y down, as the
10 +// shader has them. They are handed over as separate vec4 uniforms (Qt's
11 +// ShaderEffect can't pass arrays), eye0 to eye11 and look0 to look11:
12 +// eyeN: x, y, radius (half the eye's width), openness 0-1 (blinks included)
13 +// lookN: gaze x, gaze y (-1 to 1, the iris's full travel), shade 0-1, fade 0-1
14 +// Unused ones are zero.
15 +
16 +export const MAX_EYES = 24
17 +
18 +const rand = (lo, hi) => lo + Math.random() * (hi - lo)
19 +const TAU = 2 * Math.PI
20 +const smooth = t => t * t * (3 - 2 * t)
21 +
22 +// The life cycle, in order, with how long each part takes (seconds).
23 +export const TIMES = {
24 + wait: [0.5, 3], // unseen, before taking a spot
25 + appear: 0.8, // the line fading in
26 + opening: 1.6,
27 + open: [10, 60],
28 + closing: 3.2, // slowly
29 + vanish: 1.5, // the line fading out
30 + blink: 0.15,
31 + blinkEvery: [2, 9],
32 + glance: [0.6, 3.5], // between saccades
33 + attention: [1.5, 6], // a spell of looking at the pointer
34 +}
35 +// The chance, at each saccade, of a spell of looking at the pointer.
36 +export const ATTENTION = 0.3
37 +
38 +// The radius range for n eyes: the largest `ratio` times the smallest,
39 +// both smaller the more eyes there are, so they have room.
40 +export function sizes(n, ratio) {
41 + const big = Math.min(0.3, 0.55 / Math.sqrt(Math.max(1, n)))
42 + return [big / Math.max(1, ratio), big]
43 +}
44 +
45 +// The extent an eye takes up around its centre, to keep eyes apart.
46 +const reach = e => e.r * 1.15
47 +
48 +function lookAround() {
49 + if (Math.random() < 0.25) return [0, 0]
50 + const a = Math.random() * TAU
51 + const m = 0.35 + 0.6 * Math.sqrt(Math.random())
52 + return [m * Math.cos(a), m * Math.sin(a)]
53 +}
54 +
55 +export class Eyes {
56 + constructor() {
57 + this.list = []
58 + this.settled = null
59 + }
60 +
61 + // A fresh eye, unseen, waiting `delay` before it takes a spot.
62 + make(delay) {
63 + return {
64 + state: "wait",
65 + timer: delay ?? rand(...TIMES.wait),
66 + x: 0,
67 + y: 0,
68 + r: 0,
69 + open: 0,
70 + fade: 0,
71 + gaze: [0, 0],
72 + target: [0, 0],
73 + shade: Math.random(),
74 + blink: -1,
75 + nextBlink: rand(...TIMES.blinkEvery),
76 + nextGlance: rand(...TIMES.glance),
77 + attending: 0,
78 + }
79 + }
80 +
81 + // Somewhere free for an eye of a random size, or false if none was
82 + // found (it waits a moment and tries again).
83 + place(e, extent, n, ratio) {
84 + const [lo, hi] = sizes(n, ratio)
85 + for (let tries = 0; tries < 40; tries++) {
86 + // Log-uniform, so small and large are equally common by ratio.
87 + const r = lo * Math.pow(hi / lo, Math.random())
88 + const mx = r * 1.15
89 + const my = r * 0.75
90 + const x = rand(mx, Math.max(mx, extent[0] - mx))
91 + const y = rand(my, Math.max(my, extent[1] - my))
92 + const clear = this.list.every(
93 + o => o === e || o.state === "wait" || Math.hypot(o.x - x, o.y - y) > (reach(o) + r * 1.15) * 1.1,
94 + )
95 + if (clear) {
96 + Object.assign(e, { x, y, r })
97 + return true
98 + }
99 + }
100 + return false
101 + }
102 +
103 + // `pointer`: { x, y, active } in shader units, or null.
104 + step(dt, extent, n, ratio, pointer = null) {
105 + n = Math.min(MAX_EYES, Math.max(1, Math.round(n)))
106 + this.settled = null
107 + // The first ones staggered, so they don't all open together.
108 + while (this.list.length < n) this.list.push(this.make(this.list.length ? rand(0, 4) : 0.3))
109 + // Too many: the extra ones close now, and are dropped once gone.
110 + for (let i = n; i < this.list.length; i++) {
111 + const e = this.list[i]
112 + if (e.state === "open") (e.state = "closing"), (e.timer = TIMES.closing)
113 + else if (e.state === "wait") e.drop = true
114 + }
115 +
116 + const now = pointer && pointer.active ? pointer : null
117 + const fresh = now && !this.pointerWas
118 + this.pointerWas = !!now
119 +
120 + for (const e of this.list) this.live(e, dt, extent, n, ratio, now, fresh)
121 + this.list = this.list.filter(e => !e.drop)
122 + }
123 +
124 + live(e, dt, extent, n, ratio, pointer, fresh) {
125 + e.timer -= dt
126 + switch (e.state) {
127 + case "wait":
128 + if (e.timer > 0) break
129 + if (this.list.indexOf(e) >= n) {
130 + e.drop = true
131 + break
132 + }
133 + if (!this.place(e, extent, n, ratio)) {
134 + e.timer = 0.5
135 + break
136 + }
137 + Object.assign(e, { state: "appear", timer: TIMES.appear, open: 0, fade: 0, shade: Math.random() })
138 + e.gaze = [0, 0]
139 + e.target = [0, 0]
140 + break
141 + case "appear":
142 + e.fade = smooth(Math.min(1, 1 - e.timer / TIMES.appear))
143 + if (e.timer <= 0) (e.state = "opening"), (e.timer = TIMES.opening), (e.fade = 1)
144 + break
145 + case "opening":
146 + e.open = smooth(Math.min(1, 1 - e.timer / TIMES.opening))
147 + if (e.timer <= 0) (e.state = "open"), (e.timer = rand(...TIMES.open)), (e.open = 1)
148 + break
149 + case "open":
150 + if (e.timer <= 0) (e.state = "closing"), (e.timer = TIMES.closing)
151 + break
152 + case "closing":
153 + e.open = smooth(Math.max(0, e.timer / TIMES.closing))
154 + if (e.timer <= 0) (e.state = "vanish"), (e.timer = TIMES.vanish), (e.open = 0)
155 + break
156 + case "vanish":
157 + e.fade = smooth(Math.max(0, e.timer / TIMES.vanish))
158 + if (e.timer <= 0) {
159 + if (this.list.indexOf(e) >= n) e.drop = true
160 + else Object.assign(e, this.make(), { shade: e.shade })
161 + }
162 + break
163 + }
164 + if (e.state === "open" || e.state === "opening" || e.state === "closing") this.look(e, dt, pointer, fresh)
165 + // Blinks while open, each its own time: shut and open in 150 ms,
166 + // now and then twice.
167 + if (e.state === "open") {
168 + if (e.blink >= 0) {
169 + e.blink += dt
170 + if (e.blink >= TIMES.blink) {
171 + e.blink = -1
172 + e.nextBlink = Math.random() < 0.12 ? 0.12 : rand(...TIMES.blinkEvery)
173 + }
174 + } else if ((e.nextBlink -= dt) <= 0) e.blink = 0
175 + } else e.blink = -1
176 + }
177 +
178 + look(e, dt, pointer, fresh) {
179 + const toPointer = () => {
180 + const dx = pointer.x - e.x
181 + const dy = pointer.y - e.y
182 + const k = 1 / Math.sqrt(dx * dx + dy * dy + 2.25 * e.r * e.r)
183 + return [dx * k, dy * k]
184 + }
185 + // A pointer that has just turned up catches some eyes' attention.
186 + if (fresh && e.state === "open" && Math.random() < 0.5) e.nextGlance = Math.min(e.nextGlance, rand(0.1, 0.6))
187 +
188 + if (e.attending > 0) {
189 + e.attending -= dt
190 + if (!pointer) e.attending = 0
191 + }
192 + if ((e.nextGlance -= dt) <= 0) {
193 + e.nextGlance = rand(...TIMES.glance)
194 + if (pointer && e.attending <= 0 && Math.random() < (fresh ? 0.6 : ATTENTION)) e.attending = rand(...TIMES.attention)
195 + if (e.attending <= 0 || !pointer) e.target = lookAround()
196 + }
197 + // Following the pointer smoothly while attending; otherwise quick
198 + // saccades to each new target.
199 + let tau = 0.035
200 + if (e.attending > 0 && pointer) {
201 + e.target = toPointer()
202 + tau = 0.08
203 + }
204 + const k = 1 - Math.exp(-dt / tau)
205 + e.gaze = [e.gaze[0] + (e.target[0] - e.gaze[0]) * k, e.gaze[1] + (e.target[1] - e.gaze[1]) * k]
206 + }
207 +
208 + // Openness with any blink taken out.
209 + openness(e) {
210 + if (e.blink < 0) return e.open
211 + const t = e.blink / TIMES.blink
212 + return e.open * (1 - Math.min(1, 2 * Math.min(t, 1 - t) * 1.25))
213 + }
214 +
215 + // For reduced motion: n eyes open and looking ahead, placed once and
216 + // kept while the count, ratio and canvas shape stay the same.
217 + settle(extent, n, ratio) {
218 + n = Math.min(MAX_EYES, Math.max(1, Math.round(n)))
219 + const key = `${n} ${ratio} ${extent[0].toFixed(3)} ${extent[1].toFixed(3)}`
220 + if (this.settled === key) return
221 + this.settled = key
222 + this.list = []
223 + for (let i = 0; i < n; i++) {
224 + const e = this.make(0)
225 + if (!this.place(e, extent, n, ratio)) continue
226 + Object.assign(e, { state: "open", timer: rand(...TIMES.open), open: 1, fade: 1 })
227 + this.list.push(e)
228 + }
229 + }
230 +
231 + pack() {
232 + const out = {}
233 + for (let i = 0; i < MAX_EYES; i++) {
234 + const e = this.list[i]
235 + const shown = e && e.state !== "wait"
236 + out[`eye${i}`] = shown ? [e.x, e.y, e.r, this.openness(e)] : [0, 0, 0, 0]
237 + out[`look${i}`] = shown ? [e.gaze[0], e.gaze[1], e.shade, e.fade] : [0, 0, 0, 0]
238 + }
239 + return { ...out, count: Math.min(MAX_EYES, this.list.length) }
240 + }
241 +}
added assets/js/shader_field.js
+467 −0

Click to load diff…

added assets/shaders/bubbles.frag
+144 −0

Click to load diff…

added assets/shaders/eyes.frag
+196 −0

Click to load diff…

added assets/shaders/field.frag
+279 −0

Click to load diff…

added assets/shaders/oil.frag
+110 −0

Click to load diff…

added assets/shaders/prism.frag
+153 −0

Click to load diff…

added assets/shaders/spheres.frag
+139 −0

Click to load diff…

modified config/config.exs
+1 −1

Click to load diff…

modified lib/vigil_web/components/layouts.ex
+20 −1

Click to load diff…

modified lib/vigil_web/live/home_live.ex
+1 −1

Click to load diff…

modified lib/vigil_web/live/org_invite_live.ex
+1 −1

Click to load diff…

modified lib/vigil_web/live/org_settings_live/components.ex
+1 −1

Click to load diff…

modified lib/vigil_web/live/project_live/new.ex
+1 −1

Click to load diff…

added lib/vigil_web/live/shader_live/index.ex
+281 −0

Click to load diff…

modified lib/vigil_web/live/user_live/confirmation.ex
+1 −1

Click to load diff…

modified lib/vigil_web/live/user_live/login.ex
+1 −1

Click to load diff…

modified lib/vigil_web/live/user_live/registration.ex
+1 −1

Click to load diff…

modified lib/vigil_web/live/user_live/settings.ex
+64 −61

Click to load diff…

modified lib/vigil_web/router.ex
+4 −0

Click to load diff…

added test/vigil_web/live/shader_live_test.exs
+43 −0

Click to load diff…

Parents: 6b9b29d 11accb3