Jelly Grid
A wall of glossy black silicone pillows. A tight grid of soft, rounded tiles in deep black, each a gently domed pillow with a steep rounded edge that catches a thin rim of studio light, brightest along the top, while faint smudgy reflections drift across the faces and the gaps fall to pure black. Every tile is a soft-body spring coupled to its neighbours: your cursor presses into the tile beneath it, leaving a dent that follows you, nudges the neighbours aside so they tilt away and drags them in a wobbling wake, and every press ripples outward through the grid. The tiles are gel that carries light: a pressed tile glows from inside in a drifting gradient of cobalt, violet and rose with slow caustics, the light spills into the gaps and seeps into the tiles around it, then fades. A small lamp slides its highlight across the gloss. A click sends a coloured squash-and-rebound wave rolling across the grid, idle heartbeats light a tile here and there, scrolling sets the rows wobbling, and on load the tiles pop in with an elastic overshoot. Everything overshoots a little and settles, like jelly.
Tweak
LIVELIVEColour
Tiles
Motion
Interactive
Press and drag the jelly, click for a squash wave
Usage
Follows your tweaks.
import { JellyGrid } from "@/components/inreact/jelly-grid";
export function Hero() {
return (
<JellyGrid
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the grid */}
</JellyGrid>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/jelly-grid.jsonOr copy the source
Install the dependencies, then save this as components/inreact/jelly-grid.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);
/**
* Jelly Grid: a wall of glossy black silicone pillows that squish like jelly.
*
* A tight grid of soft, rounded tiles in deep black, each a gently domed
* pillow with a steep rounded edge. Their edges catch thin rims of studio
* light (brightest along the top), their faces carry faint smudgy reflections,
* and the gaps fall to pure black.
*
* Every tile is a soft-body spring. Your cursor presses into the tile beneath
* it, leaving a dent that follows you, nudges the neighbours aside and drags
* them in a wobbling wake as you move, while a small lamp slides its
* highlight across the gloss. Tiles are coupled to their neighbours, so every
* press ripples outward through the grid. They are also gel that carries light:
* a pressed tile lights from inside in a slowly drifting gradient (cobalt,
* violet, rose by default) with moving caustics, the light spills into the
* gaps and seeps into the tiles around it, then fades. A click sends a
* coloured squash-and-rebound wave across the grid, scrolling sets the rows
* wobbling, idle heartbeats light a tile here and there, and on load the tiles
* pop in with an elastic overshoot. Everything overshoots a little and
* settles, like jelly.
*
* <JellyGrid className="h-screen w-full">
* <YourHero />
* </JellyGrid>
*
* WebGL2: each tile's offset, squash and dent are simulated in JS (underdamped
* springs) and uploaded as a small float texture; one shader draws the
* pillows (rounded-box distance field, analytic normals, studio reflection),
* then a bloom at 1/4 and 1/16 size. GSAP drives cursor, intro and scroll.
* Pauses off-screen; reduced motion shows a still frame; a CSS gradient
* without WebGL2.
*/
export interface JellyGridProps {
/** Colour of the jelly itself (keep it very dark for the glossy black look). */
color?: string;
/** Colour of the reflections and rims. */
sheen?: string;
/** The three colours the gel glows in when it is pressed. */
colors?: [string, string, string];
/** Background colour (the gaps). */
background?: string;
/** Tile size in px (scaled down on small screens). */
size?: number;
/** How soft and wobbly the tiles are, 0 to 1. */
softness?: number;
/** Calms the centre so a headline on top stays readable, 0 to 1. */
focus?: number;
/** Speed of the idle breathing and drifting reflections. */
speed?: number;
/** Strength of the glow and bloom. */
glow?: number;
/** Press, drag, click wave, scroll wobble. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the grid. */
children?: ReactNode;
className?: string;
}
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, uOff, uGrid, uMouse; // css px, top-left origin
uniform float uDpr, uTime, uCell, uHover, uFocus, uLamp;
uniform vec3 uJelly, uSheen, uBg, uA, uB, uC;
uniform float uGlowAmt;
uniform highp sampler2D uState; // per tile, two texels: (offX, offY, sx, sy) and (press, dentX, dentY, light)
in vec2 vUv;
out vec4 o;
float h21(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
float noise(vec2 p) {
vec2 i = floor(p), f = fract(p);
f = f * f * (3.0 - 2.0 * f);
return mix(mix(h21(i), h21(i + vec2(1, 0)), f.x), mix(h21(i + vec2(0, 1)), h21(i + vec2(1, 1)), f.x), f.y);
}
float sdBox(vec2 p, vec2 b, float r) {
vec2 q = abs(p) - b + r;
return length(max(q, 0.0)) + min(max(q.x, q.y), 0.0) - r;
}
// outward direction of the rounded box at p
vec2 boxDir(vec2 p, vec2 b, float r) {
vec2 q = abs(p) - b + r;
vec2 g = (q.x > 0.0 || q.y > 0.0) ? normalize(max(q, 0.0)) : (q.x > q.y ? vec2(1.0, 0.0) : vec2(0.0, 1.0));
return g * sign(p);
}
vec3 pal(float t) {
t = fract(t) * 3.0;
return t < 1.0 ? mix(uA, uB, smoothstep(0.0, 1.0, t)) : t < 2.0 ? mix(uB, uC, smoothstep(1.0, 2.0, t)) : mix(uC, uA, smoothstep(2.0, 3.0, t));
}
// the studio the gloss reflects: a softbox overhead, two dim side strips, a faint floor,
// and smudgy grey reflections that drift across each face
vec3 studio(vec2 r) {
// narrow lights, so the steep edges catch thin, crisp lines instead of a grey band
float top = exp(-pow((r.y + 0.96) / 0.1, 2.0)) * 3.0;
float sides = exp(-pow((abs(r.x) - 0.95) / 0.1, 2.0)) * 4.2;
float floorB = exp(-pow((r.y - 0.96) / 0.09, 2.0)) * 2.4;
return uSheen * (top + sides + floorB);
}
void main() {
vec2 p = vec2(gl_FragCoord.x, uRes.y * uDpr - gl_FragCoord.y) / uDpr;
vec2 g = (p - uOff) / uCell;
vec2 base = floor(g);
float half_ = uCell * 0.485;
float rad = uCell * 0.24;
// tiles can slide and swell a little, so look at the neighbours too and take the one we are inside
float bestD = 1e9;
vec2 bq = vec2(0.0), bs = vec2(1.0), bdent = vec2(0.0);
float bpress = 0.0, bid = 0.0, blight = 0.0;
vec2 boff = vec2(0.0), bcell = vec2(0.0);
// light spilling into the gaps, gathered smoothly from every nearby tile (no seams between cells)
vec3 spillAcc = vec3(0.0);
for (int j = -1; j <= 1; j++)
for (int i = -1; i <= 1; i++) {
vec2 id = base + vec2(float(i), float(j));
if (id.x < 0.0 || id.y < 0.0 || id.x >= uGrid.x || id.y >= uGrid.y) continue;
ivec2 tx = ivec2(int(id.x) * 2, int(id.y));
vec4 A = texelFetch(uState, tx, 0);
if (A.z < 0.02) continue;
vec2 c = uOff + (id + 0.5 + A.xy) * uCell;
vec2 q = (p - c) / A.zw;
float tid = h21(id + 3.3);
vec2 qn = q / uCell;
q += (vec2(noise(qn * 1.8 + tid * 11.0), noise(qn * 1.8 + tid * 23.0 + 5.0)) - 0.5) * uCell * 0.07;
float d = sdBox(q, vec2(half_), rad) * min(A.z, A.w);
float lgt = texelFetch(uState, tx + ivec2(1, 0), 0).w;
if (lgt > 0.003) spillAcc += pal(id.x * 0.055 + id.y * 0.035 + uTime * 0.025) * lgt * exp(-max(d, 0.0) / (uCell * 0.09));
if (d < bestD) {
bestD = d;
bq = q;
bs = A.zw;
vec4 B = texelFetch(uState, tx + ivec2(1, 0), 0);
bpress = B.x;
bdent = B.yz * uCell;
blight = B.w;
boff = A.xy;
bcell = id;
bid = h21(id);
}
}
vec3 col = uBg;
// the glow colour drifts slowly across the grid
vec3 hue = pal(bcell.x * 0.055 + bcell.y * 0.035 + uTime * 0.025);
float aa = 0.9 / uDpr;
float cov = clamp(0.5 - bestD / aa, 0.0, 1.0);
if (cov > 0.0) {
float d = sdBox(bq, vec2(half_), rad);
// the pillow: a steep rounded edge that flattens into a gently domed face
float e = clamp(-d / (uCell * 0.14), 0.0, 1.0);
float slope = pow(1.0 - e, 2.2) * 3.2;
vec2 nxy = boxDir(bq, vec2(half_), rad) * slope;
nxy += bq / half_ * 0.12;
// tiles pushed aside tilt away, so the grid reads in 3D as the jelly moves
nxy += boff * 1.8;
// the dent where the cursor presses
vec2 dv = bq - bdent;
float rD = uCell * 0.32;
float w = exp(-dot(dv, dv) / (rD * rD));
nxy -= bpress * w * dv / (rD * rD) * uCell * 0.16;
vec3 n = normalize(vec3(nxy, 1.0));
// gloss: mirror reflection of the studio, stronger at grazing angles
vec2 rxy = 2.0 * n.z * n.xy;
float fres = 0.04 + 0.96 * pow(1.0 - n.z, 5.0);
vec2 fq0 = bq / uCell;
float streak = 0.25 + 0.95 * smoothstep(0.25, 0.75, noise(fq0 * 5.0 + vec2(bid * 31.0, uTime * 0.06)));
vec3 refl = studio(rxy) * mix(0.2, 1.0, fres) * streak;
// lit gel tints its own rims
refl *= mix(vec3(1.0), hue * 1.3 + 0.3, clamp(blight * 0.7, 0.0, 1.0));
// mottled grey reflections drifting across each face, like the room seen in black gloss
vec2 fq = bq / uCell;
float sm = noise(fq * 2.6 + vec2(bid * 17.0, uTime * 0.05)) * noise(fq * 1.3 - vec2(uTime * 0.035, bid * 9.0));
refl += uSheen * smoothstep(0.1, 0.6, sm) * 0.3 * e;
// the lamp at the cursor is a small light reflected in the gloss: each nearby tile shows a
// crisp little highlight on the side facing the cursor, sliding as you move
vec2 toL = (uMouse - p) / (uCell * 5.0);
vec2 lampDir = toL / (1.0 + length(toL)) * 1.6;
vec2 dl = rxy - lampDir;
float near = exp(-dot(uMouse - p, uMouse - p) / pow(uCell * 3.2, 2.0)) * uHover;
float spec = (exp(-dot(dl, dl) / 0.006) * 1.1 + exp(-dot(dl, dl) / 0.08) * 0.07) * near * uLamp;
vec3 c = uJelly * (0.5 + 0.5 * n.z) + refl + uSheen * spec;
// a soft occlusion where the edge rolls under
c *= mix(0.35, 1.0, smoothstep(0.0, 0.35, e) * 0.6 + 0.4);
// the gel carries light: it glows from inside, strongest under the dent,
// with slow caustics drifting through it like light in jelly
float caus = noise(fq * 3.2 + vec2(uTime * 0.22, bid * 7.0)) * noise(fq * 5.3 - vec2(bid * 3.0, uTime * 0.17));
float body = smoothstep(0.0, 0.9, e) * 0.75 + 0.25;
float gel = blight * body * (0.7 + 0.7 * smoothstep(0.0, 0.6, caus));
c += hue * (gel * 0.85 + blight * bpress * w * 1.1) * uGlowAmt;
col = mix(uBg, c, cov);
}
col += spillAcc * (1.0 - cov) * 0.32 * uGlowAmt;
// a calm centre for headlines: it only dims, never greys
vec2 cc = (p - uRes * 0.5) / (uRes * 0.5);
col *= 1.0 - uFocus * 0.7 * exp(-dot(cc * vec2(1.0, 1.3), cc * vec2(1.0, 1.3)) / 0.3);
col = max(col, uBg);
col += (h21(gl_FragCoord.xy + fract(uTime) * 91.0) - 0.5) / 255.0;
o = vec4(col, 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.7, 1.3, 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.1);
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 DEFAULT_COLORS: [string, string, string] = ["#2b5cff", "#9b5cff", "#ff4d8a"];
export function JellyGrid({
color = "#060607",
sheen = "#f2f3f6",
colors = DEFAULT_COLORS,
background = "#000000",
size = 110,
softness = 0.6,
focus = 0.3,
speed = 1,
glow = 0.9,
interactive = true,
scroller,
children,
className,
}: JellyGridProps) {
const hostRef = useRef<HTMLDivElement>(null);
const [c1, c2, c3] = colors;
const props = useRef({ color, sheen, c1, c2, c3, background, softness, focus, speed, glow, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { color, sheen, c1, c2, c3, background, softness, focus, speed, glow, interactive };
redraw.current?.();
}, [color, sheen, c1, c2, c3, background, softness, focus, speed, glow, interactive]);
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(60% 50% at 30% 20%, ${p.c1}22, transparent 70%), radial-gradient(60% 50% at 80% 80%, ${p.c3}1c, 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", "uOff", "uGrid", "uMouse", "uDpr", "uTime", "uCell", "uHover", "uFocus", "uLamp", "uJelly", "uSheen", "uBg", "uState", "uA", "uB", "uC", "uGlowAmt"]);
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);
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;
};
// ---- tiles: springs for offset, squash and press ----
const stateTex = gl.createTexture()!;
let cols = 1, rows = 1, cell = 92, ox = 0, oy = 0;
// per tile: offset x/y, scale x/y, press, and their velocities; dent position; intro release time
let ox_ = new Float32Array(1), oy_ = new Float32Array(1), vx_ = new Float32Array(1), vy_ = new Float32Array(1);
let sx_ = new Float32Array(1), sy_ = new Float32Array(1), vsx = new Float32Array(1), vsy = new Float32Array(1);
let pr_ = new Float32Array(1), vpr = new Float32Array(1), dx_ = new Float32Array(1), dy_ = new Float32Array(1);
let rel = new Float32Array(1), ph = new Float32Array(1), lt = new Float32Array(1), lapS = new Float32Array(1), lapL = new Float32Array(1);
let buf = new Float32Array(8);
const s = { intro: still ? 1 : 0, mx: -9999, my: -9999, hover: 0, vx: 0, vy: 0, lamp: 1, wobble: 0, wobbleY: 0 };
const layout = () => {
const sc = Math.max(0.62, Math.min(1, w / 1100));
cell = Math.max(40, sizeRef.current) * sc;
cols = Math.ceil(w / cell) + 1;
rows = Math.ceil(h / cell) + 1;
ox = (w - cols * cell) / 2;
oy = (h - rows * cell) / 2;
const n = cols * rows;
const z = () => new Float32Array(n);
ox_ = z(); oy_ = z(); vx_ = z(); vy_ = z();
sx_ = z().fill(still || s.intro >= 1 ? 1 : 0); sy_ = z().fill(still || s.intro >= 1 ? 1 : 0); vsx = z(); vsy = z();
pr_ = z(); vpr = z(); dx_ = z(); dy_ = z();
rel = z(); ph = z(); lt = z(); lapS = z(); lapL = z();
buf = new Float32Array(n * 8);
for (let i = 0; i < n; i++) {
const cx = i % cols, cy = Math.floor(i / cols);
const ddx = (cx + 0.5) / cols - 0.5, ddy = ((cy + 0.5) / rows - 0.5) * (rows / cols);
// pop in from the centre outward
rel[i] = Math.hypot(ddx, ddy) * 1.4 + Math.random() * 0.12;
ph[i] = Math.random() * Math.PI * 2;
}
gl.bindTexture(gl.TEXTURE_2D, stateTex);
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);
pack();
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, cols * 2, rows, 0, gl.RGBA, gl.FLOAT, buf);
};
const pack = () => {
for (let i = 0, n = cols * rows; i < n; i++) {
buf.set([ox_[i], oy_[i], sx_[i], sy_[i], pr_[i], dx_[i], dy_[i], Math.min(1.6, lt[i])], i * 8);
}
};
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 t0 = performance.now();
const clock = () => (still ? 10 : (performance.now() - t0) / 1000);
const waves: { x: number; y: number; t: number; r: number }[] = [];
// ---- simulation: every tile is a soft-body spring that overshoots and settles ----
const step = (dt: number, now: number) => {
const P = props.current;
const soft = Math.max(0, Math.min(1, P.softness));
// softer = lower stiffness and less damping, so the jelly wobbles longer
const K = 260 - soft * 150, C = 16 - soft * 9;
const KP = 220, CP = 20;
const n = cols * rows;
const gate = s.intro * 1.6;
const R1 = cell * 0.62, R2 = cell * 1.7;
const spd = Math.hypot(s.vx, s.vy);
const sub = dt > 1 / 70 ? 2 : 1;
const hdt = dt / sub;
// the click wave: tiles squash then rebound as the ring arrives
for (let k = waves.length - 1; k >= 0; k--) {
const wv = waves[k];
const front = (now - wv.t) * 900;
const inner = wv.r;
wv.r = front;
if (inner > Math.hypot(w, h)) {
waves.splice(k, 1);
continue;
}
for (let i = 0; i < n; i++) {
const cx = ox + ((i % cols) + 0.5) * cell - wv.x, cy = oy + (Math.floor(i / cols) + 0.5) * cell - wv.y;
const d = Math.hypot(cx, cy);
if (d < inner || d >= front) continue;
const fall = Math.exp(-d / (cell * 7));
vx_[i] += (cx / Math.max(d, 1)) * 2.4 * fall;
vy_[i] += (cy / Math.max(d, 1)) * 2.4 * fall;
vsx[i] -= 4.5 * fall;
vsy[i] -= 4.5 * fall;
lt[i] = Math.max(lt[i], 0.7 * Math.exp(-d / (cell * 3.5)));
}
}
// neighbours are coupled: squash and light leak into the tiles around, so presses ripple outward
const COUP = 70 + soft * 70;
for (let i = 0; i < n; i++) {
const cx = i % cols, cy = Math.floor(i / cols);
let ss = 0, ll = 0, m = 0;
if (cx > 0) { ss += sx_[i - 1] + sy_[i - 1]; ll += lt[i - 1]; m++; }
if (cx < cols - 1) { ss += sx_[i + 1] + sy_[i + 1]; ll += lt[i + 1]; m++; }
if (cy > 0) { ss += sx_[i - cols] + sy_[i - cols]; ll += lt[i - cols]; m++; }
if (cy < rows - 1) { ss += sx_[i + cols] + sy_[i + cols]; ll += lt[i + cols]; m++; }
lapS[i] = m ? ss / (2 * m) - (sx_[i] + sy_[i]) / 2 : 0;
lapL[i] = m ? ll / m - lt[i] : 0;
}
// idle heartbeats: now and then a tile softly lights and pulses
if (s.intro >= 1 && Math.random() < dt * 1.4 * Math.max(0.2, P.speed)) {
const i = Math.floor(Math.random() * n);
lt[i] = Math.max(lt[i], 0.55 + Math.random() * 0.35);
vsx[i] -= 1.6;
vsy[i] -= 1.6;
}
for (let i = 0; i < n; i++) {
const cx = i % cols, cy = Math.floor(i / cols);
if (rel[i] > gate) {
sx_[i] = sy_[i] = 0;
vsx[i] = vsy[i] = 0;
continue;
}
const px = ox + (cx + 0.5) * cell, py = oy + (cy + 0.5) * cell;
const ddx = px - s.mx, ddy = py - s.my;
const d2 = ddx * ddx + ddy * ddy;
const d = Math.sqrt(d2) + 1e-3;
const fPress = Math.exp(-d2 / (R1 * R1)) * s.hover;
const fPush = Math.exp(-d2 / (R2 * R2)) * s.hover;
// pushed aside near the cursor, and dragged along behind it like jelly
const tx = (ddx / d) * 0.08 * fPush * (1 - fPress) - s.vx * 0.00013 * fPush;
const ty = (ddy / d) * 0.08 * fPush * (1 - fPress) - s.vy * 0.00013 * fPush;
// a pressed tile spreads a little; a moving cursor stretches its neighbours along the motion
const breathe = 0.008 * Math.sin(now * 1.3 * P.speed + ph[i]);
const stretch = Math.min(0.06, spd * 0.00003) * fPush;
const ax = spd > 1 ? Math.abs(s.vx) / spd : 0.5, ay = spd > 1 ? Math.abs(s.vy) / spd : 0.5;
let tsx = 1 + fPress * 0.035 + breathe + stretch * (ax - ay);
let tsy = 1 + fPress * 0.035 + breathe + stretch * (ay - ax);
if (s.wobble > 0.01) {
const band = Math.exp(-((cy / rows - s.wobbleY) ** 2) / 0.02) * s.wobble;
tsy += band * 0.08 * Math.sin(now * 9 + cx * 0.7);
tsx -= band * 0.04 * Math.sin(now * 9 + cx * 0.7);
}
// the dent follows the cursor inside the pressed tile
dx_[i] = Math.max(-0.32, Math.min(0.32, (s.mx - px) / cell));
dy_[i] = Math.max(-0.32, Math.min(0.32, (s.my - py) / cell));
const tp = fPress * 0.6;
// light: lit by the press, seeps into the neighbours, fades slowly
lt[i] += lapL[i] * 2.2 * dt;
lt[i] = Math.max(lt[i] * Math.exp(-dt * 1.0), fPress * 1.05);
for (let k = 0; k < sub; k++) {
vx_[i] += ((tx - ox_[i]) * K - vx_[i] * C) * hdt;
vy_[i] += ((ty - oy_[i]) * K - vy_[i] * C) * hdt;
ox_[i] += vx_[i] * hdt;
oy_[i] += vy_[i] * hdt;
vsx[i] += ((tsx - sx_[i]) * K - vsx[i] * C + lapS[i] * COUP) * hdt;
vsy[i] += ((tsy - sy_[i]) * K - vsy[i] * C + lapS[i] * COUP) * hdt;
sx_[i] += vsx[i] * hdt;
sy_[i] += vsy[i] * hdt;
vpr[i] += ((tp - pr_[i]) * KP - vpr[i] * CP) * hdt;
pr_[i] += vpr[i] * hdt;
}
ox_[i] = Math.max(-0.2, Math.min(0.2, ox_[i]));
oy_[i] = Math.max(-0.2, Math.min(0.2, oy_[i]));
sx_[i] = Math.max(0, Math.min(1.25, sx_[i]));
sy_[i] = Math.max(0, Math.min(1.25, sy_[i]));
}
};
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();
pack();
gl.bindTexture(gl.TEXTURE_2D, stateTex);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, cols * 2, rows, gl.RGBA, gl.FLOAT, buf);
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.uOff, ox, oy);
gl.uniform2f(US.uGrid, cols, rows);
gl.uniform2f(US.uMouse, s.mx, s.my);
gl.uniform1f(US.uDpr, dpr);
gl.uniform1f(US.uTime, now * p.speed);
gl.uniform1f(US.uCell, cell);
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uFocus, Math.max(0, Math.min(1, p.focus)));
gl.uniform1f(US.uLamp, s.lamp);
gl.uniform3fv(US.uJelly, rgb(p.color));
gl.uniform3fv(US.uSheen, rgb(p.sheen));
gl.uniform3fv(US.uBg, rgb(p.background));
gl.uniform3fv(US.uA, rgb(p.c1));
gl.uniform3fv(US.uB, rgb(p.c2));
gl.uniform3fv(US.uC, rgb(p.c3));
gl.uniform1f(US.uGlowAmt, Math.max(0, Math.min(2.5, p.glow)) * 0.9 + 0.1);
gl.activeTexture(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, stateTex);
gl.uniform1i(US.uState, 0);
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, Math.max(0, p.glow) * 0.6);
gl.uniform1f(UC.uTime, now);
drawQuad();
gl.activeTexture(gl.TEXTURE0);
};
setSize.current = () => {
layout();
draw();
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
if (still) {
draw();
redraw.current = draw;
return () => {
redraw.current = null;
setSize.current = null;
ro.disconnect();
freeTargets();
gl.deleteTexture(stateTex);
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: tiles pop in from the centre outward, overshooting like jelly ----
const intro = gsap.to(s, { intro: 1, duration: 1.8, ease: "power1.inOut", delay: 0.15 });
// ---- cursor: press, push and drag ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.35, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.35, ease: "power3" });
const vxTo = gsap.quickTo(s, "vx", { duration: 0.5, ease: "power2" });
const vyTo = gsap.quickTo(s, "vy", { duration: 0.5, ease: "power2" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.8, ease: "sine.inOut" });
let first = true;
let last = { x: 0, y: 0, t: 0 };
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);
const t = performance.now();
if (first) {
gsap.set(s, { mx: p.x, my: p.y });
first = false;
} else {
const dt = Math.max(8, t - last.t) / 1000;
vxTo(Math.max(-3000, Math.min(3000, (p.x - last.x) / dt)));
vyTo(Math.max(-3000, Math.min(3000, (p.y - last.y) / dt)));
}
last = { x: p.x, y: p.y, t };
mxTo(p.x);
myTo(p.y);
hoverTo(1);
};
const leave = () => {
first = true;
hoverTo(0);
vxTo(0);
vyTo(0);
};
// ---- click: a squash-and-rebound wave, and the lamp swells ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
waves.push({ x: p.x, y: p.y, t: clock(), r: 0 });
if (waves.length > 4) waves.shift();
gsap.killTweensOf(s, "lamp");
gsap.timeline().to(s, { lamp: 1.7, duration: 0.3, ease: "sine.out" }).to(s, { lamp: 1, duration: 1.2, ease: "sine.inOut" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: the rows wobble as the page moves ----
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => {
if (!props.current.interactive) return;
s.wobbleY = self.progress;
const v = Math.min(1, Math.abs(self.getVelocity()) / 2200);
if (v > s.wobble) gsap.to(s, { wobble: v, duration: 0.25, ease: "sine.out", overwrite: "auto", onComplete: () => void gsap.to(s, { wobble: 0, duration: 1.4, ease: "sine.inOut" }) });
},
});
// ---- loop, only while on screen ----
let visible = true;
let prev = performance.now();
const loop = () => {
const t = performance.now();
const dt = Math.min(0.033, (t - prev) / 1000);
prev = t;
if (!visible) return;
step(dt, clock());
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);
setSize.current = null;
freeTargets();
gl.deleteTexture(stateTex);
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 JellyGrid;
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 jelly itself (keep it very dark for the glossy black look).default "#060607"default "#060607"sheenstringColour of the reflections and rims.default "#f2f3f6"default "#f2f3f6"colors[string, string, string]The three colours the gel glows in when it is pressed.default ["#2b5cff", "#9b5cff", "#ff4d8a"]default ["#2b5cff", "#9b5cff", "#ff4d8a"]backgroundstringBackground colour (the gaps).default "#000000"default "#000000"sizenumberTile size in px (scaled down on small screens).default 110default 110softnessnumberHow soft and wobbly the tiles are, 0 to 1.default 0.6default 0.6focusnumberCalms the centre so a headline on top stays readable, 0 to 1.default 0.3default 0.3speednumberSpeed of the idle breathing and drifting reflections.default 1default 1glownumberStrength of the glow and bloom.default 0.9default 0.9interactivebooleanPress, drag, click wave and scroll wobble.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the grid.classNamestringSize it, e.g. h-screen w-full.