Animations109 / 118
Number Bloom
A flower written in numbers: a real 3D flower opens from a bud, and every frame is redrawn as rolling italic digits whose brightness carries the light. It turns its head toward your cursor, the digits under it scramble, and a click folds it back into a bud before it bursts open again.
three.jsthree.jsDigitsDigitsRender targetRender targetProceduralProceduralSpringsSpringsGSAPGSAP
Move and it turns toward youClick to make it bloom again
Tweak
LIVELIVEDigits
#f2f2f4
6px
1.0×
Usage
Follows your tweaks.
usage.tsx
import { NumberBloom } from "@/components/inreact/number-bloom";
export function Hero() {
return (
<section className="h-[700px] bg-[#1a1a1d]">
<NumberBloom color="#f2f2f4" cell={6} flicker={1} />
</section>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/number-bloom.jsonOr copy the source
Install the dependencies, then save this as components/inreact/number-bloom.tsx.
terminal
npm install gsap threecomponents/inreact/number-bloom.tsx
"use client";
import { gsap } from "gsap";
import { useEffect, useRef } from "react";
import * as THREE from "three";
/**
* Number Bloom: a flower written in numbers. A real 3D flower opens from a bud, and every frame
* of it is drawn as a grid of small italic digits whose brightness carries the light.
*
* - The flower is built live in three.js: rings of cupped, curling petals round a seeded heart,
* opening outer ring first with a soft overshoot.
* - Each frame becomes a grid of digits: brightness picks how bright each digit glows, and the
* digits keep rolling like a live readout.
* - The flower turns its head toward the cursor (the stem follows a beat later), and the digits
* under the cursor scramble faster and brighter.
* - Drag to turn it. Click (or Enter / Space): it closes back into a bud, then bursts open again,
* sending a ripple of scrambling digits out through it.
*
* <div className="h-[640px] bg-[#1a1a1d]"><NumberBloom /></div>
*/
export type NumberBloomProps = {
/** Colour of the digits. */
color?: string;
/** Size of each digit cell in CSS pixels, 6 to 16. */
cell?: number;
/** How quickly the digits roll (0 = frozen). */
flicker?: number;
/** Background colour. */
background?: string;
/** Called on each re-bloom. */
onBloom?: () => void;
className?: string;
};
const reduced = () => typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
// ten digits in an italic serif, white on black, side by side
function glyphAtlas() {
const C = 64;
const cv = document.createElement("canvas");
cv.width = C * 10;
cv.height = C;
const x = cv.getContext("2d")!;
x.fillStyle = "#000";
x.fillRect(0, 0, cv.width, cv.height);
x.fillStyle = "#fff";
x.textAlign = "center";
x.textBaseline = "middle";
x.font = `italic 400 ${C * 0.86}px Georgia, "Times New Roman", serif`;
for (let i = 0; i < 10; i++) x.fillText(String(i), i * C + C / 2, C * 0.54);
return cv;
}
const PETAL_VERT = /* glsl */ `
attribute vec3 aPet; // ring (0 inner .. 1 outer), angle round the head, random
uniform float uBloom;
uniform float uT;
varying vec3 vN;
varying float vV;
varying float vU;
varying float vRing;
const float PI = 3.14159265;
mat3 rotX(float a){ float c = cos(a), s = sin(a); return mat3(1.0, 0.0, 0.0, 0.0, c, s, 0.0, -s, c); }
mat3 rotY(float a){ float c = cos(a), s = sin(a); return mat3(c, 0.0, -s, 0.0, 1.0, 0.0, s, 0.0, c); }
vec3 petal(vec2 uv){
float ring = aPet.x;
// outer rings open first; inner ones follow, still cupped round the heart
float open = clamp(uBloom * 1.35 - (1.0 - ring) * 0.35, 0.0, 1.25);
float u = uv.x - 0.5, v = uv.y;
float L = mix(0.3, 0.62, ring) * (0.88 + 0.24 * aPet.z) * mix(0.72, 1.0, min(open, 1.0));
float W = mix(0.075, 0.13, ring) * (0.9 + 0.2 * aPet.z);
float w = W * pow(sin(PI * min(v, 0.999) * 0.98 + 0.04), 0.75) * (1.0 - 0.35 * v); // pointed tip
float cup = -(u * u) * 4.0 * w * mix(0.5, 0.25, open); // cupped across its width
vec3 p = vec3(u * w * 2.0, v * L, cup);
// curl: open petals arch outward along their length
p = rotX(-v * mix(0.05, 0.4, ring) * open) * p; // the tips lift back up a little
// pitch: from hugging the bud to spread wide
float pitch = mix(0.08 + 0.04 * ring, mix(0.32, 1.42, ring * ring * (3.0 - 2.0 * ring)), open);
p = rotX(pitch) * p;
p.z += mix(0.015, 0.08, ring) * (0.4 + 0.6 * min(open, 1.0)); // the base sits out on the heart
p = rotY(aPet.y) * p;
// a whisper of breeze
p.y += sin(uT * 1.3 + aPet.y * 3.0 + ring * 2.0) * 0.006 * ring;
return p;
}
void main(){
vec3 p = petal(uv);
vec3 pa = petal(uv + vec2(0.01, 0.0));
vec3 pb = petal(uv + vec2(0.0, 0.01));
vec3 n = normalize(cross(pa - p, pb - p));
vN = normalize(normalMatrix * n);
vV = uv.y;
vU = uv.x - 0.5;
vRing = aPet.x;
gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
}`;
const SHADE_FRAG = /* glsl */ `
uniform float uBase;
varying vec3 vN;
varying float vV;
varying float vU;
varying float vRing;
void main(){
vec3 n = normalize(vN);
if (!gl_FrontFacing) n = -n;
vec3 L = normalize(vec3(-0.35, 0.65, 0.7));
// petals are thin: lit from behind they still glow a little
float key = max(max(0.0, dot(n, L)), 0.45 * max(0.0, -dot(n, L)));
float rim = pow(1.0 - abs(n.z), 2.0);
float l = uBase + 0.95 * key * (0.45 + 0.55 * vV) + 0.4 * rim * vV;
// each petal reads on its own: bright along its middle and tip, falling dark at its edges and base
l *= mix(0.06, 1.0, smoothstep(0.48, 0.12, abs(vU))) * mix(0.3, 1.0, smoothstep(0.0, 0.3, vV));
l *= mix(0.6, 1.0, vRing) * 1.3;
gl_FragColor = vec4(vec3(l), 1.0);
}`;
const ASCII_FRAG = /* glsl */ `
uniform sampler2D uScene;
uniform sampler2D uGlyph;
uniform vec2 uRes;
uniform float uCell;
uniform float uT;
uniform float uRate;
uniform vec2 uMouse;
uniform float uMouseAmt;
uniform vec3 uColor;
uniform vec3 uBack;
uniform vec3 uRip; // centre (px), age
float hash(vec2 p){ return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453); }
void main(){
vec2 cell = floor(gl_FragCoord.xy / uCell);
vec2 cpx = (cell + 0.5) * uCell;
float l = dot(texture2D(uScene, cpx / uRes).rgb, vec3(0.33));
// the cursor stirs the digits under it; a click sends a ring of stirring outward
float dm = length(cpx - uMouse) / uCell;
float near = exp(-dm * dm / 90.0) * uMouseAmt;
float dr = length(cpx - uRip.xy) / uCell - uRip.z * 70.0;
float ring = exp(-dr * dr / 18.0) * exp(-uRip.z * 1.6);
float stir = near + ring;
float h = hash(cell);
float rate = uRate * (0.6 + 1.2 * h) + stir * 14.0;
float g = floor(hash(cell + floor(uT * rate + h * 17.0) * 0.731) * 10.0);
vec2 inC = fract(gl_FragCoord.xy / uCell);
// brighter digits are drawn larger, dim ones small: the light reads as size as well as glow
inC = (inC - 0.5) * mix(1.35, 0.95, smoothstep(0.1, 0.6, l)) + 0.5;
float a = 0.0;
if (all(greaterThan(inC, vec2(0.0))) && all(lessThan(inC, vec2(1.0)))) a = texture2D(uGlyph, vec2((g + inC.x) / 10.0, inC.y)).r;
float vis = smoothstep(0.05, 0.14, l);
float b = vis * (0.45 + 2.6 * l) * (1.0 + 0.7 * stir);
gl_FragColor = vec4(mix(uBack, uColor, clamp(a * b, 0.0, 1.0)), 1.0);
}`;
export function NumberBloom({ color = "#f2f2f4", cell = 6, flicker = 1, background = "#1a1a1d", onBloom, className }: NumberBloomProps) {
const rootRef = useRef<HTMLDivElement>(null);
const live = useRef({ flicker, onBloom });
live.current = { flicker, onBloom };
useEffect(() => {
const root = rootRef.current;
if (!root) return;
const still = reduced();
const canvas = document.createElement("canvas");
canvas.style.cssText = "position:absolute;inset:0;width:100%;height:100%;display:block;";
root.appendChild(canvas);
let renderer: THREE.WebGLRenderer;
try {
renderer = new THREE.WebGLRenderer({ canvas, antialias: false, alpha: false, powerPreference: "high-performance" });
} catch {
canvas.remove();
return;
}
const dpr = Math.min(2, window.devicePixelRatio || 1);
renderer.setPixelRatio(dpr);
// ---- the flower (rendered in grey, to a target the digits read from) ----
const scene = new THREE.Scene();
scene.background = new THREE.Color(0, 0, 0);
const uni = { uBloom: { value: still ? 1 : 0 }, uT: { value: 0 }, uBase: { value: 0.1 } };
const RINGS = 10;
const per: number[] = [];
for (let r = 0; r < RINGS; r++) per.push(Math.round(10 + r * 1.8));
const N = per.reduce((a, b) => a + b, 0);
const petalGeo = new THREE.InstancedBufferGeometry();
const plane = new THREE.PlaneGeometry(1, 1, 8, 14);
plane.translate(0.5, 0.5, 0); // uv and position both 0..1
petalGeo.index = plane.index;
petalGeo.setAttribute("position", plane.attributes.position);
petalGeo.setAttribute("uv", plane.attributes.uv);
const aPet = new Float32Array(N * 3);
let k = 0;
for (let r = 0; r < RINGS; r++)
for (let j = 0; j < per[r]; j++) {
aPet.set([r / (RINGS - 1), (j / per[r]) * Math.PI * 2 + r * 0.41, Math.random()], k * 3);
k++;
}
petalGeo.setAttribute("aPet", new THREE.InstancedBufferAttribute(aPet, 3));
petalGeo.instanceCount = N;
const petalMat = new THREE.ShaderMaterial({ uniforms: uni, vertexShader: PETAL_VERT, fragmentShader: SHADE_FRAG, side: THREE.DoubleSide });
const petals = new THREE.Mesh(petalGeo, petalMat);
petals.frustumCulled = false;
const solid = (base: number) =>
new THREE.ShaderMaterial({
uniforms: { uBase: { value: base } },
vertexShader: "varying vec3 vN; varying float vV; varying float vU; varying float vRing;\nvoid main(){ vN = normalize(normalMatrix * normal); vV = 0.6; vU = 0.0; vRing = 1.0; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }",
fragmentShader: SHADE_FRAG,
});
// the heart: a small seeded dome
const heartGeo = new THREE.SphereGeometry(0.1, 32, 16);
const hp = heartGeo.attributes.position as THREE.BufferAttribute;
for (let i = 0; i < hp.count; i++) {
const v = new THREE.Vector3().fromBufferAttribute(hp, i);
v.y *= 0.55;
v.multiplyScalar(1 + 0.08 * Math.sin(v.x * 90) * Math.sin(v.z * 90));
hp.setXYZ(i, v.x, v.y + 0.03, v.z);
}
heartGeo.computeVertexNormals();
const heartMat = solid(0.16);
const heart = new THREE.Mesh(heartGeo, heartMat);
// the stem: a long, gently curving stalk
const stemCurve = new THREE.CatmullRomCurve3([new THREE.Vector3(0.02, -2.2, 0), new THREE.Vector3(-0.03, -1.4, 0.02), new THREE.Vector3(0.015, -0.6, 0), new THREE.Vector3(0, -0.02, 0)]);
const stemGeo = new THREE.TubeGeometry(stemCurve, 40, 0.028, 10, false);
const stemMat = solid(0.12);
const stem = new THREE.Mesh(stemGeo, stemMat);
// rig: base (sways, turns) > stem > head pivot (turns toward the cursor a beat later)
const base = new THREE.Group();
const head = new THREE.Group();
head.add(petals, heart);
head.scale.setScalar(1.7);
base.add(stem, head);
scene.add(base);
base.position.y = 0.05;
const camera = new THREE.PerspectiveCamera(30, 1, 0.1, 50);
const target = new THREE.WebGLRenderTarget(4, 4, { samples: 4 });
// ---- the digits ----
const atlas = new THREE.CanvasTexture(glyphAtlas());
atlas.minFilter = THREE.LinearMipmapLinearFilter;
atlas.anisotropy = 4;
const bg = new THREE.Color(background), fg = new THREE.Color(color);
const ascii = new THREE.ShaderMaterial({
uniforms: {
uScene: { value: target.texture },
uGlyph: { value: atlas },
uRes: { value: new THREE.Vector2(1, 1) },
uCell: { value: cell },
uT: { value: 0 },
uRate: { value: 1.5 },
uMouse: { value: new THREE.Vector2(-9999, -9999) },
uMouseAmt: { value: 0 },
uColor: { value: new THREE.Vector3(fg.r, fg.g, fg.b) },
uBack: { value: new THREE.Vector3(bg.r, bg.g, bg.b) },
uRip: { value: new THREE.Vector3(0, 0, 9) },
},
vertexShader: "void main(){ gl_Position = vec4(position.xy, 0.0, 1.0); }",
fragmentShader: ASCII_FRAG,
depthTest: false,
depthWrite: false,
});
const quadScene = new THREE.Scene();
const quad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), ascii);
quad.frustumCulled = false;
quadScene.add(quad);
const quadCam = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
let W = 0, H = 0;
const resize = () => {
const w = root.clientWidth, h = root.clientHeight;
if (w < 2 || h < 2 || (w === W && h === H)) return;
W = w;
H = h;
renderer.setSize(W, H, false);
target.setSize(Math.round(W * dpr), Math.round(H * dpr));
ascii.uniforms.uRes.value.set(W * dpr, H * dpr);
// the digits scale with the stage, so a small card still draws the flower in fine detail
ascii.uniforms.uCell.value = Math.max(3, Math.max(6, Math.min(16, cell)) * Math.min(1, Math.min(W, H) / 640)) * dpr;
camera.aspect = W / H;
// fit the open flower and its stem
const t = Math.tan(THREE.MathUtils.degToRad(15));
const spanH = 2.9, spanW = 2.0;
camera.position.set(0, 0, Math.max(spanH / (2 * t), spanW / (2 * t * camera.aspect)));
camera.lookAt(0, 0, 0);
camera.updateProjectionMatrix();
};
resize();
const ro = new ResizeObserver(resize);
ro.observe(root);
// ---- motion ----
type Spring = { x: number; v: number; t: number; k: number; c: number };
const sp = (x: number, k: number, c: number): Spring => ({ x, v: 0, t: x, k, c });
const step = (s: Spring, dt: number) => {
const h = dt / 2;
for (let i = 0; i < 2; i++) {
s.v += (s.k * (s.t - s.x) - s.c * s.v) * h;
s.x += s.v * h;
}
};
const bloom = sp(still ? 1 : 0, 9, 4.2); // soft, with an overshoot as it opens
const leanX = sp(0, 20, 6), leanY = sp(0, 20, 6); // the stem leans
const headX = sp(0, 30, 5.5), headY = sp(0, 30, 5.5); // the head follows a beat later, overshooting a touch
const mouseAmt = sp(0, 30, 9);
let yaw = 0, yawV = still ? 0 : 0.15;
let pointer: { x: number; y: number } | null = null;
let drag: { x: number; t: number; sx: number; sy: number; t0: number; id: number } | null = null;
let busy = false, ripT = 9;
const calls: gsap.core.Tween[] = [];
let t = 0;
if (!still) calls.push(gsap.delayedCall(0.5, () => (bloom.t = 1)));
const rebloom = (px: number, py: number) => {
if (busy) return;
busy = true;
live.current.onBloom?.();
if (still) {
busy = false;
return;
}
// anticipation: it folds back into a bud
bloom.k = 30;
bloom.c = 9;
bloom.t = 0.12;
calls.push(
gsap.delayedCall(0.5, () => {
// and bursts open again, a ring of stirring digits racing out from where you clicked
bloom.k = 14;
bloom.c = 4;
bloom.t = 1;
ascii.uniforms.uRip.value.set(px * dpr, (H - py) * dpr, 0);
ripT = 0;
}),
gsap.delayedCall(2.2, () => {
bloom.k = 9;
bloom.c = 4.2;
busy = false;
}),
);
};
let visible = true;
const io = new IntersectionObserver(([en]) => (visible = en.isIntersecting), { rootMargin: "80px" });
io.observe(root);
const tick = (_time: number, dms: number) => {
const dt = Math.min(0.05, Math.max(0.001, dms / 1000));
t += dt;
const px = pointer ? (pointer.x / W) * 2 - 1 : 0;
const py = pointer ? -((pointer.y / H) * 2 - 1) : 0;
leanX.t = still ? 0 : -py * 0.1;
leanY.t = still ? 0 : px * 0.08;
headX.t = (still ? 0 : -py * 0.22) + 0.5; // tipped a little toward you, so you see into the bloom
headY.t = still ? 0 : px * 0.32;
mouseAmt.t = pointer && !still ? 1 : 0;
[bloom, leanX, leanY, headX, headY, mouseAmt].forEach((s) => step(s, dt));
if (!drag) yawV += ((still ? 0 : 0.15) - yawV) * (1 - Math.exp(-dt * 0.8));
yaw += yawV * dt;
base.rotation.set(leanX.x + (still ? 0 : Math.sin(t * 0.6) * 0.012), 0, -leanY.x * 0.6 + (still ? 0 : Math.sin(t * 0.45) * 0.015));
head.rotation.set(headX.x, yaw + headY.x, 0, "YXZ");
uni.uBloom.value = Math.max(0, bloom.x);
uni.uT.value = still ? 0 : t;
ripT += dt;
ascii.uniforms.uRip.value.z = ripT;
ascii.uniforms.uT.value = still ? 0 : t;
ascii.uniforms.uRate.value = 1.5 * live.current.flicker;
ascii.uniforms.uMouseAmt.value = Math.max(0, mouseAmt.x);
if (pointer) ascii.uniforms.uMouse.value.set(pointer.x * dpr, (H - pointer.y) * dpr);
if (visible && W) {
renderer.setRenderTarget(target);
renderer.render(scene, camera);
renderer.setRenderTarget(null);
renderer.render(quadScene, quadCam);
}
};
gsap.ticker.add(tick);
const local = (ev: PointerEvent) => {
const r = root.getBoundingClientRect();
return { x: ev.clientX - r.left, y: ev.clientY - r.top };
};
const onMove = (ev: PointerEvent) => {
pointer = local(ev);
if (!drag) return;
const now = performance.now();
const ddt = Math.max(8, now - drag.t) / 1000;
yawV = THREE.MathUtils.lerp(yawV, ((ev.clientX - drag.x) / root.clientWidth / ddt) * 5, 0.5);
drag.x = ev.clientX;
drag.t = now;
};
const onDown = (ev: PointerEvent) => {
if (ev.button !== 0) return;
const now = performance.now();
drag = { x: ev.clientX, t: now, sx: ev.clientX, sy: ev.clientY, t0: now, id: ev.pointerId };
try {
root.setPointerCapture(ev.pointerId);
} catch {
/* synthetic pointers can't be captured */
}
};
const onUp = (ev: PointerEvent) => {
if (!drag) return;
const moved = Math.hypot(ev.clientX - drag.sx, ev.clientY - drag.sy);
const quick = performance.now() - drag.t0 < 450;
try {
root.releasePointerCapture(drag.id);
} catch {
/* not captured */
}
drag = null;
if (moved < 7 && quick) {
const p = local(ev);
rebloom(p.x, p.y);
}
};
const onLeave = () => {
if (!drag) pointer = null;
};
const onKey = (ev: KeyboardEvent) => {
if (ev.key === "Enter" || ev.key === " ") {
ev.preventDefault();
rebloom(W / 2, H * 0.4);
} else if (ev.key === "ArrowLeft" || ev.key === "ArrowRight") {
ev.preventDefault();
yawV += ev.key === "ArrowLeft" ? -1.2 : 1.2;
}
};
root.addEventListener("pointermove", onMove);
root.addEventListener("pointerdown", onDown);
root.addEventListener("pointerup", onUp);
root.addEventListener("pointercancel", onUp);
root.addEventListener("pointerleave", onLeave);
root.addEventListener("keydown", onKey);
return () => {
gsap.ticker.remove(tick);
calls.forEach((c) => c.kill());
io.disconnect();
ro.disconnect();
root.removeEventListener("pointermove", onMove);
root.removeEventListener("pointerdown", onDown);
root.removeEventListener("pointerup", onUp);
root.removeEventListener("pointercancel", onUp);
root.removeEventListener("pointerleave", onLeave);
root.removeEventListener("keydown", onKey);
[petalGeo, plane, heartGeo, stemGeo, quad.geometry].forEach((g) => g.dispose());
[petalMat, heartMat, stemMat, ascii].forEach((m) => m.dispose());
atlas.dispose();
target.dispose();
renderer.dispose();
canvas.remove();
};
}, [color, cell, background]);
return (
<div
ref={rootRef}
tabIndex={0}
role="button"
aria-label="A flower written in numbers. Move to turn it toward you, press to make it bloom again."
className={["relative h-full min-h-[280px] w-full cursor-grab touch-none overflow-hidden outline-none select-none active:cursor-grabbing", className].filter(Boolean).join(" ")}
style={{ background }}
/>
);
}
export default NumberBloom;
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
6 propscolorstringColour of the digits.default "#f2f2f4"default "#f2f2f4"cellnumberSize of each digit cell in CSS pixels, 6 to 16.default 6default 6flickernumberHow quickly the digits roll (0 = frozen).default 1default 1backgroundstringBackground colour.default "#1a1a1d"default "#1a1a1d"onBloom() => voidCalled on each re-bloom.classNamestringExtra classes (it fills its parent).