Backgrounds19 / 118
Petal Light
Soft petals of cobalt light fan out of a warm cream glow in one corner, like a flower seen up close: broad curved petals split by fine dark creases, deep navy at the tips and paling to cream toward the source, fading into black. The petals breathe open and closed and the fan sways; they lean toward your cursor as the glow follows it, a click blooms the fan open in a pulse of light, and scrolling unfolds it further.
WebGLWebGLSoft gradientsSoft gradientsBreathing petalsBreathing petalsClick bloomClick bloomGSAPGSAPReduced-motion safeReduced-motion safe
Lean the petalsClick to bloom
Tweak
LIVELIVEColour
#f4eee4
#2c5cf0
#08155a
#000000
Shape
4
1.00
0.50
Motion
1.00
Interactive
Petals lean toward the cursor, clicks bloom them open
Usage
Follows your tweaks.
usage.tsx
import { PetalLight } from "@/components/inreact/petal-light";
export function Hero() {
return (
<PetalLight
className="h-screen w-full"
>
{/* optional: your hero content, drawn above the light */}
</PetalLight>
);
}Install with the CLI
TS + Tailwind
npx shadcn@latest add https://inreact.vercel.app/r/petal-light.jsonOr copy the source
Install the dependencies, then save this as components/inreact/petal-light.tsx.
terminal
npm install gsapcomponents/inreact/petal-light.tsx
"use client";
import { gsap } from "gsap";
import { ScrollTrigger } from "gsap/ScrollTrigger";
import { useEffect, useRef, type ReactNode } from "react";
gsap.registerPlugin(ScrollTrigger);
/**
* Petal Light: soft petals of cobalt light fanning out of a warm glow.
*
* From a cream-white glow in one corner, broad curved petals of light open
* outward like a flower seen up close, each one deep cobalt at its tip and
* paling to cream toward the source, separated by fine dark creases that
* curve with the petals. Toward the far corner everything falls away into
* navy and black. A soft bloom lifts the bright heart; the blacks stay black.
*
* It is always alive: the petals breathe open and closed, each a little out of
* step, and the whole fan sways. It reacts: the petals lean toward your cursor
* and the glow follows it; a click blooms the fan open in a pulse of light;
* scrolling unfolds and turns the petals. On load the fan opens out of the dark.
*
* <PetalLight className="h-screen w-full">
* <YourHero />
* </PetalLight>
*
* WebGL: one shader (curved polar petals, soft creases, a four-stop colour ramp
* with fine grain so the gradients never band), then 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 WebGL.
*/
export interface PetalLightProps {
/** Colour of the glowing heart. */
heart?: string;
/** Colour of the petals. */
petal?: string;
/** Colour the petals deepen into at their tips. */
deep?: string;
/** Background colour beyond the petals. */
background?: string;
/** How many petals. */
petals?: number;
/** How far the light reaches. */
reach?: number;
/** Strength of the bloom. */
glow?: number;
/** Speed of the breathing. */
speed?: number;
/** Cursor lean, click bloom. */
interactive?: boolean;
/** Scroll container if the page does not scroll the window. */
scroller?: Element | null;
/** Foreground content, drawn above the light. */
children?: ReactNode;
className?: string;
}
const QUAD = `attribute vec2 aQ; varying vec2 vUv; void main(){ vUv = aQ * 0.5 + 0.5; gl_Position = vec4(aQ, 0.0, 1.0); }`;
const SCENE = `
precision highp float;
uniform vec2 uRes, uSrc, uMouse;
uniform float uTime, uIn, uCount, uReach, uOpen, uTurn, uCurl, uHover, uBloom, uLean;
uniform vec3 uHeart, uPetal, uDeep, uBg;
varying vec2 vUv;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
// the colour ramp: black, deep navy, cobalt, a pale lift, then the cream heart
vec3 ramp(float v) {
v = clamp(v, 0.0, 1.0);
vec3 c = mix(uBg, uDeep, smoothstep(0.0, 0.22, v));
c = mix(c, uPetal, smoothstep(0.18, 0.55, v));
// through a pale periwinkle on the way to cream, never via a muddy green
vec3 pale = mix(uPetal, vec3(0.78, 0.82, 1.0), 0.6);
c = mix(c, pale, smoothstep(0.58, 0.82, v));
c = mix(c, uHeart, smoothstep(0.82, 0.98, v));
return c;
}
void main() {
float H = uRes.y;
vec2 p = gl_FragCoord.xy / H;
vec2 d = p - uSrc;
float r = length(d);
float a = atan(d.y, d.x);
// the petals lean toward the cursor, more the further out they reach
vec2 dm = uMouse - uSrc;
float ma = atan(dm.y, dm.x);
float lean = sin(ma - a) * 0.22 * uHover * smoothstep(0.0, 1.0, r);
// each petal curves as it grows outward, and sways
float ac = a - r * (uCurl + 0.06 * sin(uTime * 0.4)) + lean + uTurn;
// the fan spans the quarter turn out of the corner, split into petals
float span = 1.75;
float t = (ac + 0.12) / span * uCount;
// depth: the lean varies smoothly across the fan, so outer petals slide against inner ones as the cursor moves
ac += lean * 0.35 * sin(ac * 2.4 + 0.6);
t = (ac + 0.12) / span * uCount;
float idx = floor(t);
float h = hash(vec2(idx, 4.1));
float u = fract(t); // 0 at a crease, 1 at the next
// each petal breathes on its own, reaching further and closer
float breathe = 1.0 + 0.09 * sin(uTime * 0.7 + idx * 1.9) + 0.25 * uBloom;
float reach = uReach * (0.82 + 0.3 * h) * breathe * uOpen;
// across the petal: lit toward its leading side, falling into the crease behind it
float across = mix(0.68, 1.0, smoothstep(0.0, 0.9, u));
// where the petal tucks under its neighbour it falls into soft shadow
across *= 1.0 - 0.22 * smoothstep(0.82, 1.0, u);
float crease = 1.0 - 0.45 * exp(-u / 0.022) - 0.25 * exp(-u / 0.1);
// a soft rounded petal edge where the light gives out
float fall = exp(-pow(r / reach, 1.5)) * 0.92;
float v = fall * across * crease;
// a satin sheen running down each petal, catching more light as the petal breathes
float sheen = exp(-pow((u - 0.62 - 0.05 * sin(uTime * 0.5 + idx)) / 0.13, 2.0));
v += sheen * fall * (0.1 + 0.05 * sin(uTime * 0.7 + idx * 1.9)) * smoothstep(0.05, 0.4, r);
// the heart: a broad warm glow at the source
v += exp(-pow(r / (reach * 0.36), 2.0)) * 0.32;
// the cursor's own soft light
v += exp(-dot(p - uMouse, p - uMouse) / 0.06) * 0.12 * uHover;
v *= 1.0 + 0.2 * uBloom;
// outside the fan's span, only darkness
v *= smoothstep(-0.3, -0.05, ac) * smoothstep(span + 0.3, span - 0.1, ac);
v *= uIn;
vec3 col = ramp(v);
// fine grain so the long gradients never band
col += (hash(gl_FragCoord.xy + fract(uTime) * 37.0) - 0.5) / 160.0;
gl_FragColor = vec4(col, 1.0);
}`;
const BLUR = `
precision mediump float;
uniform sampler2D uTex;
uniform vec2 uStep;
varying vec2 vUv;
void main() {
vec4 c = texture2D(uTex, vUv) * 0.2270;
c += (texture2D(uTex, vUv + uStep * 1.3846) + texture2D(uTex, vUv - uStep * 1.3846)) * 0.3162;
c += (texture2D(uTex, vUv + uStep * 3.2308) + texture2D(uTex, vUv - uStep * 3.2308)) * 0.0703;
gl_FragColor = c;
}`;
const BRIGHT = `
precision mediump float;
uniform sampler2D uTex;
varying vec2 vUv;
void main() {
vec3 c = texture2D(uTex, vUv).rgb;
float l = max(c.r, max(c.g, c.b));
gl_FragColor = vec4(c * smoothstep(0.7, 1.0, l), 1.0);
}`;
const COMPOSITE = `
precision mediump float;
uniform sampler2D uScene, uBloom, uWide;
uniform float uGlow, uTime;
varying vec2 vUv;
float hash(vec2 p) { return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453); }
void main() {
vec3 sc = texture2D(uScene, vUv).rgb;
vec3 bl = texture2D(uBloom, vUv).rgb * 0.6 + texture2D(uWide, vUv).rgb * 0.5;
vec3 x = sc + bl * uGlow;
vec3 col = x / (1.0 + max(x - 0.85, 0.0) * 1.3);
col = min(col, vec3(1.0));
col += (hash(gl_FragCoord.xy + fract(uTime * 7.0) * 91.0) - 0.5) / 255.0;
gl_FragColor = vec4(col, 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];
}
export function PetalLight({
heart = "#f4eee4",
petal = "#2c5cf0",
deep = "#08155a",
background = "#000000",
petals = 4,
reach = 1,
glow = 0.5,
speed = 1,
interactive = true,
scroller,
children,
className,
}: PetalLightProps) {
const hostRef = useRef<HTMLDivElement>(null);
const props = useRef({ heart, petal, deep, background, petals, reach, glow, speed, interactive });
const redraw = useRef<(() => void) | null>(null);
useEffect(() => {
props.current = { heart, petal, deep, background, petals, reach, glow, speed, interactive };
redraw.current?.();
}, [heart, petal, deep, background, petals, reach, glow, speed, 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("webgl", { alpha: false, antialias: false, powerPreference: "high-performance" });
if (!gl) {
const p = props.current;
host.style.background = `radial-gradient(circle at 0% 100%, ${p.heart}, ${p.petal} 45%, ${p.deep} 75%, ${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.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", "uSrc", "uMouse", "uTime", "uIn", "uCount", "uReach", "uOpen", "uTurn", "uCurl", "uHover", "uBloom", "uLean", "uHeart", "uPetal", "uDeep", "uBg"]);
const UB = uni(blurProg, ["uTex", "uStep"]);
const UR = uni(brightProg, ["uTex"]);
const UC = uni(compProg, ["uScene", "uBloom", "uWide", "uGlow", "uTime"]);
const quad = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, quad);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 3, -1, -1, 3]), gl.STATIC_DRAW);
const drawQuad = (pr: WebGLProgram) => {
const a = gl.getAttribLocation(pr, "aQ");
gl.bindBuffer(gl.ARRAY_BUFFER, quad);
gl.enableVertexAttribArray(a);
gl.vertexAttribPointer(a, 2, gl.FLOAT, false, 0, 0);
gl.drawArrays(gl.TRIANGLES, 0, 3);
gl.disableVertexAttribArray(a);
};
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 x of Object.values(T)) {
gl.deleteFramebuffer(x.fb);
gl.deleteTexture(x.tex);
}
T = null;
};
let w = 1, h = 1, dpr = 1;
const resize = () => {
dpr = Math.min(window.devicePixelRatio || 1, 2);
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();
// ---- state: every value GSAP moves (positions in height units, y up) ----
const s = { in: still ? 1 : 0, open: still ? 1 : 0.35, turn: 0, sway: 0, curl: 0.4, mx: 0, my: 0, hover: 0, bloom: 0, sx: 0, sy: 0, unfold: 0 };
let time = still ? 3 : 0;
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(blurProg);
};
const draw = () => {
if (!T) return;
const p = props.current;
const X = T;
const aspect = w / h;
gl.bindFramebuffer(gl.FRAMEBUFFER, X.scene.fb);
gl.viewport(0, 0, X.scene.w, X.scene.h);
gl.useProgram(sceneProg);
gl.uniform2f(US.uRes, X.scene.w, X.scene.h);
// the void sits a little right of centre on wide screens, centred on narrow ones, leaving room for content
const off = Math.min(0.18, Math.max(0, (aspect - 1) * 0.12));
// the source sits just off the lower-left corner; on wide screens the fan reaches further to fill the frame
gl.uniform2f(US.uSrc, -0.06 + s.sx, -0.06 + s.sy);
gl.uniform2f(US.uMouse, s.mx, s.my);
gl.uniform1f(US.uTime, time);
gl.uniform1f(US.uIn, s.in);
gl.uniform1f(US.uCount, Math.max(1, Math.round(p.petals)));
gl.uniform1f(US.uReach, p.reach * 0.78 * Math.max(1, Math.pow(aspect, 0.6)));
gl.uniform1f(US.uOpen, s.open + s.unfold);
gl.uniform1f(US.uTurn, s.turn + s.sway);
gl.uniform1f(US.uCurl, s.curl);
gl.uniform1f(US.uHover, s.hover);
gl.uniform1f(US.uBloom, s.bloom);
gl.uniform1f(US.uLean, 0);
gl.uniform3fv(US.uHeart, rgb(p.heart));
gl.uniform3fv(US.uPetal, rgb(p.petal));
gl.uniform3fv(US.uDeep, rgb(p.deep));
gl.uniform3fv(US.uBg, rgb(p.background));
drawQuad(sceneProg);
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(brightProg);
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, time);
drawQuad(compProg);
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 fan opens out of the dark ----
const intro = gsap
.timeline({ delay: 0.1 })
.to(s, { in: 1, duration: 1.6, ease: "power2.out" }, 0)
.to(s, { open: 1, duration: 3.2, ease: "expo.out" }, 0)
.fromTo(s, { turn: -0.25 }, { turn: 0, duration: 3.4, ease: "expo.out" }, 0);
// ---- idle: the fan sways and its petals curl and uncurl ----
const sway = gsap.to(s, { sway: 0.07, duration: 6, ease: "sine.inOut", yoyo: true, repeat: -1 });
const curl = gsap.to(s, { curl: 0.55, duration: 7.5, ease: "sine.inOut", yoyo: true, repeat: -1 });
// ---- cursor: the petals lean toward it and the glow drifts after it ----
const mxTo = gsap.quickTo(s, "mx", { duration: 0.9, ease: "power3" });
const myTo = gsap.quickTo(s, "my", { duration: 0.9, ease: "power3" });
const sxTo = gsap.quickTo(s, "sx", { duration: 1.6, ease: "power3" });
const syTo = gsap.quickTo(s, "sy", { duration: 1.6, ease: "power3" });
const hoverTo = gsap.quickTo(s, "hover", { duration: 1, ease: "power2.inOut" });
const local = (e: PointerEvent) => {
const r = host.getBoundingClientRect();
return { x: (e.clientX - r.left) / r.height, y: (r.bottom - e.clientY) / r.height, nx: (e.clientX - r.left) / r.width, ny: (r.bottom - e.clientY) / r.height };
};
let first = true;
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);
sxTo((p.nx - 0.5) * 0.12);
syTo((p.ny - 0.5) * 0.12);
};
const leave = () => {
first = true;
hoverTo(0);
sxTo(0);
syTo(0);
};
// ---- click: the fan blooms open in a pulse of light ----
const down = () => {
if (!props.current.interactive) return;
gsap.killTweensOf(s, "bloom");
gsap.timeline().to(s, { bloom: 0.8, duration: 0.7, ease: "sine.out" }).to(s, { bloom: 0, duration: 2.2, ease: "sine.inOut" });
};
host.addEventListener("pointermove", move);
host.addEventListener("pointerleave", leave);
host.addEventListener("pointerdown", down);
// ---- scroll: the petals unfold further as you scroll through ----
const unfoldTo = gsap.quickTo(s, "unfold", { duration: 1.3, ease: "power3" });
const st = ScrollTrigger.create({
trigger: host,
scroller: scroller ?? undefined,
start: "top bottom",
end: "bottom top",
onUpdate: (self) => unfoldTo(Math.max(0, self.progress - 0.5) * 0.8),
});
// ---- loop, only while on screen ----
let visible = true;
let prev = performance.now();
const loop = () => {
const now = performance.now();
const dt = Math.min(0.05, (now - prev) / 1000);
prev = now;
if (!visible) return;
time += dt * props.current.speed;
draw();
};
const io = new IntersectionObserver(([en]) => {
visible = en.isIntersecting;
prev = performance.now();
});
io.observe(host);
gsap.ticker.add(loop);
return () => {
gsap.ticker.remove(loop);
intro.kill();
sway.kill();
curl.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>
);
}
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 propsheartstringColour of the glowing heart.default "#f4eee4"default "#f4eee4"petalstringColour of the petals.default "#2c5cf0"default "#2c5cf0"deepstringColour the petals deepen into at their tips.default "#08155a"default "#08155a"backgroundstringBackground colour beyond the petals.default "#000000"default "#000000"petalsnumberHow many petals.default 4default 4reachnumberHow far the light reaches.default 1default 1glownumberStrength of the bloom.default 0.5default 0.5speednumberSpeed of the breathing.default 1default 1interactivebooleanCursor lean, click bloom.default truedefault truescrollerElement | nullScroll container, if the page does not scroll the window.childrenReactNodeForeground content, drawn above the light.classNamestringSize it, e.g. h-screen w-full.