Night Garden
An engraved garden of flowers, drawn entirely in code like a silver etching: three layers of blossoms with rings of petals, ink outlines, dark seams and fine line shading, stippled centres and serrated leaves tucked beneath. It grows lush and bright at the edges and falls into a calm, dark centre where your headline reads, and every flower breathes and turns slowly at its own depth. Your cursor is a lantern: the flowers under it open wider, turn toward you and fill with rose, violet and gold while the layers shift in parallax. A click sends a ring through the garden that bursts every flower it passes open, scrolling turns the flowers and slides the layers in depth, and on load the garden blooms from the edges inward.
Tweak
LIVELIVEColour
Garden
Motion
Interactive
Lantern opens and colours the flowers, click for a bloom ring
Usage
Follows your tweaks.
import { NightGarden } from "@/components/inreact/night-garden";
export function Hero() {
return (
<NightGarden
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the garden */}
</NightGarden>
);
}Install with the CLI
npx shadcn@latest add https://inreact.vercel.app/r/night-garden.jsonOr copy the source
Install the dependencies, then save this as components/inreact/night-garden.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);
/**
* Night Garden: an engraved garden of flowers that blooms around your content.
*
* Three layers of flowers and serrated leaves, drawn in code like a silver
* engraving: layered petal rings with ink outlines, dark seams between petals,
* fine concentric line shading and stippled centres. The garden is dense and
* bright at the edges and falls into a calm, dark centre where a headline
* reads. Every flower breathes and turns slowly; the layers sit at different
* depths.
*
* It reacts: your cursor is a lantern. The flowers under it open wider, turn
* toward you and fill with colour (rose, violet, gold) while the layers shift
* in parallax. A click sends a ring through the garden that makes every flower
* it passes burst open and spin. Scrolling turns the flowers and slides the
* layers in depth. On load the garden blooms from the edges inward.
*
* <NightGarden className="h-screen w-full">
* <YourHero />
* </NightGarden>
*
* WebGL2: one shader draws every flower as an anti-aliased distance field,
* then a bloom at 1/4 and 1/16 size. GSAP drives every motion. Pauses
* off-screen; reduced motion shows a still frame; a CSS gradient without WebGL2.
*/
export interface NightGardenProps {
/** Colour of the engraving (the resting flowers). */
ink?: string;
/** The three petal colours the lantern reveals. */
colors?: [string, string, string];
/** Background colour. */
background?: string;
/** How much colour the garden shows at rest, 0 (pure engraving) to 1. */
colorfulness?: number;
/** How dark and calm the centre is, 0 to 1. */
focus?: number;
/** Flower size multiplier. */
scale?: number;
/** Speed of the breathing and turning. */
speed?: number;
/** Strength of the bloom on lit petals. */
glow?: number;
/** Lantern, click bloom ring, scroll response. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the garden. */
children?: ReactNode;
className?: string;
}
const MAXW = 4;
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, uPar; // css px, top-left origin; parallax -1..1
uniform float uDpr, uTime, uIntro, uHover, uFocus, uColorAmt, uSize, uSpin, uScroll, uBreath;
uniform vec3 uInk, uA, uB, uC, uBg;
uniform vec4 uWave[${MAXW}];
in vec2 vUv;
out vec4 o;
const float PI = 3.14159265;
float h21(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
vec3 pal(float t) {
t = fract(t) * 3.0;
return t < 1.0 ? mix(uA, uB, t) : t < 2.0 ? mix(uB, uC, t - 1.0) : mix(uC, uA, t - 2.0);
}
mat2 rot2(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }
// one layer of flowers on a jittered grid; neighbours are visited in a fixed order so overlaps never seam
void garden(inout vec3 col, vec2 ps, float layer, float cell, float depth, float tilt) {
vec2 off = uPar * depth * vec2(26.0, 18.0) + vec2(0.0, uScroll * depth);
// each layer's grid is turned and shifted, so no rows or columns ever line up
mat2 Rt = rot2(tilt);
vec2 p = Rt * (ps + off) + layer * vec2(0.37, 0.61) * cell;
vec2 base = floor(p / cell);
for (int j = -1; j <= 1; j++)
for (int i = -1; i <= 1; i++) {
vec2 id = base + vec2(float(i), float(j));
vec2 key = id + layer * 37.0;
float h1 = h21(key), h2 = h21(key + 1.7), h3 = h21(key + 4.1), h4 = h21(key + 7.3);
vec2 c = (id + 0.5 + (vec2(h1, h2) - 0.5) * 0.66) * cell;
vec2 q = p - c;
float reach = cell * 1.1;
if (dot(q, q) > reach * reach) continue;
vec2 cs = transpose(Rt) * (c - layer * vec2(0.37, 0.61) * cell) - off; // flower centre on screen
q = transpose(Rt) * q;
// the lantern and the bloom rings
vec2 dm = cs - uMouse;
float near = exp(-dot(dm, dm) / (190.0 * 190.0 * uSize * uSize)) * uHover;
float wave = 0.0;
for (int k = 0; k < ${MAXW}; k++) {
vec4 W = uWave[k];
if (W.w <= 0.0) continue;
float age = uTime - W.z;
if (age < 0.0 || age > 3.0) continue;
float r = length(cs - W.xy);
wave = max(wave, exp(-pow((r - age * 560.0 * uSize) / (110.0 * uSize), 2.0)) * exp(-age * 0.9) * W.w);
}
// composition: lush at the edges, calm and dark in the centre
vec2 hd = (cs - uRes * 0.5) / (uRes * 0.5);
float el = length(hd * vec2(1.0, 0.92));
float vign = mix(1.0 - uFocus * 0.9, 1.0, pow(smoothstep(0.18, 1.05, el), 1.3));
// intro: blooms from the edges inward
float dly = (1.0 - smoothstep(0.0, 1.25, el)) * 0.85 + h4 * 0.2;
float gate = smoothstep(dly, dly + 0.35, uIntro * 1.4);
if (gate <= 0.0) continue;
float R = cell * mix(0.26, 0.55, h3 * h3 * 0.4 + h3 * 0.6);
float open = gate * (0.86 + 0.07 * sin(uBreath * 0.8 + h4 * 6.283)) + near * 0.13 + wave * 0.26;
float spin = h1 * 6.283 + uSpin * (h2 - 0.5) * 2.2 + uBreath * 0.05 * (h3 - 0.5) + near * 0.4 + wave * 1.1;
float n = floor(mix(5.0, 11.0, h2));
float bright = depth * vign * (1.0 + near * 1.0 + wave * 0.8);
float cAmt = clamp(uColorAmt + near * 0.9 + wave * 0.6, 0.0, 1.0);
vec3 tint = mix(uInk, pal(h3 * 0.9 + layer * 0.17 + h1 * 0.2), cAmt);
float lw = max(0.9, R * 0.045);
// distances are in css px, so a constant edge width is exact anti-aliasing (no derivatives in divergent loops)
float AA = 1.2 / uDpr;
// leaves first, tucked under the flower
float nl = 2.0 + step(0.45, h1);
for (int k = 0; k < 3; k++) {
if (float(k) >= nl) break;
float ang = h4 * 6.283 + float(k) * 6.283 / nl + spin * 0.25;
vec2 lq = rot2(-ang) * q;
float L = R * 1.32 * mix(0.7, 1.0, gate);
float x = lq.x - R * 0.2;
float t = clamp(x / L, 0.0, 1.0);
float wdt = R * 0.34 * pow(sin(PI * t), 0.75) * (1.0 + 0.08 * sin(t * 40.0));
float d = max(abs(lq.y) - wdt, max(-x, x - L));
float aa = AA;
float al = clamp(0.5 - d / aa, 0.0, 1.0) * gate;
if (al <= 0.0) continue;
float ay = abs(lq.y);
float tone = 0.4 * mix(0.55, 1.0, smoothstep(0.0, 1.0, ay / max(wdt, 1e-3)));
tone *= mix(0.35, 1.0, smoothstep(lw * 0.4, lw * 1.4, ay)); // midrib
tone *= 0.78 + 0.22 * smoothstep(-0.3, 0.7, sin((x - ay * 1.5) / R * 15.0)); // veins
tone *= mix(0.22, 1.0, smoothstep(0.0, lw * 1.8, -d)); // ink edge
col = mix(col, mix(uInk, tint, 0.5) * tone * bright, al);
}
// three rings of petals, each turned half a petal from the last
float r = length(q);
float a0 = atan(q.y, q.x) + spin;
float rnd = step(0.5, h4);
for (int k = 0; k < 3; k++) {
float fk = float(k);
float sr = fk == 0.0 ? 1.0 : fk == 1.0 ? 0.68 : 0.42;
float a = a0 + fk * PI / n + fk * 0.3;
float m = abs(cos(a * n * 0.5));
float shape = mix(pow(m, 1.5), sqrt(m), rnd);
float rp = R * sr * open * (0.5 + 0.5 * shape);
float d = r - rp;
float aa = AA;
float al = clamp(0.5 - d / aa, 0.0, 1.0);
if (al <= 0.0) continue;
float tone = (fk == 0.0 ? 0.7 : fk == 1.0 ? 0.84 : 0.96);
tone *= mix(0.5, 1.0, smoothstep(0.0, 0.9, r / max(rp, 1e-3)));
tone *= mix(0.4, 1.0, smoothstep(0.0, 0.16, m)); // seams between petals
tone *= 1.0 + 0.12 * smoothstep(0.9, 1.0, m) * smoothstep(0.3, 0.8, r / max(rp, 1e-3)); // a lit midrib on each petal
float kk = min(42.0, R * 1.2);
tone *= 0.94 + 0.06 * sin(r / R * kk); // fine engraved line shading
tone *= mix(fk == 0.0 ? 0.22 : 0.45, 1.0, smoothstep(0.0, lw * 1.5, -d)); // ink edge, lighter on inner rings
col = mix(col, tint * tone * bright, al);
}
// stippled centre
{
float d = r - R * 0.17 * max(open, 0.2);
float aa = AA;
float al = clamp(0.5 - d / aa, 0.0, 1.0);
if (al > 0.0) {
vec2 sq = q / max(R * 0.05, 1.2);
float dots = smoothstep(0.55, 0.15, length(fract(sq) - 0.5));
float tone = 0.95 * mix(0.55, 1.0, dots) * mix(0.25, 1.0, smoothstep(0.0, lw * 1.4, -d));
col = mix(col, mix(tint, pal(h2 + 0.33), cAmt * 0.6) * tone * bright, al);
}
}
}
}
void main() {
vec2 p = vec2(gl_FragCoord.x, uRes.y * uDpr - gl_FragCoord.y) / uDpr;
vec3 col = uBg;
// far to near: small and hazy, then larger and brighter
garden(col, p, 0.0, 74.0 * uSize, 0.42, 0.31);
garden(col, p, 1.0, 104.0 * uSize, 0.68, -0.22);
garden(col, p, 2.0, 142.0 * uSize, 1.0, 0.12);
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.2, 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 DEFAULT_COLORS: [string, string, string] = ["#ff5c8a", "#8a6bff", "#ffb547"];
export function NightGarden({
ink = "#ece8f2",
colors = DEFAULT_COLORS,
background = "#030303",
colorfulness = 0.12,
focus = 0.7,
scale = 1,
speed = 1,
glow = 0.6,
interactive = true,
scroller,
children,
className,
}: NightGardenProps) {
const hostRef = useRef<HTMLDivElement>(null);
const [c1, c2, c3] = colors;
const props = useRef({ ink, c1, c2, c3, background, colorfulness, focus, scale, speed, glow, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { ink, c1, c2, c3, background, colorfulness, focus, scale, speed, glow, interactive };
redraw.current?.();
}, [ink, c1, c2, c3, background, colorfulness, focus, scale, speed, glow, interactive]);
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(70% 60% at 50% 50%, ${p.background}, transparent 100%), radial-gradient(120% 120% at 50% 50%, transparent 40%, ${p.ink}33), ${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", "uPar", "uDpr", "uTime", "uIntro", "uHover", "uFocus", "uColorAmt", "uSize", "uSpin", "uScroll", "uBreath",
"uInk", "uA", "uB", "uC", "uBg", "uWave",
]);
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;
};
let w = 1, h = 1, dpr = 1;
const resize = () => {
dpr = Math.min(window.devicePixelRatio || 1, 1.5);
w = Math.max(1, host.clientWidth);
h = Math.max(1, host.clientHeight);
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)),
};
};
resize();
const s = { intro: still ? 1 : 0, mx: -9999, my: -9999, hover: 0, px: 0, py: 0, scroll: 0, spin: 0, spinV: 0 };
let breath = still ? 3 : 0;
const t0 = performance.now();
const clock = () => (still ? 10 : (performance.now() - t0) / 1000);
const waves: { x: number; y: number; t: number; s: number }[] = [];
const waveBuf = new Float32Array(MAXW * 4);
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();
// flowers scale down on small screens so phones still get a full garden
const size = Math.max(0.3, p.scale) * Math.max(0.62, Math.min(1, Math.min(w, h * 1.4) / 1100));
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.uniform2f(US.uPar, s.px, s.py);
gl.uniform1f(US.uDpr, dpr);
gl.uniform1f(US.uTime, now);
gl.uniform1f(US.uIntro, s.intro);
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uFocus, Math.max(0, Math.min(1, p.focus)));
gl.uniform1f(US.uColorAmt, Math.max(0, Math.min(1, p.colorfulness)));
gl.uniform1f(US.uSize, size);
gl.uniform1f(US.uSpin, s.spin);
gl.uniform1f(US.uScroll, s.scroll);
gl.uniform1f(US.uBreath, breath);
gl.uniform3fv(US.uInk, rgb(p.ink));
gl.uniform3fv(US.uA, rgb(p.c1));
gl.uniform3fv(US.uB, rgb(p.c2));
gl.uniform3fv(US.uC, rgb(p.c3));
gl.uniform3fv(US.uBg, rgb(p.background));
waveBuf.fill(0);
waves.forEach((v, i) => waveBuf.set([v.x, v.y, v.t, v.s], i * 4));
gl.uniform4fv(US.uWave, waveBuf);
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);
};
const ro = new ResizeObserver(() => {
resize();
draw();
});
ro.observe(host);
if (still) {
draw();
redraw.current = draw;
return () => {
redraw.current = null;
ro.disconnect();
freeTargets();
canvas.remove();
gl.getExtension("WEBGL_lose_context")?.loseContext();
};
}
// ---- on load: the garden blooms from the edges inward ----
const intro = gsap.to(s, { intro: 1, duration: 2.8, ease: "power2.out", delay: 0.1 });
// ---- cursor: a lantern that opens and colours the flowers, layers in parallax ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.45, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.45, ease: "power3" });
const pxTo = gsap.quickTo(s, "px", { duration: 1.3, ease: "power3" });
const pyTo = gsap.quickTo(s, "py", { duration: 1.3, ease: "power3" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 0.8, ease: "power2.inOut" });
let first = true;
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: e.clientX - r.left, y: e.clientY - r.top, nx: (e.clientX - r.left) / r.width - 0.5, ny: (e.clientY - r.top) / r.height - 0.5 };
};
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);
pxTo(-p.nx * 2);
pyTo(-p.ny * 2);
hoverTo(1);
};
const leave = () => {
first = true;
hoverTo(0);
pxTo(0);
pyTo(0);
};
// ---- click: a ring that bursts every flower it passes open ----
const down = (e: PointerEvent) => {
if (!props.current.interactive) return;
const p = local(e);
waves.push({ x: p.x, y: p.y, t: clock(), s: 1 });
if (waves.length > MAXW) waves.shift();
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: layers slide in depth, scroll speed turns the flowers ----
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) * -160);
if (!props.current.interactive) return;
const v = Math.max(-1, Math.min(1, self.getVelocity() / 2500));
if (Math.abs(v) > Math.abs(s.spinV)) gsap.to(s, { spinV: v * 1.6, duration: 0.25, ease: "power2.out", overwrite: "auto", onComplete: () => void gsap.to(s, { spinV: 0, duration: 1.6, 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;
breath += dt * props.current.speed;
s.spin += s.spinV * dt;
const now = clock();
for (let i = waves.length - 1; i >= 0; i--) if (now - waves[i].t > 3.2) 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);
freeTargets();
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 NightGarden;
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
12 propsinkstringColour of the engraving (the resting flowers).default "#ece8f2"default "#ece8f2"colors[string, string, string]The three petal colours the lantern reveals.default ["#ff5c8a", "#8a6bff", "#ffb547"]default ["#ff5c8a", "#8a6bff", "#ffb547"]backgroundstringBackground colour.default "#030303"default "#030303"colorfulnessnumberHow much colour the garden shows at rest, 0 (pure engraving) to 1.default 0.12default 0.12focusnumberHow dark and calm the centre is, 0 to 1.default 0.7default 0.7scalenumberFlower size multiplier.default 1default 1speednumberSpeed of the breathing and turning.default 1default 1glownumberStrength of the bloom on lit petals.default 0.6default 0.6interactivebooleanLantern, click bloom ring and scroll response.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the garden.classNamestringSize it, e.g. h-screen w-full.