Inscription
A living manuscript wall. Dense columns of calligraphic characters in soft greys drift slowly at different speeds, like scrolls unrolling at different depths, and the characters quietly change into others as you watch. Every moment a new phrase writes itself somewhere on the wall: character by character, each one filling with light from the top like wet ink, holding, then fading back, a few of them in a seal-red accent, lifted by a real bloom while the blacks stay black. Your cursor is a reading light: the characters under it brighten, lean away and start to change, and moving it writes glowing phrases along your path. A click sends a ring that rewrites every character it passes and inks seal-red phrases around the point, and scrolling slides the columns past each other in depth.
Tweak
LIVELIVEColour
Wall
Motion
Interactive
Reading light writes along your path, click for a ring of ink
Usage
Follows your tweaks.
import { Inscription } from "@/components/inreact/inscription";
export function Hero() {
return (
<Inscription
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the wall */}
</Inscription>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/inscription.jsonOr copy the source
Install the dependencies, then save this as components/inreact/inscription.tsx.
npm install gsap"use client";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useEffect, useRef, type ReactNode } from "react";
gsap.registerPlugin(ScrollTrigger);
/**
* Inscription: a living manuscript wall.
*
* A dense wall of calligraphic characters in soft greys, set in vertical
* columns that drift slowly at different speeds, like scrolls unrolling at
* different depths. Characters quietly change into others as you watch. Every
* moment a new phrase writes itself somewhere on the wall: character by
* character, each one filling with light from the top like wet ink, holding,
* then fading back. A few are written in a seal-red accent.
*
* It reacts: your cursor is a reading light. The characters under it brighten,
* lean away and start to change, and moving it writes glowing phrases along
* your path. A click sends a ring that rewrites every character it passes and
* inks seal-red phrases around the point. Scrolling slides the columns past
* each other in depth and speeds the drift. On load the wall dissolves in.
*
* <Inscription className="h-screen w-full">
* <YourHero />
* </Inscription>
*
* WebGL2: one shader draws the wall from a glyph atlas (sampled with explicit
* gradients, so cell edges never show seams), then a bloom at 1/4 and 1/16
* size. Pass `glyphs` to use any characters you like; without a CJK font on the
* device it falls back to Latin letters. Pauses off-screen; reduced motion
* shows a still frame; a CSS gradient without WebGL2.
*/
export interface InscriptionProps {
/** Colour of the resting characters. */
color?: string;
/** Colour of the written phrases. */
highlight?: string;
/** Accent colour for seal-red phrases and click ink. */
accent?: string;
/** Background colour. */
background?: string;
/** Characters to build the wall from (up to 256). */
glyphs?: string;
/** Character size in px (scaled down on small screens). */
size?: number;
/** How bright the resting wall is, 0 to 1. */
intensity?: number;
/** Speed of the drift and the writing. */
speed?: number;
/** Strength of the bloom on written phrases. */
glow?: number;
/** Reading light, cursor writing, click ring, scroll response. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the wall. */
children?: ReactNode;
className?: string;
}
const DEFAULT_GLYPHS =
"光影风雨山水云月花夜梦心天地人和安静远长春秋星海江河林雪火金木石竹书字画诗歌声音色香清明白青红黄蓝紫流动生命时空道路门家城市街灯雾露霜冰波浪潮岸舟桥楼窗纸墨笔印章意境情思念忆新古今未来去回见听看说行走飞落起开上下中外内前后东西南北方圆高深浅轻重快慢大小多少美好真善爱乐喜悲笑泪自由梅兰菊松鹤龙凤云雷电晨暮朝夕岁年日星辰宇宙川谷峰岭泉溪湖烟尘沙玉珠锦绣丝绸琴棋茶酒舞剑影随风逝如梦初醒归途千万里一念之间";
const LATIN = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789&§¶†‡";
const ATLAS_N = 16; // 16 x 16 cells
const CELL = 64;
const MAXP = 24; // phrases being written at once
const MAXW = 4; // click rings in flight
const QUAD = `#version 300 es
in vec2 aQ; out vec2 vUv;
void main(){ vUv = aQ * 0.5 + 0.5; gl_Position = vec4(aQ, 0.0, 1.0); }`;
const SCENE = `#version 300 es
precision highp float;
uniform vec2 uRes, uMouse; // css px, top-left origin
uniform float uDpr, uTime, uCs, uDrift, uScroll, uIntro, uHover, uScale, uCount, uCols, uLevel;
uniform vec3 uColor, uHi, uAcc, uBg;
uniform vec4 uP[${MAXP}]; // column, first row, length, start time
uniform vec4 uQ[${MAXP}]; // chars per second, hold, accent, active
uniform vec4 uWave[${MAXW}]; // x, y, start time, strength
uniform sampler2D uAtlas;
uniform highp sampler2D uColTex; // per column: drift speed, scroll depth
in vec2 vUv;
out vec4 o;
float h21(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float glyph(float gi, vec2 inner, float cs) {
if (inner.x < 0.0 || inner.x > 1.0 || inner.y < 0.0 || inner.y > 1.0) return 0.0;
vec2 slot = vec2(mod(gi, ${ATLAS_N}.0), floor(gi / ${ATLAS_N}.0));
vec2 uv = (slot + inner) / ${ATLAS_N}.0;
vec2 gd = vec2(1.0 / (cs * 0.9 * uDpr) / ${ATLAS_N}.0);
return textureGrad(uAtlas, uv, vec2(gd.x, 0.0), vec2(0.0, gd.y)).r;
}
void main() {
vec2 p = vec2(gl_FragCoord.x, uRes.y * uDpr - gl_FragCoord.y) / uDpr;
float col = floor(p.x / uCs);
vec2 cd = texelFetch(uColTex, ivec2(int(clamp(col, 0.0, uCols - 1.0)), 0), 0).rg;
float off = uDrift * cd.x + uScroll * cd.y;
float y = p.y + off;
float row = floor(y / uCs);
vec2 f = vec2(fract(p.x / uCs), fract(y / uCs));
vec2 cell = vec2(col, row);
vec2 cc = vec2((col + 0.5) * uCs, (row + 0.5) * uCs - off);
// the reading light
vec2 dm = cc - uMouse;
float R = 150.0 * uScale;
float near = exp(-dot(dm, dm) / (R * R)) * uHover;
// click rings
float wave = 0.0;
for (int i = 0; i < ${MAXW}; i++) {
vec4 W = uWave[i];
if (W.w <= 0.0) continue;
float age = uTime - W.z;
if (age < 0.0 || age > 2.6) continue;
float r = length(cc - W.xy);
wave = max(wave, exp(-pow((r - age * 520.0 * uScale) / (46.0 * uScale), 2.0)) * exp(-age * 1.3) * W.w);
}
// written phrases: each character fills with light from the top, like ink
float lit = 0.0, tint = 0.0, head = 0.0;
for (int i = 0; i < ${MAXP}; i++) {
vec4 P = uP[i], Q = uQ[i];
if (Q.w < 0.5 || abs(P.x - col) > 0.5) continue;
float k = row - P.y;
if (k < 0.0 || k >= P.z) continue;
float age = uTime - P.w;
float rv = age * Q.x - k;
if (rv <= 0.0) continue;
float wipe = clamp((rv * 1.4 - f.y) / 0.3, 0.0, 1.0);
float total = P.z / Q.x;
float fade = 1.0 - smoothstep(total + Q.y, total + Q.y + 1.8, age);
float L = wipe * fade;
if (L > lit) {
lit = L;
tint = Q.z;
head = (1.0 - smoothstep(0.0, 2.5, rv)) * fade;
}
}
// characters slowly change into others; faster under the light and in a ring
float hs = h21(cell);
float rate = 0.03 + 0.09 * hs + near * 1.6 + wave * 5.0;
float ph = uTime * rate + hs * 17.0;
float ep = floor(ph);
float fr = lit > 0.01 ? 0.0 : smoothstep(0.7, 1.0, fract(ph));
float g1 = floor(h21(cell + ep * 0.37) * uCount);
float g2 = floor(h21(cell + (ep + 1.0) * 0.37) * uCount);
// characters lean away from the light
vec2 push = dm / max(length(dm), 1.0) * near * 0.12;
vec2 inner = (f - 0.5 - push) / 0.9 + 0.5;
float a = mix(glyph(g1, inner, uCs), glyph(g2, inner, uCs), fr);
// the resting wall: mostly soft greys, a few brighter characters
float base = mix(0.13, 0.5, pow(h21(cell + 3.1), 1.5));
if (h21(cell + 8.8) < 0.025) base = 0.62;
base *= uLevel;
vec3 c = uColor * base * (1.0 + near * 1.7) + mix(uHi, uAcc, 0.35) * wave * 0.55;
vec3 hc = mix(uHi, uAcc, tint);
c = mix(c, hc * (1.05 + head * 0.85), lit);
// intro: the wall dissolves in, character by character
float th = h21(cell + 5.7) * 0.75 + (1.0 - p.y / uRes.y) * 0.25;
float show = smoothstep(th, th + 0.12, uIntro * 1.15);
vec3 outc = uBg + c * a * show;
outc += (h21(gl_FragCoord.xy + fract(uTime) * 91.0) - 0.5) / 255.0;
o = vec4(outc, 1.0);
}`;
const BLUR = `#version 300 es
precision mediump float;
uniform sampler2D uTex; uniform vec2 uStep; in vec2 vUv; out vec4 o;
void main() {
vec4 c = texture(uTex, vUv) * 0.2270;
c += (texture(uTex, vUv + uStep * 1.3846) + texture(uTex, vUv - uStep * 1.3846)) * 0.3162;
c += (texture(uTex, vUv + uStep * 3.2308) + texture(uTex, vUv - uStep * 3.2308)) * 0.0703;
o = c;
}`;
const BRIGHT = `#version 300 es
precision mediump float;
uniform sampler2D uTex; in vec2 vUv; out vec4 o;
void main() {
vec3 c = texture(uTex, vUv).rgb;
float l = max(c.r, max(c.g, c.b));
o = vec4(c * smoothstep(0.6, 1.1, l), 1.0);
}`;
const COMPOSITE = `#version 300 es
precision mediump float;
uniform sampler2D uScene, uBloom, uWide; uniform float uGlow, uTime; in vec2 vUv; out vec4 o;
float h(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
void main() {
vec3 sc = texture(uScene, vUv).rgb;
vec3 bl = texture(uBloom, vUv).rgb * 0.6 + texture(uWide, vUv).rgb * 0.4;
vec3 x = sc + bl * uGlow;
vec3 col = x / (1.0 + max(x - 0.8, 0.0) * 1.2);
col += (h(gl_FragCoord.xy + fract(uTime * 7.0) * 91.0) - 0.5) / 255.0;
o = vec4(min(col, vec3(1.0)), 1.0);
}`;
const isReducedMotion = () =>
typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function rgb(hex: string): [number, number, number] {
let h = hex.replace("#", "");
if (h.length === 3) h = h.replace(/./g, (c) => c + c);
const n = parseInt(h, 16) || 0;
return [((n >> 16) & 255) / 255, ((n >> 8) & 255) / 255, (n & 255) / 255];
}
const FONT = (px: number) =>
`500 ${px}px "Songti SC", "STSong", "SimSun", "Noto Serif CJK SC", "Source Han Serif SC", "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", serif`;
/** True when the device can draw the characters (no blank or tofu boxes). */
function canDraw(sample: string) {
const c = document.createElement("canvas");
c.width = c.height = 32;
const x = c.getContext("2d", { willReadFrequently: true });
if (!x) return false;
const shot = (ch: string) => {
x.clearRect(0, 0, 32, 32);
x.font = FONT(26);
x.fillStyle = "#fff";
x.textBaseline = "middle";
x.fillText(ch, 2, 16);
return x.getImageData(0, 0, 32, 32).data.join(",");
};
const missing = shot("");
const a = shot(sample[0]), b = shot(sample[1] ?? sample[0]);
return a !== missing && b !== missing && a !== b;
}
export function Inscription({
color = "#9a9ca3",
highlight = "#f7f1e6",
accent = "#ff4d1f",
background = "#050505",
glyphs = DEFAULT_GLYPHS,
size = 20,
intensity = 1,
speed = 1,
glow = 0.8,
interactive = true,
scroller,
children,
className,
}: InscriptionProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ color, highlight, accent, background, intensity, speed, glow, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { color, highlight, accent, background, intensity, speed, glow, interactive };
redraw.current?.();
}, [color, highlight, accent, background, intensity, speed, glow, interactive]);
const glyphsRef = useRef(glyphs);
const setGlyphs = useRef<(() => void) | null>(null);
useEffect(() => {
glyphsRef.current = glyphs;
setGlyphs.current?.();
}, [glyphs]);
const sizeRef = useRef(size);
const setSize = useRef<(() => void) | null>(null);
useEffect(() => {
sizeRef.current = size;
setSize.current?.();
}, [size]);
useEffect(() => {
const host = hostRef.current;
if (!host) return;
if (getComputedStyle(host).position === "static") host.style.position = "relative";
const still = isReducedMotion();
const canvas = document.createElement("canvas");
canvas.setAttribute("aria-hidden", "true");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:pan-y;";
host.prepend(canvas);
const gl = canvas.getContext("webgl2", { alpha: false, antialias: false, powerPreference: "high-performance" });
if (!gl) {
const p = props.current;
host.style.background = `radial-gradient(90% 70% at 50% 30%, ${p.color}1f, transparent 70%), ${p.background}`;
canvas.remove();
return;
}
const build = (fs: string) => {
const pr = gl.createProgram()!;
for (const [type, src] of [
[gl.VERTEX_SHADER, QUAD],
[gl.FRAGMENT_SHADER, fs],
] as const) {
const sh = gl.createShader(type)!;
gl.shaderSource(sh, src);
gl.compileShader(sh);
if (!gl.getShaderParameter(sh, gl.COMPILE_STATUS)) console.error(gl.getShaderInfoLog(sh));
gl.attachShader(pr, sh);
}
gl.bindAttribLocation(pr, 0, "aQ");
gl.linkProgram(pr);
if (!gl.getProgramParameter(pr, gl.LINK_STATUS)) console.error(gl.getProgramInfoLog(pr));
return pr;
};
const sceneProg = build(SCENE);
const blurProg = build(BLUR);
const brightProg = build(BRIGHT);
const compProg = build(COMPOSITE);
const uni = (pr: WebGLProgram, names: string[]) =>
Object.fromEntries(names.map((n) => [n, gl.getUniformLocation(pr, n)])) as Record<string, WebGLUniformLocation | null>;
const US = uni(sceneProg, [
"uRes", "uMouse", "uDpr", "uTime", "uCs", "uDrift", "uScroll", "uIntro", "uHover", "uScale", "uCount", "uCols", "uLevel",
"uColor", "uHi", "uAcc", "uBg", "uP", "uQ", "uWave", "uAtlas", "uColTex",
]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uGlow", "uTime"]);
const vao = gl.createVertexArray();
gl.bindVertexArray(vao);
gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
gl.enableVertexAttribArray(0);
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 0, 0);
const drawQuad = () => gl.drawArrays(gl.TRIANGLES, 0, 3);
// ---- glyph atlas: white characters, mipmapped ----
const atlasTex = gl.createTexture()!;
let count = 1;
const buildAtlas = () => {
let chars = Array.from(new Set(Array.from(glyphsRef.current.replace(/\s/g, "")))).slice(0, ATLAS_N * ATLAS_N);
if (chars.length < 2 || !canDraw(chars.join(""))) chars = Array.from(LATIN);
count = chars.length;
const c = document.createElement("canvas");
c.width = c.height = ATLAS_N * CELL;
const x = c.getContext("2d")!;
x.fillStyle = "#000";
x.fillRect(0, 0, c.width, c.height);
x.fillStyle = "#fff";
x.textAlign = "center";
x.textBaseline = "middle";
x.font = FONT(CELL * 0.8);
chars.forEach((g, i) => x.fillText(g, (i % ATLAS_N + 0.5) * CELL, (Math.floor(i / ATLAS_N) + 0.53) * CELL));
gl.bindTexture(gl.TEXTURE_2D, atlasTex);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, c);
gl.generateMipmap(gl.TEXTURE_2D);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_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);
};
buildAtlas();
// ---- render targets ----
type Target = { fb: WebGLFramebuffer; tex: WebGLTexture; w: number; h: number };
const target = (tw: number, th: number): Target => {
const tex = gl.createTexture()!;
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.RGBA, tw, th, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
const fb = gl.createFramebuffer()!;
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
return { fb, tex, w: tw, h: th };
};
let T: { scene: Target; a: Target; b: Target; c: Target; d: Target } | null = null;
const freeTargets = () => {
if (!T) return;
for (const t of Object.values(T)) {
gl.deleteFramebuffer(t.fb);
gl.deleteTexture(t.tex);
}
T = null;
};
// ---- columns: each drifts at its own speed and sits at its own depth for scroll ----
const colTex = gl.createTexture()!;
let cols = 1, cs = 20, scale = 1;
let colData = new Float32Array(2);
const layout = () => {
scale = Math.max(0.75, Math.min(1, w / 1100));
cs = Math.max(10, sizeRef.current) * scale;
cols = Math.ceil(w / cs);
colData = new Float32Array(cols * 2);
for (let i = 0; i < cols; i++) {
colData[i * 2] = 0.35 + Math.random() * 0.9; // drift multiplier
colData[i * 2 + 1] = 0.3 + Math.random() * 0.9; // scroll depth
}
gl.bindTexture(gl.TEXTURE_2D, colTex);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
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.RG32F, cols, 1, 0, gl.RG, gl.FLOAT, colData);
for (const ph of phrases) ph.on = 0;
};
// ---- phrases being written ----
type Phrase = { col: number; row: number; len: number; t: number; rate: number; hold: number; tint: number; on: number };
const phrases: Phrase[] = Array.from({ length: MAXP }, () => ({ col: 0, row: 0, len: 0, t: 0, rate: 1, hold: 0, tint: 0, on: 0 }));
const pBuf = new Float32Array(MAXP * 4), qBuf = new Float32Array(MAXP * 4);
const t0 = performance.now();
const clock = () => (still ? 40 : (performance.now() - t0) / 1000);
const s = { intro: still ? 1 : 0, mx: -9999, my: -9999, hover: 0, scroll: 0, boost: 0 };
let drift = 0;
const colOff = (c: number) => drift * colData[c * 2] + s.scroll * colData[c * 2 + 1];
const cellAt = (x: number, y: number) => {
const c = Math.max(0, Math.min(cols - 1, Math.floor(x / cs)));
return { c, r: Math.floor((y + colOff(c)) / cs) };
};
const ended = (ph: Phrase, now: number) => !ph.on || now > ph.t + ph.len / ph.rate + ph.hold + 1.9;
const write = (c: number, r: number, len: number, rate: number, hold: number, tint: number, now: number) => {
if (c < 0 || c >= cols) return;
// never overlap a phrase already alive in this column
for (const ph of phrases) if (!ended(ph, now) && ph.col === c && r < ph.row + ph.len + 1 && r + len + 1 > ph.row) return;
let slot = phrases.find((ph) => ended(ph, now));
if (!slot) slot = phrases.reduce((a, b) => (a.t < b.t ? a : b));
Object.assign(slot, { col: c, row: r, len, t: now, rate, hold, tint, on: 1 });
};
const writeRandom = (now: number) => {
const c = Math.floor(Math.random() * cols);
const len = 3 + Math.floor(Math.random() * 6);
const rowsVis = Math.floor(h / cs);
const top = Math.floor(colOff(c) / cs);
const r = top + 1 + Math.floor(Math.random() * Math.max(1, rowsVis - len - 2));
write(c, r, len, 4 + Math.random() * 4, 2.2 + Math.random() * 2.5, Math.random() < 0.16 ? 1 : 0, now);
};
const waves: { x: number; y: number; t: number; s: number }[] = [];
const waveBuf = new Float32Array(MAXW * 4);
let w = 1, h = 1, dpr = 1;
const resize = () => {
dpr = Math.min(window.devicePixelRatio || 1, 1.75);
const nw = Math.max(1, host.clientWidth), nh = Math.max(1, host.clientHeight);
const changed = nw !== w || nh !== h;
w = nw;
h = nh;
canvas.width = Math.round(w * dpr);
canvas.height = Math.round(h * dpr);
const sw = canvas.width, sh = canvas.height;
freeTargets();
T = {
scene: target(sw, sh),
a: target(Math.max(1, sw >> 2), Math.max(1, sh >> 2)),
b: target(Math.max(1, sw >> 2), Math.max(1, sh >> 2)),
c: target(Math.max(1, sw >> 4), Math.max(1, sh >> 4)),
d: target(Math.max(1, sw >> 4), Math.max(1, sh >> 4)),
};
if (changed) layout();
};
resize();
const blurPass = (src: Target, dst: Target, dx: number, dy: number) => {
gl.bindFramebuffer(gl.FRAMEBUFFER, dst.fb);
gl.viewport(0, 0, dst.w, dst.h);
gl.useProgram(blurProg);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, src.tex);
gl.uniform1i(UB.uTex, 0);
gl.uniform2f(UB.uStep, dx / src.w, dy / src.h);
drawQuad();
};
const draw = () => {
if (!T) return;
const p = props.current;
const X = T;
const now = clock();
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.useProgram(sceneProg);
gl.uniform2f(US.uRes, w, h);
gl.uniform2f(US.uMouse, s.mx, s.my);
gl.uniform1f(US.uDpr, dpr);
gl.uniform1f(US.uTime, now);
gl.uniform1f(US.uCs, cs);
gl.uniform1f(US.uDrift, drift);
gl.uniform1f(US.uScroll, s.scroll);
gl.uniform1f(US.uIntro, s.intro);
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uScale, scale);
gl.uniform1f(US.uCount, count);
gl.uniform1f(US.uCols, cols);
gl.uniform1f(US.uLevel, Math.max(0, Math.min(1.6, p.intensity)));
gl.uniform3fv(US.uColor, rgb(p.color));
gl.uniform3fv(US.uHi, rgb(p.highlight));
gl.uniform3fv(US.uAcc, rgb(p.accent));
gl.uniform3fv(US.uBg, rgb(p.background));
phrases.forEach((ph, i) => {
pBuf.set([ph.col, ph.row, ph.len, ph.t], i * 4);
qBuf.set([ph.rate, ph.hold, ph.tint, ph.on], i * 4);
});
gl.uniform4fv(US.uP, pBuf);
gl.uniform4fv(US.uQ, qBuf);
waveBuf.fill(0);
waves.forEach((v, i) => waveBuf.set([v.x, v.y, v.t, v.s], i * 4));
gl.uniform4fv(US.uWave, waveBuf);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, atlasTex);
gl.uniform1i(US.uAtlas, 0);
gl.activeTexture(gl.TEXTURE1);
gl.bindTexture(gl.TEXTURE_2D, colTex);
gl.uniform1i(US.uColTex, 1);
drawQuad();
gl.bindFramebuffer(gl.FRAMEBUFFER, X.a.fb);
gl.viewport(0, 0, X.a.w, X.a.h);
gl.useProgram(brightProg);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, X.scene.tex);
gl.uniform1i(UR.uTex, 0);
drawQuad();
blurPass(X.a, X.b, 1, 0);
blurPass(X.b, X.a, 0, 1);
blurPass(X.a, X.c, 1, 0);
blurPass(X.c, X.d, 0, 1);
blurPass(X.d, X.c, 1.8, 0);
blurPass(X.c, X.d, 0, 1.8);
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
gl.viewport(0, 0, canvas.width, canvas.height);
gl.useProgram(compProg);
[X.scene.tex, X.a.tex, X.d.tex].forEach((tex, i) => {
gl.activeTexture(gl.TEXTURE0 + i);
gl.bindTexture(gl.TEXTURE_2D, tex);
});
gl.uniform1i(UC.uScene, 0);
gl.uniform1i(UC.uBloom, 1);
gl.uniform1i(UC.uWide, 2);
gl.uniform1f(UC.uGlow, p.glow);
gl.uniform1f(UC.uTime, now);
drawQuad();
gl.activeTexture(gl.TEXTURE0);
};
setGlyphs.current = () => {
buildAtlas();
draw();
};
setSize.current = () => {
layout();
if (still) for (let i = 0; i < 9; i++) writeRandom(clock() - 6);
draw();
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
if (still) {
// a still page: a handful of phrases already written
for (let i = 0; i < 9; i++) writeRandom(clock() - 6);
draw();
redraw.current = draw;
return () => {
redraw.current = null;
setGlyphs.current = null;
setSize.current = null;
ro.disconnect();
freeTargets();
gl.deleteTexture(atlasTex);
gl.deleteTexture(colTex);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: the wall dissolves in, then the first phrases write themselves ----
const intro = gsap.to(s, { intro: 1, duration: 2.4, ease: "power2.inOut", delay: 0.1 });
let nextWrite = 1.2;
// ---- cursor: a reading light that writes along your path ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.3, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.3, ease: "power3" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.6, ease: "power2.inOut" });
let first = true;
let lastPen = { x: 0, y: 0, t: -1 };
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top };
};
const move = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
if (first) {
gsap.set(s, { mx: p.x, my: p.y });
first = false;
}
mxTo(p.x);
myTo(p.y);
hoverTo(1);
const now = clock();
if (now - lastPen.t > 0.14 && Math.hypot(p.x - lastPen.x, p.y - lastPen.y) > cs * 1.5) {
const { c, r } = cellAt(p.x, p.y);
write(c, r - 1, 3 + Math.floor(Math.random() * 4), 12, 1.4, 0, now);
lastPen = { x: p.x, y: p.y, t: now };
}
};
const leave = () => {
first = true;
hoverTo(0);
};
// ---- click: a ring that rewrites the wall, and seal-red ink around the point ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
const now = clock();
waves.push({ x: p.x, y: p.y, t: now, s: 1 });
if (waves.length > MAXW) waves.shift();
const { c } = cellAt(p.x, p.y);
for (const dc of [0, -2, 2, -4, 4]) {
const cc = c + dc;
if (cc < 0 || cc >= cols) continue;
const r = Math.floor((p.y + colOff(cc)) / cs) - 2 + Math.floor(Math.random() * 3);
write(cc, r, 3 + Math.floor(Math.random() * 4), 9, 2.4, dc === 0 ? 1 : Math.random() < 0.5 ? 1 : 0, now + Math.abs(dc) * 0.06);
}
gsap.fromTo(s, { boost: 3 }, { boost: 0, duration: 1.4, ease: "power3.out", overwrite: "auto" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: the columns slide past each other in depth, faster with scroll speed ----
const scrollTo = gsap.quickTo(s, "scroll", { duration: 1, ease: "power3" });
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
scrollTo((self.progress - 0.5) * h * 0.7);
const v = Math.min(1, Math.abs(self.getVelocity()) / 2500);
if (v * 4 > s.boost) gsap.to(s, { boost: v * 4, duration: 0.25, ease: "power2.out", overwrite: "auto", onComplete: () => void gsap.to(s, { boost: 0, duration: 1.4, ease: "power2.out" }) });
},
});
// ---- loop, only while on screen ----
let visible = true;
let prev = performance.now();
const loop = () => {
const t = performance.now();
const dt = Math.min(0.05, (t - prev) / 1000);
prev = t;
if (!visible) return;
const sp = props.current.speed;
drift += dt * 14 * scale * sp * (1 + s.boost);
const now = clock();
if (now > nextWrite && s.intro > 0.4) {
writeRandom(now);
nextWrite = now + (0.25 + Math.random() * 0.55) / Math.max(0.2, sp) * Math.max(0.6, 900 / Math.max(w, 300));
}
for (let i = waves.length - 1; i >= 0; i--) if (now - waves[i].t > 2.8) waves.splice(i, 1);
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
io.observe(host);
gsap.ticker.add(loop);
redraw.current = null;
return () => {
gsap.ticker.remove(loop);
intro.kill();
st.kill();
io.disconnect();
ro.disconnect();
host.removeEventListener("pointermove", move);
host.removeEventListener("pointerleave", leave);
host.removeEventListener("pointerdown", down);
gsap.killTweensOf(s);
setGlyphs.current = null;
setSize.current = null;
freeTargets();
gl.deleteTexture(atlasTex);
gl.deleteTexture(colTex);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}, [scroller]);
return (
<div ref={hostRef} className={["isolate overflow-hidden", className].filter(Boolean).join(" ")} style={{ background }}>
{children && <div className="relative z-10 h-full">{children}</div>}
</div>
);
}
export default Inscription;
One prompt, any AI agent
Paste into Claude Code, Codex, Cursor or Windsurf. It carries your tweaks and the full source, so the agent installs it exactly.
Props
13 propscolorstringColour of the resting characters.default "#9a9ca3"default "#9a9ca3"highlightstringColour of the written phrases.default "#f7f1e6"default "#f7f1e6"accentstringAccent colour for seal-red phrases and click ink.default "#ff4d1f"default "#ff4d1f"backgroundstringBackground colour.default "#050505"default "#050505"glyphsstringCharacters to build the wall from (up to 256). Falls back to Latin letters if the device has no font for them.default Chinese charactersdefault Chinese characterssizenumberCharacter size in px (scaled down on small screens).default 20default 20intensitynumberHow bright the resting wall is.default 1default 1speednumberSpeed of the drift and the writing.default 1default 1glownumberStrength of the bloom on written phrases.default 0.8default 0.8interactivebooleanReading light, cursor writing, click ring and scroll response.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the wall.classNamestringSize it, e.g. h-screen w-full.