Light Trail Login
A sign in form where the pointer draws with light, like a long exposure photo. The trail is warm at first, turns pink and fades out blue.
- Sign in & forms
- Free
- webgl
- Added Oct 9, 2026
<style>
/* page shell, only needed while this file is the whole page */
</style>
<!-- login start -->
<main class="lt">
<section class="lt-door">
<canvas class="lt-glow" aria-hidden="true"></canvas>
<div class="lt-gate">
<h1 class="lt-huge lt-write">Log in</h1>
<form class="lt-form" novalidate data-busy="Logging in" data-label="Logged in" data-done="Welcome back. Change this line or send people to their page.">
<label class="lt-hide" for="lt-user">Email</label>
<input class="lt-field" id="lt-user" name="email" type="email" autocomplete="username" placeholder="you@example.com" data-need="Enter your email.">
<label class="lt-hide" for="lt-pass">Password</label>
<input class="lt-field" id="lt-pass" name="password" type="password" autocomplete="current-password" placeholder="Password" data-need="Enter your password.">
<button class="lt-btn" type="submit">Log in</button>
<p class="lt-note" role="status"></p>
</form>
</div>
</section>
</main>
<!-- login end -->
<script>
/* Light Trail Login by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */
(() => {
const root = document.querySelector('.lt');
if (!root) return;
const LIGHT = { night: [7, 8, 14], warm: [255, 178, 92], pink: [255, 104, 150], cool: [96, 170, 255] };
const LINE = 3, LIGHT_FADE = .99, GLOW = 1.3, LIGHT_PIXELS = 1.6e6;
const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches;
root.classList.add('lt-js');
const $ = (s, el = root) => el.querySelector(s);
const $$ = (s, el = root) => [...el.querySelectorAll(s)];
const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x));
const wait = ms => new Promise(r => setTimeout(r, ms));
/* light: the pointer draws lines of light like a long exposure; old light fades, cools down and thins out */
const lamps = [];
$$('.lt-glow').forEach(cv => {
if (reduce) return;
const host = cv.parentNode, title = $('.lt-write', host);
const gl = cv.getContext('webgl2', { alpha: false, antialias: false, depth: false });
if (!gl || !(gl.getExtension('EXT_color_buffer_float') || gl.getExtension('EXT_color_buffer_half_float'))) return;
const VERT = `#version 300 es
in vec2 a;
out vec2 uv;
void main() { uv = a * .5 + .5; gl_Position = vec4(a, 0., 1.); }`;
// a segment of light: a quad around the segment, brightness falls off with the distance to it
const SEG = `#version 300 es
in vec2 a;
uniform vec2 p0, p1, view;
uniform float width;
out vec2 at;
void main() {
vec2 d = p1 - p0, n = normalize(vec2(-d.y, d.x) + 1e-5), t = normalize(d + 1e-5);
vec2 c = mix(p0, p1, a.x * .5 + .5) + n * a.y * width * 3. + t * a.x * width * 3.;
at = c;
gl_Position = vec4(c / view * 2. - 1., 0., 1.);
}`;
const HEAD = '#version 300 es\nprecision highp float;\nout vec4 o;\n';
const rgb = c => c.map(v => (v / 255).toFixed(3)).join(', ');
const SRC = {
line: `in vec2 at; uniform vec2 p0, p1; uniform float width, power;
void main() {
vec2 d = p1 - p0; float k = clamp(dot(at - p0, d) / max(dot(d, d), 1e-4), 0., 1.);
float r = length(at - p0 - d * k) / width;
o = vec4(power * (exp(-r * r * 1.6) + .22 * exp(-r * .8)), 0., 0., 1.);
}`,
// the old picture fades a little each frame; a scroll of the page drags it along
fade: 'in vec2 uv; uniform sampler2D src; uniform float keep; uniform vec2 shift;\nvoid main() { o = vec4(texture(src, uv + shift).r * keep, 0., 0., 1.); }',
blur: 'in vec2 uv; uniform sampler2D src; uniform vec2 dir;\nvoid main() {\n float s = texture(src, uv).r * .227;\n for (int i = 1; i < 5; i++) { float w = float[5](0., .195, .122, .054, .016)[i]; s += (texture(src, uv + dir * float(i)).r + texture(src, uv - dir * float(i)).r) * w; }\n o = vec4(s, 0., 0., 1.);\n}',
// strong light is warm, it cools to pink and then to blue as it fades
show: `in vec2 uv; uniform sampler2D src, halo; uniform float lift;
const vec3 NIGHT = vec3(${rgb(LIGHT.night)}), WARM = vec3(${rgb(LIGHT.warm)}), PINK = vec3(${rgb(LIGHT.pink)}), COOL = vec3(${rgb(LIGHT.cool)});
vec3 tint(float v) { return v > .55 ? mix(PINK, WARM, smoothstep(.55, 1.1, v)) : mix(COOL, PINK, smoothstep(.12, .55, v)); }
void main() {
float v = texture(src, uv).r, h = texture(halo, uv).r;
vec3 c = NIGHT + tint(v) * min(v, 1.6) + tint(h) * h * ${GLOW.toFixed(2)} * (1. + lift);
c += WARM * max(v - 1.2, 0.) * .25;
o = vec4(1. - exp(-c * 1.35), 1.);
}`,
};
const shader = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); return s; };
const P = {};
for (const name in SRC) {
const p = gl.createProgram();
gl.attachShader(p, shader(gl.VERTEX_SHADER, name === 'line' ? SEG : VERT)); gl.attachShader(p, shader(gl.FRAGMENT_SHADER, HEAD + SRC[name]));
gl.bindAttribLocation(p, 0, 'a'); gl.linkProgram(p);
if (!gl.getProgramParameter(p, gl.LINK_STATUS)) return;
const u = {};
for (let i = 0; i < gl.getProgramParameter(p, gl.ACTIVE_UNIFORMS); i++) { const n = gl.getActiveUniform(p, i).name; u[n] = gl.getUniformLocation(p, n); }
P[name] = { p, u };
}
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
function target(w, h, id) {
const tex = gl.createTexture();
gl.activeTexture(gl.TEXTURE0 + id); gl.bindTexture(gl.TEXTURE_2D, tex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.R16F, w, h, 0, gl.RED, gl.HALF_FLOAT, null);
const fbo = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
gl.viewport(0, 0, w, h); gl.clearColor(0, 0, 0, 1); gl.clear(gl.COLOR_BUFFER_BIT);
return { id, fbo, w, h };
}
let a, b, h1, h2, W = 1, H = 1, k = 1;
function build() {
W = host.clientWidth; H = host.clientHeight;
if (!W || !H) return false;
k = Math.min(devicePixelRatio || 1, 2, Math.sqrt(LIGHT_PIXELS / (W * H)));
cv.width = Math.round(W * k); cv.height = Math.round(H * k);
a = target(cv.width, cv.height, 0); b = target(cv.width, cv.height, 1);
const hw = Math.round(cv.width / 4), hh = Math.round(cv.height / 4);
h1 = target(hw, hh, 2); h2 = target(hw, hh, 3);
return gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE;
}
if (!build()) return;
root.classList.add('lt-lit');
function pass(name, to, set) {
const { p, u } = P[name];
gl.useProgram(p); set(u);
gl.bindFramebuffer(gl.FRAMEBUFFER, to ? to.fbo : null);
gl.viewport(0, 0, to ? to.w : cv.width, to ? to.h : cv.height);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
// segments wait here until the next frame draws them: [x0, y0, x1, y1, width, power] in css pixels from the top left
const marks = [];
function stroke(x0, y0, x1, y1, speed) {
const fast = clamp(speed / 1600);
marks.push([x0, y0, x1, y1, LINE * (1.3 - .6 * fast), 1.55 - .6 * fast]);
}
// lines of its own: two or three slow lights wander over the page when nobody draws
const roam = [0, 1, 2].map(i => ({ ph: i * 2.1, sp: .11 + i * .035, x: -1, y: -1 }));
let shown = true, running = false, last = 0, start = 0, idle = 9, lift = 0, shift = 0;
function frame(now) {
if (!shown || document.hidden) { running = false; return; }
const t = now / 1000, dt = Math.min(t - last, 1 / 20); last = t;
if (!start) start = t;
idle += dt;
const calm = clamp((idle - 1.2) / 1.5);
for (const r of roam) {
if (r === roam[2] && W < 700) continue;
const u = t * r.sp + r.ph;
const x = W * (.5 + .4 * Math.sin(u * 1.3) * Math.cos(u * .37) + .07 * Math.sin(u * 3.7)), y = H * (.5 + .34 * Math.sin(u * .9 + 1.2) + .09 * Math.sin(u * 2.9 + r.ph));
if (r.x >= 0 && calm > 0) marks.push([r.x, r.y, x, y, LINE * .95, .85 * calm]);
r.x = x; r.y = y;
}
gl.disable(gl.BLEND);
pass('fade', b, u => { gl.uniform1i(u.src, a.id); gl.uniform1f(u.keep, Math.pow(LIGHT_FADE, dt * 60)); gl.uniform2f(u.shift, 0, -shift / H); });
shift = 0;
// the brightest wins where two strokes meet: the line stays even, with no beads at the joints
gl.enable(gl.BLEND); gl.blendFunc(gl.ONE, gl.ONE); gl.blendEquation(gl.MAX);
const { p, u } = P.line;
gl.useProgram(p); gl.bindFramebuffer(gl.FRAMEBUFFER, b.fbo); gl.viewport(0, 0, b.w, b.h);
gl.uniform2f(u.view, b.w, b.h);
for (const [x0, y0, x1, y1, w, pw] of marks.splice(0, 200)) {
gl.uniform2f(u.p0, x0 * k, (H - y0) * k); gl.uniform2f(u.p1, x1 * k, (H - y1) * k);
gl.uniform1f(u.width, w * k); gl.uniform1f(u.power, pw);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
gl.disable(gl.BLEND); gl.blendEquation(gl.FUNC_ADD);
[a, b] = [b, a];
pass('blur', h1, u => { gl.uniform1i(u.src, a.id); gl.uniform2f(u.dir, 2.5 / cv.width, 0); });
pass('blur', h2, u => { gl.uniform1i(u.src, h1.id); gl.uniform2f(u.dir, 0, 2.5 / cv.height); });
lift = Math.max(0, lift - dt * 1.2);
pass('show', null, u => { gl.uniform1i(u.src, a.id); gl.uniform1i(u.halo, h2.id); gl.uniform1f(u.lift, lift); });
requestAnimationFrame(frame);
}
const wake = () => { if (running || !shown || document.hidden) return; running = true; requestAnimationFrame(t => { last = t / 1000; frame(t); }); };
const spot = e => { const r = cv.getBoundingClientRect(); return [e.clientX - r.left, e.clientY - r.top]; };
let px = -1, py = -1, pt = 0, pace = 0;
host.addEventListener('pointermove', e => {
const [x, y] = spot(e), now = performance.now() / 1000;
// over a form or a button the light rests, it only draws on the empty dark
if (e.target.closest('form, a, button')) { px = -1; return; }
if (px >= 0) {
// the speed is smoothed over the last moves, so one late event does not leave a bright dash
pace = pace * .6 + Math.hypot(x - px, y - py) / Math.max(now - pt, 1 / 60) * .4;
stroke(px, py, x, y, pace);
}
px = x; py = y; pt = now; idle = 0;
});
host.addEventListener('pointerleave', () => { px = -1; });
host.addEventListener('pointercancel', () => { px = -1; });
// a tap is a flash: a short bright burst where the finger lands
host.addEventListener('pointerdown', e => {
if (e.target.closest('a, button, input, textarea, label')) return;
const [x, y] = spot(e);
for (let i = 0; i < 8; i++) { const q = i / 8 * Math.PI * 2; marks.push([x, y, x + Math.cos(q) * 14, y + Math.sin(q) * 14, LINE * 1.4, .9]); }
px = x; py = y; pt = performance.now() / 1000; idle = 0;
});
// scrolling the page pulls all the light up with it
let top = scrollY;
addEventListener('scroll', () => { const d = scrollY - top; top = scrollY; if (shown) shift += d; }, { passive: true });
lamps.push({
host,
// a line of light runs from one point to the next, used by the headline and the button
trace(path, power = .7) { for (let i = 1; i < path.length; i++) marks.push([...path[i - 1], ...path[i], LINE, power]); idle = 0; },
spot(cx, cy) { const r = cv.getBoundingClientRect(); return [cx - r.left, cy - r.top]; },
flare() { lift = 1; },
});
new ResizeObserver(() => { if (cv.width && Math.abs(host.clientWidth - W) + Math.abs(host.clientHeight - H) > 2) build(); }).observe(host);
new IntersectionObserver(([e]) => { shown = e.isIntersecting; wake(); }).observe(cv);
document.addEventListener('visibilitychange', wake);
wake();
});
/* headlines: a line of light runs along each row of letters and writes them as it passes */
$$('.lt-write').forEach(el => {
if (reduce) return;
el.innerHTML = el.textContent.trim().split(' ').map(w => `<span class="lt-wd">${[...w].map(c => `<span class="lt-ch">${c}</span>`).join('')}</span>`).join(' ');
const chars = $$('.lt-ch', el), lamp = lamps.find(l => l.host.contains(el));
const rows = [];
for (const c of chars) {
const r = c.getBoundingClientRect(), row = rows.find(q => Math.abs(q.top - r.top) < r.height / 2);
if (row) { row.cs.push([c, r]); row.right = r.right; } else rows.push({ top: r.top, mid: r.top + r.height * .58, left: r.left, right: r.right, cs: [[c, r]] });
}
const PER = .62, t0 = performance.now() + 200;
let head = null;
requestAnimationFrame(function run(now) {
const s = (now - t0) / 1000;
if (s < 0) { requestAnimationFrame(run); return; }
const i = Math.min(rows.length - 1, Math.floor(s / PER)), row = rows[i], u = clamp((s - i * PER) / PER), e = 1 - Math.pow(1 - u, 2);
const x = row.left - 24 + (row.right - row.left + 48) * e, y = row.mid + Math.sin(e * Math.PI * 2) * row.cs[0][1].height * .12;
if (lamp) {
const p = lamp.spot(x, y);
if (head && head[2] === i) lamp.trace([[head[0], head[1]], p], .85);
head = [...p, i];
}
for (let r = 0; r <= i; r++) for (const [c, box] of rows[r].cs) if (r < i || box.left + box.width / 2 < x) c.classList.add('lt-on');
if (s < rows.length * PER) requestAnimationFrame(run); else chars.forEach(c => c.classList.add('lt-on'));
});
});
/* a line of light runs round an element and closes the loop; over the light canvas it is real light that fades on its own */
function encircle(el, { gap = 6, time = .9, power = 1, flare = false } = {}) {
if (reduce) return;
const r = el.getBoundingClientRect(), k = Math.min(devicePixelRatio || 1, 2);
const L = r.left - gap, T = r.top - gap, R = r.right + gap, B = r.bottom + gap, rad = Math.min((B - T) / 2, parseFloat(getComputedStyle(el).borderTopLeftRadius) + gap || gap), pts = [];
const arc = (cx, cy, a0, a1) => { for (let i = 0; i <= 10; i++) { const q = a0 + (a1 - a0) * i / 10; pts.push([cx + Math.cos(q) * rad, cy + Math.sin(q) * rad]); } };
arc(L + rad, T + rad, Math.PI, Math.PI * 1.5); arc(R - rad, T + rad, -Math.PI / 2, 0); arc(R - rad, B - rad, 0, Math.PI / 2); arc(L + rad, B - rad, Math.PI / 2, Math.PI);
pts.push(pts[0]);
const lamp = lamps.find(l => { const h = l.host.getBoundingClientRect(); return L > h.left && R < h.right && T > h.top && B < h.bottom; });
const t0 = performance.now();
let drawn = 0, cv = null, c = null;
if (!lamp) {
cv = document.createElement('canvas'); c = cv.getContext('2d');
cv.className = 'lt-ring'; cv.width = innerWidth * k; cv.height = innerHeight * k;
root.append(cv);
}
const warm = LIGHT.warm.join(', '), pink = LIGHT.pink.join(', ');
requestAnimationFrame(function run(now) {
const s = (now - t0) / 1000, u = clamp(s / time), e = 1 - Math.pow(1 - u, 2), n = Math.max(1, Math.round(e * (pts.length - 1)));
if (lamp) {
if (n > drawn) lamp.trace(pts.slice(Math.max(0, drawn - 1), n + 1).map(([x, y]) => lamp.spot(x, y)), power);
drawn = n;
if (flare && u === 1) { lamp.flare(); flare = false; }
if (u < 1) requestAnimationFrame(run);
return;
}
c.setTransform(k, 0, 0, k, 0, 0); c.clearRect(0, 0, innerWidth, innerHeight);
const fade = clamp(1 - (s - time - .2) / .7);
c.lineCap = 'round'; c.lineJoin = 'round'; c.lineWidth = 2; c.shadowBlur = 10;
for (let i = 1; i <= n; i++) {
const f = i / n, a = fade * (u < 1 ? .25 + .75 * f : 1);
c.strokeStyle = `rgba(${f > .5 || u === 1 ? warm : pink}, ${a.toFixed(3)})`;
c.shadowColor = `rgba(${warm}, ${(a * .8).toFixed(3)})`;
c.beginPath(); c.moveTo(...pts[i - 1]); c.lineTo(...pts[i]); c.stroke();
}
if (s < time + .9) requestAnimationFrame(run); else cv.remove();
});
}
/* the form: checks the fields, waits for the server, then a line of light runs round the button */
$$('.lt-form').forEach(form => {
const btn = $('.lt-btn', form), note = $('.lt-note', form), fields = $$('.lt-field', form);
form.addEventListener('submit', async e => {
e.preventDefault();
const bad = fields.find(f => !f.value.trim() || f.type === 'email' && !/^\S+@\S+\.\S+$/.test(f.value.trim()));
fields.forEach(f => f.classList.toggle('lt-bad', f === bad));
form.classList.toggle('lt-form-bad', !!bad);
if (bad) {
note.textContent = bad.type === 'email' && bad.value.trim() ? 'That does not look like an email. Try one like name@example.com.' : bad.dataset.need || 'Fill in this field first.';
bad.focus();
return;
}
btn.disabled = true; btn.textContent = form.dataset.busy || 'Sending';
// a real server request goes here, for example:
// await fetch('/api/login', { method: 'POST', body: new FormData(form) });
await wait(700);
fields.forEach(f => { f.disabled = true; });
btn.textContent = form.dataset.label || 'Sent';
form.classList.add('lt-sent');
note.textContent = form.dataset.done || 'Thank you. We will write back soon.';
encircle(btn, { flare: true });
});
fields.forEach(f => f.addEventListener('input', () => { form.classList.remove('lt-form-bad'); f.classList.remove('lt-bad'); note.textContent = ''; }));
});
})();
</script>
Move the pointer to draw. Type any email and password and press Log in: a line of light runs round the button and closes.
What you can change
Change a number, save, and reload the page to see the difference.
LIGHTnight and three colorsThe night and three colors of the light (head, middle, tail), each as red, green, blue.
LINE3How thick a line of light is, in pixels.
LIGHT_FADE0.99How long the light lives, closer to 1 lives longer. Keep it below 1.
GLOW1.3How much soft glow surrounds the lines.
Add it to your site
The sign in page of a studio, a portfolio or a product, anywhere the first screen can afford a little motion.
CSS
Paste into your stylesheet, or inside a <style> tag in <head>.
/* page shell, only needed while this file is the whole page */HTML
Put it where the effect should appear on your page.
<!-- login start --> <main class="lt"> <section class="lt-door"> <canvas class="lt-glow" aria-hidden="true"></canvas> <div class="lt-gate"> <h1 class="lt-huge lt-write">Log in</h1> <form class="lt-form" novalidate data-busy="Logging in" data-label="Logged in" data-done="Welcome back. Change this line or send people to their page."> <label class="lt-hide" for="lt-user">Email</label> <input class="lt-field" id="lt-user" name="email" type="email" autocomplete="username" placeholder="you@example.com" data-need="Enter your email."> <label class="lt-hide" for="lt-pass">Password</label> <input class="lt-field" id="lt-pass" name="password" type="password" autocomplete="current-password" placeholder="Password" data-need="Enter your password."> <button class="lt-btn" type="submit">Log in</button> <p class="lt-note" role="status"></p> </form> </div> </section> </main> <!-- login end -->JavaScript
Paste right before the closing </body> tag, inside <script></script>.
/* Light Trail Login by @codinvisual · t.me/CodinVisual · free for your own site, don't resell this file */ (() => { const root = document.querySelector('.lt'); if (!root) return; const LIGHT = { night: [7, 8, 14], warm: [255, 178, 92], pink: [255, 104, 150], cool: [96, 170, 255] }; const LINE = 3, LIGHT_FADE = .99, GLOW = 1.3, LIGHT_PIXELS = 1.6e6; const reduce = matchMedia('(prefers-reduced-motion: reduce)').matches; root.classList.add('lt-js'); const $ = (s, el = root) => el.querySelector(s); const $$ = (s, el = root) => [...el.querySelectorAll(s)]; const clamp = (x, a = 0, b = 1) => Math.min(b, Math.max(a, x)); const wait = ms => new Promise(r => setTimeout(r, ms)); /* light: the pointer draws lines of light like a long exposure; old light fades, cools down and thins out */ const lamps = []; $$('.lt-glow').forEach(cv => { if (reduce) return; const host = cv.parentNode, title = $('.lt-write', host); const gl = cv.getContext('webgl2', { alpha: false, antialias: false, depth: false }); if (!gl || !(gl.getExtension('EXT_color_buffer_float') || gl.getExtension('EXT_color_buffer_half_float'))) return; const VERT = `#version 300 es in vec2 a; out vec2 uv; void main() { uv = a * .5 + .5; gl_Position = vec4(a, 0., 1.); }`; // a segment of light: a quad around the segment, brightness falls off with the distance to it const SEG = `#version 300 es in vec2 a; uniform vec2 p0, p1, view; uniform float width; out vec2 at; void main() { vec2 d = p1 - p0, n = normalize(vec2(-d.y, d.x) + 1e-5), t = normalize(d + 1e-5); vec2 c = mix(p0, p1, a.x * .5 + .5) + n * a.y * width * 3. + t * a.x * width * 3.; at = c; gl_Position = vec4(c / view * 2. - 1., 0., 1.); }`; const HEAD = '#version 300 es\nprecision highp float;\nout vec4 o;\n'; const rgb = c => c.map(v => (v / 255).toFixed(3)).join(', '); const SRC = { line: `in vec2 at; uniform vec2 p0, p1; uniform float width, power; void main() { vec2 d = p1 - p0; float k = clamp(dot(at - p0, d) / max(dot(d, d), 1e-4), 0., 1.); float r = length(at - p0 - d * k) / width; o = vec4(power * (exp(-r * r * 1.6) + .22 * exp(-r * .8)), 0., 0., 1.); }`, // the old picture fades a little each frame; a scroll of the page drags it along fade: 'in vec2 uv; uniform sampler2D src; uniform float keep; uniform vec2 shift;\nvoid main() { o = vec4(texture(src, uv + shift).r * keep, 0., 0., 1.); }', blur: 'in vec2 uv; uniform sampler2D src; uniform vec2 dir;\nvoid main() {\n float s = texture(src, uv).r * .227;\n for (int i = 1; i < 5; i++) { float w = float[5](0., .195, .122, .054, .016)[i]; s += (texture(src, uv + dir * float(i)).r + texture(src, uv - dir * float(i)).r) * w; }\n o = vec4(s, 0., 0., 1.);\n}', // strong light is warm, it cools to pink and then to blue as it fades show: `in vec2 uv; uniform sampler2D src, halo; uniform float lift; const vec3 NIGHT = vec3(${rgb(LIGHT.night)}), WARM = vec3(${rgb(LIGHT.warm)}), PINK = vec3(${rgb(LIGHT.pink)}), COOL = vec3(${rgb(LIGHT.cool)}); vec3 tint(float v) { return v > .55 ? mix(PINK, WARM, smoothstep(.55, 1.1, v)) : mix(COOL, PINK, smoothstep(.12, .55, v)); } void main() { float v = texture(src, uv).r, h = texture(halo, uv).r; vec3 c = NIGHT + tint(v) * min(v, 1.6) + tint(h) * h * ${GLOW.toFixed(2)} * (1. + lift); c += WARM * max(v - 1.2, 0.) * .25; o = vec4(1. - exp(-c * 1.35), 1.); }`, }; const shader = (type, src) => { const s = gl.createShader(type); gl.shaderSource(s, src); gl.compileShader(s); return s; }; const P = {}; for (const name in SRC) { const p = gl.createProgram(); gl.attachShader(p, shader(gl.VERTEX_SHADER, name === 'line' ? SEG : VERT)); gl.attachShader(p, shader(gl.FRAGMENT_SHADER, HEAD + SRC[name])); gl.bindAttribLocation(p, 0, 'a'); gl.linkProgram(p); if (!gl.getProgramParameter(p, gl.LINK_STATUS)) return; const u = {}; for (let i = 0; i < gl.getProgramParameter(p, gl.ACTIVE_UNIFORMS); i++) { const n = gl.getActiveUniform(p, i).name; u[n] = gl.getUniformLocation(p, n); } P[name] = { p, u }; } gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer()); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW); gl.enableVertexAttribArray(0); gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0); function target(w, h, id) { const tex = gl.createTexture(); gl.activeTexture(gl.TEXTURE0 + id); gl.bindTexture(gl.TEXTURE_2D, tex); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); gl.texImage2D(gl.TEXTURE_2D, 0, gl.R16F, w, h, 0, gl.RED, gl.HALF_FLOAT, null); const fbo = gl.createFramebuffer(); gl.bindFramebuffer(gl.FRAMEBUFFER, fbo); gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0); gl.viewport(0, 0, w, h); gl.clearColor(0, 0, 0, 1); gl.clear(gl.COLOR_BUFFER_BIT); return { id, fbo, w, h }; } let a, b, h1, h2, W = 1, H = 1, k = 1; function build() { W = host.clientWidth; H = host.clientHeight; if (!W || !H) return false; k = Math.min(devicePixelRatio || 1, 2, Math.sqrt(LIGHT_PIXELS / (W * H))); cv.width = Math.round(W * k); cv.height = Math.round(H * k); a = target(cv.width, cv.height, 0); b = target(cv.width, cv.height, 1); const hw = Math.round(cv.width / 4), hh = Math.round(cv.height / 4); h1 = target(hw, hh, 2); h2 = target(hw, hh, 3); return gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE; } if (!build()) return; root.classList.add('lt-lit'); function pass(name, to, set) { const { p, u } = P[name]; gl.useProgram(p); set(u); gl.bindFramebuffer(gl.FRAMEBUFFER, to ? to.fbo : null); gl.viewport(0, 0, to ? to.w : cv.width, to ? to.h : cv.height); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); } // segments wait here until the next frame draws them: [x0, y0, x1, y1, width, power] in css pixels from the top left const marks = []; function stroke(x0, y0, x1, y1, speed) { const fast = clamp(speed / 1600); marks.push([x0, y0, x1, y1, LINE * (1.3 - .6 * fast), 1.55 - .6 * fast]); } // lines of its own: two or three slow lights wander over the page when nobody draws const roam = [0, 1, 2].map(i => ({ ph: i * 2.1, sp: .11 + i * .035, x: -1, y: -1 })); let shown = true, running = false, last = 0, start = 0, idle = 9, lift = 0, shift = 0; function frame(now) { if (!shown || document.hidden) { running = false; return; } const t = now / 1000, dt = Math.min(t - last, 1 / 20); last = t; if (!start) start = t; idle += dt; const calm = clamp((idle - 1.2) / 1.5); for (const r of roam) { if (r === roam[2] && W < 700) continue; const u = t * r.sp + r.ph; const x = W * (.5 + .4 * Math.sin(u * 1.3) * Math.cos(u * .37) + .07 * Math.sin(u * 3.7)), y = H * (.5 + .34 * Math.sin(u * .9 + 1.2) + .09 * Math.sin(u * 2.9 + r.ph)); if (r.x >= 0 && calm > 0) marks.push([r.x, r.y, x, y, LINE * .95, .85 * calm]); r.x = x; r.y = y; } gl.disable(gl.BLEND); pass('fade', b, u => { gl.uniform1i(u.src, a.id); gl.uniform1f(u.keep, Math.pow(LIGHT_FADE, dt * 60)); gl.uniform2f(u.shift, 0, -shift / H); }); shift = 0; // the brightest wins where two strokes meet: the line stays even, with no beads at the joints gl.enable(gl.BLEND); gl.blendFunc(gl.ONE, gl.ONE); gl.blendEquation(gl.MAX); const { p, u } = P.line; gl.useProgram(p); gl.bindFramebuffer(gl.FRAMEBUFFER, b.fbo); gl.viewport(0, 0, b.w, b.h); gl.uniform2f(u.view, b.w, b.h); for (const [x0, y0, x1, y1, w, pw] of marks.splice(0, 200)) { gl.uniform2f(u.p0, x0 * k, (H - y0) * k); gl.uniform2f(u.p1, x1 * k, (H - y1) * k); gl.uniform1f(u.width, w * k); gl.uniform1f(u.power, pw); gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); } gl.disable(gl.BLEND); gl.blendEquation(gl.FUNC_ADD); [a, b] = [b, a]; pass('blur', h1, u => { gl.uniform1i(u.src, a.id); gl.uniform2f(u.dir, 2.5 / cv.width, 0); }); pass('blur', h2, u => { gl.uniform1i(u.src, h1.id); gl.uniform2f(u.dir, 0, 2.5 / cv.height); }); lift = Math.max(0, lift - dt * 1.2); pass('show', null, u => { gl.uniform1i(u.src, a.id); gl.uniform1i(u.halo, h2.id); gl.uniform1f(u.lift, lift); }); requestAnimationFrame(frame); } const wake = () => { if (running || !shown || document.hidden) return; running = true; requestAnimationFrame(t => { last = t / 1000; frame(t); }); }; const spot = e => { const r = cv.getBoundingClientRect(); return [e.clientX - r.left, e.clientY - r.top]; }; let px = -1, py = -1, pt = 0, pace = 0; host.addEventListener('pointermove', e => { const [x, y] = spot(e), now = performance.now() / 1000; // over a form or a button the light rests, it only draws on the empty dark if (e.target.closest('form, a, button')) { px = -1; return; } if (px >= 0) { // the speed is smoothed over the last moves, so one late event does not leave a bright dash pace = pace * .6 + Math.hypot(x - px, y - py) / Math.max(now - pt, 1 / 60) * .4; stroke(px, py, x, y, pace); } px = x; py = y; pt = now; idle = 0; }); host.addEventListener('pointerleave', () => { px = -1; }); host.addEventListener('pointercancel', () => { px = -1; }); // a tap is a flash: a short bright burst where the finger lands host.addEventListener('pointerdown', e => { if (e.target.closest('a, button, input, textarea, label')) return; const [x, y] = spot(e); for (let i = 0; i < 8; i++) { const q = i / 8 * Math.PI * 2; marks.push([x, y, x + Math.cos(q) * 14, y + Math.sin(q) * 14, LINE * 1.4, .9]); } px = x; py = y; pt = performance.now() / 1000; idle = 0; }); // scrolling the page pulls all the light up with it let top = scrollY; addEventListener('scroll', () => { const d = scrollY - top; top = scrollY; if (shown) shift += d; }, { passive: true }); lamps.push({ host, // a line of light runs from one point to the next, used by the headline and the button trace(path, power = .7) { for (let i = 1; i < path.length; i++) marks.push([...path[i - 1], ...path[i], LINE, power]); idle = 0; }, spot(cx, cy) { const r = cv.getBoundingClientRect(); return [cx - r.left, cy - r.top]; }, flare() { lift = 1; }, }); new ResizeObserver(() => { if (cv.width && Math.abs(host.clientWidth - W) + Math.abs(host.clientHeight - H) > 2) build(); }).observe(host); new IntersectionObserver(([e]) => { shown = e.isIntersecting; wake(); }).observe(cv); document.addEventListener('visibilitychange', wake); wake(); }); /* headlines: a line of light runs along each row of letters and writes them as it passes */ $$('.lt-write').forEach(el => { if (reduce) return; el.innerHTML = el.textContent.trim().split(' ').map(w => `<span class="lt-wd">${[...w].map(c => `<span class="lt-ch">${c}</span>`).join('')}</span>`).join(' '); const chars = $$('.lt-ch', el), lamp = lamps.find(l => l.host.contains(el)); const rows = []; for (const c of chars) { const r = c.getBoundingClientRect(), row = rows.find(q => Math.abs(q.top - r.top) < r.height / 2); if (row) { row.cs.push([c, r]); row.right = r.right; } else rows.push({ top: r.top, mid: r.top + r.height * .58, left: r.left, right: r.right, cs: [[c, r]] }); } const PER = .62, t0 = performance.now() + 200; let head = null; requestAnimationFrame(function run(now) { const s = (now - t0) / 1000; if (s < 0) { requestAnimationFrame(run); return; } const i = Math.min(rows.length - 1, Math.floor(s / PER)), row = rows[i], u = clamp((s - i * PER) / PER), e = 1 - Math.pow(1 - u, 2); const x = row.left - 24 + (row.right - row.left + 48) * e, y = row.mid + Math.sin(e * Math.PI * 2) * row.cs[0][1].height * .12; if (lamp) { const p = lamp.spot(x, y); if (head && head[2] === i) lamp.trace([[head[0], head[1]], p], .85); head = [...p, i]; } for (let r = 0; r <= i; r++) for (const [c, box] of rows[r].cs) if (r < i || box.left + box.width / 2 < x) c.classList.add('lt-on'); if (s < rows.length * PER) requestAnimationFrame(run); else chars.forEach(c => c.classList.add('lt-on')); }); }); /* a line of light runs round an element and closes the loop; over the light canvas it is real light that fades on its own */ function encircle(el, { gap = 6, time = .9, power = 1, flare = false } = {}) { if (reduce) return; const r = el.getBoundingClientRect(), k = Math.min(devicePixelRatio || 1, 2); const L = r.left - gap, T = r.top - gap, R = r.right + gap, B = r.bottom + gap, rad = Math.min((B - T) / 2, parseFloat(getComputedStyle(el).borderTopLeftRadius) + gap || gap), pts = []; const arc = (cx, cy, a0, a1) => { for (let i = 0; i <= 10; i++) { const q = a0 + (a1 - a0) * i / 10; pts.push([cx + Math.cos(q) * rad, cy + Math.sin(q) * rad]); } }; arc(L + rad, T + rad, Math.PI, Math.PI * 1.5); arc(R - rad, T + rad, -Math.PI / 2, 0); arc(R - rad, B - rad, 0, Math.PI / 2); arc(L + rad, B - rad, Math.PI / 2, Math.PI); pts.push(pts[0]); const lamp = lamps.find(l => { const h = l.host.getBoundingClientRect(); return L > h.left && R < h.right && T > h.top && B < h.bottom; }); const t0 = performance.now(); let drawn = 0, cv = null, c = null; if (!lamp) { cv = document.createElement('canvas'); c = cv.getContext('2d'); cv.className = 'lt-ring'; cv.width = innerWidth * k; cv.height = innerHeight * k; root.append(cv); } const warm = LIGHT.warm.join(', '), pink = LIGHT.pink.join(', '); requestAnimationFrame(function run(now) { const s = (now - t0) / 1000, u = clamp(s / time), e = 1 - Math.pow(1 - u, 2), n = Math.max(1, Math.round(e * (pts.length - 1))); if (lamp) { if (n > drawn) lamp.trace(pts.slice(Math.max(0, drawn - 1), n + 1).map(([x, y]) => lamp.spot(x, y)), power); drawn = n; if (flare && u === 1) { lamp.flare(); flare = false; } if (u < 1) requestAnimationFrame(run); return; } c.setTransform(k, 0, 0, k, 0, 0); c.clearRect(0, 0, innerWidth, innerHeight); const fade = clamp(1 - (s - time - .2) / .7); c.lineCap = 'round'; c.lineJoin = 'round'; c.lineWidth = 2; c.shadowBlur = 10; for (let i = 1; i <= n; i++) { const f = i / n, a = fade * (u < 1 ? .25 + .75 * f : 1); c.strokeStyle = `rgba(${f > .5 || u === 1 ? warm : pink}, ${a.toFixed(3)})`; c.shadowColor = `rgba(${warm}, ${(a * .8).toFixed(3)})`; c.beginPath(); c.moveTo(...pts[i - 1]); c.lineTo(...pts[i]); c.stroke(); } if (s < time + .9) requestAnimationFrame(run); else cv.remove(); }); } /* the form: checks the fields, waits for the server, then a line of light runs round the button */ $$('.lt-form').forEach(form => { const btn = $('.lt-btn', form), note = $('.lt-note', form), fields = $$('.lt-field', form); form.addEventListener('submit', async e => { e.preventDefault(); const bad = fields.find(f => !f.value.trim() || f.type === 'email' && !/^\S+@\S+\.\S+$/.test(f.value.trim())); fields.forEach(f => f.classList.toggle('lt-bad', f === bad)); form.classList.toggle('lt-form-bad', !!bad); if (bad) { note.textContent = bad.type === 'email' && bad.value.trim() ? 'That does not look like an email. Try one like name@example.com.' : bad.dataset.need || 'Fill in this field first.'; bad.focus(); return; } btn.disabled = true; btn.textContent = form.dataset.busy || 'Sending'; // a real server request goes here, for example: // await fetch('/api/login', { method: 'POST', body: new FormData(form) }); await wait(700); fields.forEach(f => { f.disabled = true; }); btn.textContent = form.dataset.label || 'Sent'; form.classList.add('lt-sent'); note.textContent = form.dataset.done || 'Thank you. We will write back soon.'; encircle(btn, { flare: true }); }); fields.forEach(f => f.addEventListener('input', () => { form.classList.remove('lt-form-bad'); f.classList.remove('lt-bad'); note.textContent = ''; })); }); })();
Connect it to your backend
The form sends nothing until you connect it. Search for a real server request goes here, put your fetch() there and remove the timer on the next line.
Good to know
- A slow hand draws a bright thick line, a fast one a long thin one.
- The words Log in are written by a running line of light.
- On a phone a tap is a flash and a swipe draws.
Tilda, Webflow, WordPress
Press Copy all code at the top and paste it into one HTML block.
Add block, Other, T123 HTML code. Paste and save. Check the published page, the editor preview does not run scripts.
Add panel, Embed. Paste, then Save & Close. Custom code runs on the published site.
Add block, Custom HTML. Paste and press Update.



