Noise Displaced Scene
Liquid abstract background: upper and lower color fields whose edges are warped by SVG turbulence displacement into a wavy seam, over a ground with grain. Uses the warmth palette, OKLCH overrides and an adjustable seam position.
import { useId } from "react"
import { cn } from "cn"
import { ORBITAL_PALETTES } from "@/components/orbs/orbital-palettes"
import {
firstStops,
fmt,
type FieldAnchors,
type OklchColor,
} from "@/lib/field-layers"
const GRAIN = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='turbulence' baseFrequency='1.4' numOctaves='1'/%3E%3CfeComponentTransfer result='g'%3E%3CfeFuncR type='linear' slope='4' intercept='1'/%3E%3CfeFuncG type='linear' slope='4' intercept='1'/%3E%3CfeFuncB type='linear' slope='4' intercept='1'/%3E%3C/feComponentTransfer%3E%3CfeColorMatrix type='saturate' values='0' in='g'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`
// The one painting: the warmth palette from the shared table, read as its
// ground and first stops. `colors` overrides any of the three.
const WARMTH: FieldAnchors = firstStops(ORBITAL_PALETTES.warmth)
type NoiseDisplacedColors = Partial<FieldAnchors>
/**
* Full-bleed art layer — drop inside a `relative` parent; sits behind content.
*/
function NoiseDisplacedScene({
className,
colors,
horizon = 50,
grain = true,
...props
}: Omit<React.ComponentProps<"div">, "children"> & {
/** Set false when stacking your own grain on top. */
grain?: boolean
/** OKLCH overrides for the `ground`, `upper` and `lower` anchors. */
colors?: NoiseDisplacedColors
/**
* Vertical seam position 0–100. 50 = default heights; lower pulls the seam
* up.
*/
horizon?: number
}) {
// useId alone can emit characters that are illegal in an SVG id.
const uid = useId().replace(/[^a-zA-Z0-9]/g, "")
const upperFilter = `nd-${uid}-1`
const lowerFilter = `nd-${uid}-2`
const base = WARMTH
const ground = colors?.ground ?? base.ground
const upper = colors?.upper ?? base.upper
const lower = colors?.lower ?? base.lower
// 0 and 100 both overflow the box; clamp to the usable band.
const h = Number.isFinite(horizon) ? Math.min(95, Math.max(5, horizon)) : 50
const upperH = h + 5
const lowerH = 102 - h
return (
<div
className={cn(
"pointer-events-none absolute inset-0 overflow-hidden",
className
)}
aria-hidden="true"
data-slot="noise-displaced-scene"
{...props}
>
<svg className="absolute size-0" aria-hidden="true">
<defs>
<filter id={upperFilter} x="-10%" y="-10%" width="120%" height="120%">
<feTurbulence
type="fractalNoise"
baseFrequency="0.01 0.005"
numOctaves={2}
seed={1}
result="noise"
/>
<feDisplacementMap
in="SourceGraphic"
in2="noise"
scale={25}
xChannelSelector="R"
yChannelSelector="G"
/>
</filter>
<filter id={lowerFilter} x="-10%" y="-10%" width="120%" height="120%">
<feTurbulence
type="fractalNoise"
baseFrequency="0.008 0.004"
numOctaves={3}
seed={5}
result="noise"
/>
<feDisplacementMap
in="SourceGraphic"
in2="noise"
scale={20}
xChannelSelector="R"
yChannelSelector="G"
/>
</filter>
</defs>
</svg>
<div className="absolute inset-0" style={{ background: fmt(ground) }} />
<div
className="absolute inset-x-0 top-0"
style={{
height: `${upperH}%`,
background: fmt(upper),
filter: `url(#${upperFilter})`,
}}
/>
<div
className="absolute inset-x-0 bottom-0"
style={{
height: `${lowerH}%`,
background: fmt(lower),
filter: `url(#${lowerFilter})`,
}}
/>
{grain && (
<div
className="absolute inset-0 opacity-20 mix-blend-overlay"
style={{ backgroundImage: GRAIN }}
/>
)}
</div>
)
}
export { NoiseDisplacedScene }
export type { OklchColor as NoiseDisplacedOklch }
// The OKLCH math the painted scenes share: a color, a shift of it and its
// CSS string, used across components/scene; plus the two blurred fields over
// a ground that ColorFieldWash and HorizonGlazeScene build from three anchors.
// Plain functions, no React, so a scene can also precompute its palettes.
export type OklchColor = { l: number; c: number; h: number }
/** The three colors a field is painted from. */
export type FieldAnchors = {
ground: OklchColor
upper: OklchColor
lower: OklchColor
}
/** The CSS backgrounds built from the anchors. */
export type FieldLayers = {
ground: string
upper: string
lower: string
}
export function shift(base: OklchColor, dl = 0, dc = 0, dh = 0): OklchColor {
return {
l: Math.max(0, Math.min(1, base.l + dl)),
c: Math.max(0, base.c + dc),
h: (base.h + dh + 360) % 360,
}
}
export function fmt(c: OklchColor, alpha?: number): string {
const l = Math.round(c.l * 1000) / 1000
const ch = Math.round(c.c * 1000) / 1000
const h = Math.round(c.h * 10) / 10
const a = alpha != null ? ` / ${alpha}` : ""
return `oklch(${l} ${ch} ${h}${a})`
}
export const clean = <T extends object>(o: T) =>
Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined)) as T
// Upper field: a little darker, duller and cooler toward its edge; lower
// field the same, more so. The geometry matches the hand-tuned palettes
// that share this shape.
export function buildFieldLayers(a: FieldAnchors): FieldLayers {
return {
ground: fmt(a.ground),
upper: `radial-gradient(ellipse 130% 100% at 50% 35%, ${fmt(a.upper)} 0%, ${fmt(shift(a.upper, -0.025, -0.003, -3), 0.7)} 55%, transparent 100%)`,
lower: `radial-gradient(ellipse 130% 90% at 50% 80%, ${fmt(a.lower)} 0%, ${fmt(shift(a.lower, -0.03, -0.009, -1.5), 0.8)} 55%, transparent 100%)`,
}
}
/**
* The anchors behind a palette written as CSS: the ground and the first
* `oklch()` stop of each field. Lets a scene seed its overrides from a
* palette it already has as strings, so the numbers live once.
*/
export function firstStops(p: FieldLayers): FieldAnchors {
const first = (css: string): OklchColor => {
const m = /oklch\(([\d.]+) ([\d.]+) ([\d.]+)/.exec(css)
if (!m) throw new Error(`field-layers: no oklch() stop in ${css}`)
return { l: Number(m[1]), c: Number(m[2]), h: Number(m[3]) }
}
return {
ground: first(p.ground),
upper: first(p.upper),
lower: first(p.lower),
}
}
// Named palettes for the painted fields: a ground with an upper and a lower
// field blurred over it, the way Orbital paints a ball and ColorWash paints
// a panel. Plain data with no imports, so any component can read it. Pass a
// name to ColorWash as `color`, or an entry (or your own object of the same
// shape) to Orbital or ColorWash as `palette`.
type OrbitalPalette = {
/** The base color under everything else, any CSS color. */
ground: string
/** A CSS background, usually a radial gradient, blurred over the top. */
upper: string
/** A CSS background blurred over the bottom. */
lower: string
/** The orb's glow: an inner bloom and a halo. ColorWash ignores it. */
glow?: string
/** The orb's preferred shading tier. ColorWash ignores it. */
form?: "off" | "medium" | "strong"
/** Read by nothing today; kept so older palettes still type-check. */
period?: "nocturne"
}
type OrbitalPaletteName =
| "gold"
| "delft"
| "warmth"
| "marigold"
| "vesper"
| "aurora"
| "gesso"
| "plaster"
| "moss"
| "tidepool"
| "vermillion"
| "cocoa"
| "linen"
| "tarn"
| "gold-dark"
| "mint"
| "rose"
| "sky"
| "lilac"
| "pewter"
| "oxblood"
| "heather"
| "chambray"
| "lichen"
| "mallow"
| "kiln"
const ORBITAL_PALETTES: Record<OrbitalPaletteName, OrbitalPalette> = {
gold: {
ground: "oklch(0.315 0.064 270.3)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.875 0.097 100.4) 0%, oklch(0.850 0.101 100.7 / 0.7) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.365 0.073 269.3) 0%, oklch(0.365 0.073 269.3 / 0.8) 56%, transparent 100%)",
glow: "oklch(0.936 0.055 102.9)",
form: "strong",
},
delft: {
ground: "oklch(0.376 0.087 261.9)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.905 0.025 104.4) 0%, oklch(0.887 0.026 104.5 / 0.72) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.467 0.121 261.9) 0%, oklch(0.467 0.121 261.9 / 0.8) 55%, transparent 100%)",
glow: "oklch(0.978 0.010 261.8)",
form: "strong",
},
warmth: {
ground: "oklch(0.652 0.147 52.4)",
upper:
"radial-gradient(ellipse 130% 100% at 50% 35%, oklch(0.836 0.159 96.2) 0%, oklch(0.814 0.157 92.4 / 0.7) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 90% at 50% 80%, oklch(0.518 0.176 28.9) 0%, oklch(0.487 0.167 27.7 / 0.8) 55%, transparent 100%)",
glow: "oklch(0.836 0.159 96.2)",
},
marigold: {
ground: "oklch(0.379 0.076 35.6)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.805 0.160 71.9) 0%, oklch(0.805 0.160 71.9 / 0.75) 53%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.243 0.023 32.4) 0%, oklch(0.243 0.023 32.4 / 0.88) 56%, transparent 100%)",
glow: "oklch(0.829 0.154 76.5)",
form: "strong",
},
vesper: {
ground: "oklch(0.28 0.06 300)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.90 0.04 55) 0%, oklch(0.90 0.04 55 / 0.7) 53%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.42 0.13 305) 0%, oklch(0.42 0.13 305 / 0.85) 56%, transparent 100%)",
glow: "oklch(0.82 0.07 50)",
form: "strong",
},
aurora: {
ground: "oklch(0.318 0.057 158.2)",
upper:
"radial-gradient(ellipse 140% 110% at 50% 45%, oklch(0.890 0.129 146.1) 0%, oklch(0.890 0.129 146.1 / 0.5) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 100% at 50% 55%, oklch(0.236 0.055 296.3) 0%, oklch(0.236 0.055 296.3 / 0.5) 55%, transparent 100%)",
},
gesso: {
ground: "oklch(0.563 0.167 30.8)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.919 0.014 53.3) 0%, oklch(0.907 0.011 45.7 / 0.75) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.621 0.161 28.1) 0%, oklch(0.621 0.161 28.1 / 0.8) 55%, transparent 100%)",
glow: "oklch(0.949 0.014 53.3)",
form: "strong",
},
plaster: {
ground: "oklch(0.728 0.030 93.8)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.787 0.035 68.7) 0%, oklch(0.787 0.035 68.7 / 0.65) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.547 0.181 27.1) 0%, oklch(0.516 0.172 26.6 / 0.75) 55%, transparent 100%)",
glow: "oklch(0.561 0.158 29.1)",
form: "strong",
},
moss: {
ground: "oklch(0.313 0.006 34.3)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.561 0.039 200.7) 0%, oklch(0.507 0.038 203.1 / 0.7) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.373 0.047 214.5) 0%, oklch(0.395 0.046 210.5 / 0.8) 56%, transparent 100%)",
glow: "oklch(0.659 0.131 237.7)",
form: "medium",
},
tidepool: {
ground: "oklch(0.179 0.029 240.3)",
upper:
"radial-gradient(ellipse 140% 110% at 50% 45%, oklch(0.413 0.082 166.3) 0%, oklch(0.413 0.082 166.3 / 0.5) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 100% at 50% 55%, oklch(0.962 0.077 113.3) 0%, oklch(0.962 0.077 113.3 / 0.5) 55%, transparent 100%)",
},
vermillion: {
ground: "oklch(0.235 0.06 18.06)",
upper:
"radial-gradient(ellipse 130% 100% at 50% 38%, oklch(0.66 0.205 30.97) 0%, oklch(0.619 0.205 30.96 / 60%) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 90% at 50% 82%, oklch(0.28 0.136 266.87) 0%, oklch(0.25 0.136 267.22 / 70%) 55%, transparent 100%)",
},
cocoa: {
ground: "oklch(0.306 0.066 45.1)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.794 0.054 64.1) 0%, oklch(0.794 0.054 64.1 / 0.75) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.457 0.115 42.0) 0%, oklch(0.457 0.115 42.0 / 0.84) 56%, transparent 100%)",
glow: "oklch(0.762 0.120 49.2)",
form: "strong",
},
linen: {
ground: "oklch(0.267 0.021 54.1)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.782 0.021 58.0) 0%, oklch(0.782 0.021 58.0 / 0.75) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.363 0.028 53.6) 0%, oklch(0.363 0.028 53.6 / 0.85) 56%, transparent 100%)",
glow: "oklch(0.994 0.000 89.9)",
form: "strong",
},
tarn: {
ground: "oklch(0.286 0.036 189.5)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.757 0.155 95.6) 0%, oklch(0.757 0.155 95.6 / 0.72) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.468 0.065 190.9) 0%, oklch(0.468 0.065 190.9 / 0.82) 56%, transparent 100%)",
glow: "oklch(0.831 0.167 96.2)",
form: "strong",
},
"gold-dark": {
ground: "oklch(0.16 0.04 270)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.29 0.06 100) 0%, oklch(0.27 0.06 101 / 0.7) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.23 0.07 269) 0%, oklch(0.23 0.07 269 / 0.8) 56%, transparent 100%)",
},
mint: {
ground: "oklch(0.315 0.06368 314.9)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.875 0.09651 145.0) 0%, oklch(0.850 0.10049 145.3 / 0.7) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.365 0.07263 313.9) 0%, oklch(0.365 0.07263 313.9 / 0.8) 56%, transparent 100%)",
},
rose: {
ground: "oklch(0.315 0.04852 149.9)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.875 0.07355 340.0) 0%, oklch(0.850 0.07658 340.3 / 0.7) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.365 0.05535 148.9) 0%, oklch(0.365 0.05535 148.9 / 0.8) 56%, transparent 100%)",
},
sky: {
ground: "oklch(0.315 0.04989 29.9)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.875 0.07562 220.0) 0%, oklch(0.850 0.07874 220.3 / 0.7) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.365 0.05691 28.9) 0%, oklch(0.365 0.05691 28.9 / 0.8) 56%, transparent 100%)",
},
lilac: {
ground: "oklch(0.315 0.03869 99.9)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.875 0.05864 290.0) 0%, oklch(0.850 0.06106 290.3 / 0.7) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.365 0.04413 98.9) 0%, oklch(0.365 0.04413 98.9 / 0.8) 56%, transparent 100%)",
},
pewter: {
ground: "oklch(0.240 0.022 91.8)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.577 0.031 306.8) 0%, oklch(0.524 0.029 305.5 / 0.75) 54%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.263 0.022 329.5) 0%, oklch(0.263 0.022 329.5 / 0.85) 56%, transparent 100%)",
glow: "oklch(0.964 0.006 308.4)",
form: "medium",
period: "nocturne",
},
oxblood: {
ground: "oklch(0.247 0.023 277.2)",
upper:
"radial-gradient(ellipse 140% 110% at 50% 45%, oklch(0.456 0.136 21.1) 0%, oklch(0.456 0.136 21.1 / 0.5) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 100% at 50% 55%, oklch(0.655 0.090 76.4) 0%, oklch(0.655 0.090 76.4 / 0.5) 55%, transparent 100%)",
},
heather: {
ground: "oklch(0.561 0.203 32.9)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.923 0.021 48.5) 0%, oklch(0.915 0.019 38.1 / 0.75) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.550 0.091 357.3) 0%, oklch(0.602 0.095 359.5 / 0.8) 55%, transparent 100%)",
glow: "oklch(0.940 0.017 44.8)",
form: "strong",
},
chambray: {
ground: "oklch(0.280 0.110 251.6)",
upper: "oklch(0.905 0.040 251.6)",
lower: "oklch(0.450 0.155 251.6)",
glow: "oklch(0.840 0.075 251.6)",
form: "strong",
},
lichen: {
ground: "oklch(0.258 0.027 329.1)",
upper:
"radial-gradient(ellipse 140% 110% at 50% 45%, oklch(0.551 0.058 87.6) 0%, oklch(0.551 0.058 87.6 / 0.5) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 100% at 50% 55%, oklch(0.234 0.035 278.5) 0%, oklch(0.234 0.035 278.5 / 0.5) 55%, transparent 100%)",
period: "nocturne",
},
mallow: {
ground: "oklch(0.250 0.050 325)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.87 0.06 350) 0%, oklch(0.80 0.07 340 / 0.8) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.34 0.09 320) 0%, oklch(0.28 0.07 325 / 0.85) 56%, transparent 100%)",
glow: "oklch(0.88 0.07 350)",
form: "medium",
},
kiln: {
ground: "oklch(0.408 0.085 48.6)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.757 0.089 60.2) 0%, oklch(0.757 0.089 60.2 / 0.75) 53%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.583 0.121 44.5) 0%, oklch(0.583 0.121 44.5 / 0.8) 55%, transparent 100%)",
glow: "oklch(0.834 0.088 72.9)",
form: "strong",
},
}
/** One line per palette, for pickers and captions. */
const ORBITAL_PALETTE_NOTES: Record<OrbitalPaletteName, string> = {
gold: "pale gold over indigo, the Orbital default",
delft: "cream over blue",
warmth: "gold over terracotta",
marigold: "gold over rust",
vesper: "pale peach over violet",
aurora: "mint over deep green",
gesso: "warm white over red-orange",
plaster: "rose over plaster",
moss: "sky over warm grey",
tidepool: "teal over deep blue",
vermillion: "cream over oxblood",
cocoa: "pale sand over cocoa",
linen: "pale sand over umber",
tarn: "gold over deep teal",
"gold-dark": "dim gold over near-black blue",
mint: "pale mint over plum",
rose: "pale pink over deep green",
sky: "pale blue over dark brown",
lilac: "pale lilac over dark olive",
pewter: "grey lilac over dark umber",
oxblood: "oxblood over ochre",
heather: "warm white over dusty rose",
chambray: "pale blue over deep blue",
lichen: "khaki over dark indigo",
mallow: "pale pink over plum",
kiln: "apricot over terracotta",
}
export { ORBITAL_PALETTES, ORBITAL_PALETTE_NOTES }
export type { OrbitalPalette, OrbitalPaletteName }
Installation
pnpm dlx shadcn@latest add @01orbital/noise-displaced-scenenpx shadcn@latest add @01orbital/noise-displaced-sceneyarn dlx shadcn@latest add @01orbital/noise-displaced-scenebunx --bun shadcn@latest add @01orbital/noise-displaced-sceneUsage
import { NoiseDisplacedScene } from "@/components/scene/noise-displaced-scene"
export default function Example() {
return <NoiseDisplacedScene />
}Examples
Burgundy Over Mauvenoise-displaced-scene-burgundy-over-mauve
Noise Displaced Scene example: a burgundy field over a dusty mauve one, their wavering edges showing a rose ground, under a field of stars.
The source comes with full access.
One payment of $149 opens the source right here and lets the CLI install every paid component, with lifetime updates.
pnpm dlx shadcn@latest add @01orbital/noise-displaced-scene-burgundy-over-mauvenpx shadcn@latest add @01orbital/noise-displaced-scene-burgundy-over-mauveyarn dlx shadcn@latest add @01orbital/noise-displaced-scene-burgundy-over-mauvebunx --bun shadcn@latest add @01orbital/noise-displaced-scene-burgundy-over-mauveTeal Over Mauvenoise-displaced-scene-teal-over-mauve
Noise Displaced Scene example: a deep teal field over a dusty mauve one, their wavering edges showing a cornflower blue ground, with the scene's own grain.
import { NoiseDisplacedScene } from "@/components/scene/noise-displaced-scene"
const COLORS = {
ground: { l: 0.639, c: 0.118, h: 264.5 },
upper: { l: 0.328, c: 0.085, h: 222.9 },
lower: { l: 0.74, c: 0.027, h: 4.4 },
} as const
export default function NoiseDisplacedSceneTealOverMauve() {
return (
<div className="dark relative isolate min-h-[32rem] w-full flex-1 overflow-hidden bg-background">
<NoiseDisplacedScene colors={COLORS} />
</div>
)
}
import { useId } from "react"
import { cn } from "cn"
import { ORBITAL_PALETTES } from "@/components/orbs/orbital-palettes"
import {
firstStops,
fmt,
type FieldAnchors,
type OklchColor,
} from "@/lib/field-layers"
const GRAIN = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='250' height='250'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='turbulence' baseFrequency='1.4' numOctaves='1'/%3E%3CfeComponentTransfer result='g'%3E%3CfeFuncR type='linear' slope='4' intercept='1'/%3E%3CfeFuncG type='linear' slope='4' intercept='1'/%3E%3CfeFuncB type='linear' slope='4' intercept='1'/%3E%3C/feComponentTransfer%3E%3CfeColorMatrix type='saturate' values='0' in='g'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`
// The one painting: the warmth palette from the shared table, read as its
// ground and first stops. `colors` overrides any of the three.
const WARMTH: FieldAnchors = firstStops(ORBITAL_PALETTES.warmth)
type NoiseDisplacedColors = Partial<FieldAnchors>
/**
* Full-bleed art layer — drop inside a `relative` parent; sits behind content.
*/
function NoiseDisplacedScene({
className,
colors,
horizon = 50,
grain = true,
...props
}: Omit<React.ComponentProps<"div">, "children"> & {
/** Set false when stacking your own grain on top. */
grain?: boolean
/** OKLCH overrides for the `ground`, `upper` and `lower` anchors. */
colors?: NoiseDisplacedColors
/**
* Vertical seam position 0–100. 50 = default heights; lower pulls the seam
* up.
*/
horizon?: number
}) {
// useId alone can emit characters that are illegal in an SVG id.
const uid = useId().replace(/[^a-zA-Z0-9]/g, "")
const upperFilter = `nd-${uid}-1`
const lowerFilter = `nd-${uid}-2`
const base = WARMTH
const ground = colors?.ground ?? base.ground
const upper = colors?.upper ?? base.upper
const lower = colors?.lower ?? base.lower
// 0 and 100 both overflow the box; clamp to the usable band.
const h = Number.isFinite(horizon) ? Math.min(95, Math.max(5, horizon)) : 50
const upperH = h + 5
const lowerH = 102 - h
return (
<div
className={cn(
"pointer-events-none absolute inset-0 overflow-hidden",
className
)}
aria-hidden="true"
data-slot="noise-displaced-scene"
{...props}
>
<svg className="absolute size-0" aria-hidden="true">
<defs>
<filter id={upperFilter} x="-10%" y="-10%" width="120%" height="120%">
<feTurbulence
type="fractalNoise"
baseFrequency="0.01 0.005"
numOctaves={2}
seed={1}
result="noise"
/>
<feDisplacementMap
in="SourceGraphic"
in2="noise"
scale={25}
xChannelSelector="R"
yChannelSelector="G"
/>
</filter>
<filter id={lowerFilter} x="-10%" y="-10%" width="120%" height="120%">
<feTurbulence
type="fractalNoise"
baseFrequency="0.008 0.004"
numOctaves={3}
seed={5}
result="noise"
/>
<feDisplacementMap
in="SourceGraphic"
in2="noise"
scale={20}
xChannelSelector="R"
yChannelSelector="G"
/>
</filter>
</defs>
</svg>
<div className="absolute inset-0" style={{ background: fmt(ground) }} />
<div
className="absolute inset-x-0 top-0"
style={{
height: `${upperH}%`,
background: fmt(upper),
filter: `url(#${upperFilter})`,
}}
/>
<div
className="absolute inset-x-0 bottom-0"
style={{
height: `${lowerH}%`,
background: fmt(lower),
filter: `url(#${lowerFilter})`,
}}
/>
{grain && (
<div
className="absolute inset-0 opacity-20 mix-blend-overlay"
style={{ backgroundImage: GRAIN }}
/>
)}
</div>
)
}
export { NoiseDisplacedScene }
export type { OklchColor as NoiseDisplacedOklch }
// The OKLCH math the painted scenes share: a color, a shift of it and its
// CSS string, used across components/scene; plus the two blurred fields over
// a ground that ColorFieldWash and HorizonGlazeScene build from three anchors.
// Plain functions, no React, so a scene can also precompute its palettes.
export type OklchColor = { l: number; c: number; h: number }
/** The three colors a field is painted from. */
export type FieldAnchors = {
ground: OklchColor
upper: OklchColor
lower: OklchColor
}
/** The CSS backgrounds built from the anchors. */
export type FieldLayers = {
ground: string
upper: string
lower: string
}
export function shift(base: OklchColor, dl = 0, dc = 0, dh = 0): OklchColor {
return {
l: Math.max(0, Math.min(1, base.l + dl)),
c: Math.max(0, base.c + dc),
h: (base.h + dh + 360) % 360,
}
}
export function fmt(c: OklchColor, alpha?: number): string {
const l = Math.round(c.l * 1000) / 1000
const ch = Math.round(c.c * 1000) / 1000
const h = Math.round(c.h * 10) / 10
const a = alpha != null ? ` / ${alpha}` : ""
return `oklch(${l} ${ch} ${h}${a})`
}
export const clean = <T extends object>(o: T) =>
Object.fromEntries(Object.entries(o).filter(([, v]) => v !== undefined)) as T
// Upper field: a little darker, duller and cooler toward its edge; lower
// field the same, more so. The geometry matches the hand-tuned palettes
// that share this shape.
export function buildFieldLayers(a: FieldAnchors): FieldLayers {
return {
ground: fmt(a.ground),
upper: `radial-gradient(ellipse 130% 100% at 50% 35%, ${fmt(a.upper)} 0%, ${fmt(shift(a.upper, -0.025, -0.003, -3), 0.7)} 55%, transparent 100%)`,
lower: `radial-gradient(ellipse 130% 90% at 50% 80%, ${fmt(a.lower)} 0%, ${fmt(shift(a.lower, -0.03, -0.009, -1.5), 0.8)} 55%, transparent 100%)`,
}
}
/**
* The anchors behind a palette written as CSS: the ground and the first
* `oklch()` stop of each field. Lets a scene seed its overrides from a
* palette it already has as strings, so the numbers live once.
*/
export function firstStops(p: FieldLayers): FieldAnchors {
const first = (css: string): OklchColor => {
const m = /oklch\(([\d.]+) ([\d.]+) ([\d.]+)/.exec(css)
if (!m) throw new Error(`field-layers: no oklch() stop in ${css}`)
return { l: Number(m[1]), c: Number(m[2]), h: Number(m[3]) }
}
return {
ground: first(p.ground),
upper: first(p.upper),
lower: first(p.lower),
}
}
// Named palettes for the painted fields: a ground with an upper and a lower
// field blurred over it, the way Orbital paints a ball and ColorWash paints
// a panel. Plain data with no imports, so any component can read it. Pass a
// name to ColorWash as `color`, or an entry (or your own object of the same
// shape) to Orbital or ColorWash as `palette`.
type OrbitalPalette = {
/** The base color under everything else, any CSS color. */
ground: string
/** A CSS background, usually a radial gradient, blurred over the top. */
upper: string
/** A CSS background blurred over the bottom. */
lower: string
/** The orb's glow: an inner bloom and a halo. ColorWash ignores it. */
glow?: string
/** The orb's preferred shading tier. ColorWash ignores it. */
form?: "off" | "medium" | "strong"
/** Read by nothing today; kept so older palettes still type-check. */
period?: "nocturne"
}
type OrbitalPaletteName =
| "gold"
| "delft"
| "warmth"
| "marigold"
| "vesper"
| "aurora"
| "gesso"
| "plaster"
| "moss"
| "tidepool"
| "vermillion"
| "cocoa"
| "linen"
| "tarn"
| "gold-dark"
| "mint"
| "rose"
| "sky"
| "lilac"
| "pewter"
| "oxblood"
| "heather"
| "chambray"
| "lichen"
| "mallow"
| "kiln"
const ORBITAL_PALETTES: Record<OrbitalPaletteName, OrbitalPalette> = {
gold: {
ground: "oklch(0.315 0.064 270.3)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.875 0.097 100.4) 0%, oklch(0.850 0.101 100.7 / 0.7) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.365 0.073 269.3) 0%, oklch(0.365 0.073 269.3 / 0.8) 56%, transparent 100%)",
glow: "oklch(0.936 0.055 102.9)",
form: "strong",
},
delft: {
ground: "oklch(0.376 0.087 261.9)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.905 0.025 104.4) 0%, oklch(0.887 0.026 104.5 / 0.72) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.467 0.121 261.9) 0%, oklch(0.467 0.121 261.9 / 0.8) 55%, transparent 100%)",
glow: "oklch(0.978 0.010 261.8)",
form: "strong",
},
warmth: {
ground: "oklch(0.652 0.147 52.4)",
upper:
"radial-gradient(ellipse 130% 100% at 50% 35%, oklch(0.836 0.159 96.2) 0%, oklch(0.814 0.157 92.4 / 0.7) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 90% at 50% 80%, oklch(0.518 0.176 28.9) 0%, oklch(0.487 0.167 27.7 / 0.8) 55%, transparent 100%)",
glow: "oklch(0.836 0.159 96.2)",
},
marigold: {
ground: "oklch(0.379 0.076 35.6)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.805 0.160 71.9) 0%, oklch(0.805 0.160 71.9 / 0.75) 53%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.243 0.023 32.4) 0%, oklch(0.243 0.023 32.4 / 0.88) 56%, transparent 100%)",
glow: "oklch(0.829 0.154 76.5)",
form: "strong",
},
vesper: {
ground: "oklch(0.28 0.06 300)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.90 0.04 55) 0%, oklch(0.90 0.04 55 / 0.7) 53%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.42 0.13 305) 0%, oklch(0.42 0.13 305 / 0.85) 56%, transparent 100%)",
glow: "oklch(0.82 0.07 50)",
form: "strong",
},
aurora: {
ground: "oklch(0.318 0.057 158.2)",
upper:
"radial-gradient(ellipse 140% 110% at 50% 45%, oklch(0.890 0.129 146.1) 0%, oklch(0.890 0.129 146.1 / 0.5) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 100% at 50% 55%, oklch(0.236 0.055 296.3) 0%, oklch(0.236 0.055 296.3 / 0.5) 55%, transparent 100%)",
},
gesso: {
ground: "oklch(0.563 0.167 30.8)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.919 0.014 53.3) 0%, oklch(0.907 0.011 45.7 / 0.75) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.621 0.161 28.1) 0%, oklch(0.621 0.161 28.1 / 0.8) 55%, transparent 100%)",
glow: "oklch(0.949 0.014 53.3)",
form: "strong",
},
plaster: {
ground: "oklch(0.728 0.030 93.8)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.787 0.035 68.7) 0%, oklch(0.787 0.035 68.7 / 0.65) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.547 0.181 27.1) 0%, oklch(0.516 0.172 26.6 / 0.75) 55%, transparent 100%)",
glow: "oklch(0.561 0.158 29.1)",
form: "strong",
},
moss: {
ground: "oklch(0.313 0.006 34.3)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.561 0.039 200.7) 0%, oklch(0.507 0.038 203.1 / 0.7) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.373 0.047 214.5) 0%, oklch(0.395 0.046 210.5 / 0.8) 56%, transparent 100%)",
glow: "oklch(0.659 0.131 237.7)",
form: "medium",
},
tidepool: {
ground: "oklch(0.179 0.029 240.3)",
upper:
"radial-gradient(ellipse 140% 110% at 50% 45%, oklch(0.413 0.082 166.3) 0%, oklch(0.413 0.082 166.3 / 0.5) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 100% at 50% 55%, oklch(0.962 0.077 113.3) 0%, oklch(0.962 0.077 113.3 / 0.5) 55%, transparent 100%)",
},
vermillion: {
ground: "oklch(0.235 0.06 18.06)",
upper:
"radial-gradient(ellipse 130% 100% at 50% 38%, oklch(0.66 0.205 30.97) 0%, oklch(0.619 0.205 30.96 / 60%) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 90% at 50% 82%, oklch(0.28 0.136 266.87) 0%, oklch(0.25 0.136 267.22 / 70%) 55%, transparent 100%)",
},
cocoa: {
ground: "oklch(0.306 0.066 45.1)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.794 0.054 64.1) 0%, oklch(0.794 0.054 64.1 / 0.75) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.457 0.115 42.0) 0%, oklch(0.457 0.115 42.0 / 0.84) 56%, transparent 100%)",
glow: "oklch(0.762 0.120 49.2)",
form: "strong",
},
linen: {
ground: "oklch(0.267 0.021 54.1)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.782 0.021 58.0) 0%, oklch(0.782 0.021 58.0 / 0.75) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.363 0.028 53.6) 0%, oklch(0.363 0.028 53.6 / 0.85) 56%, transparent 100%)",
glow: "oklch(0.994 0.000 89.9)",
form: "strong",
},
tarn: {
ground: "oklch(0.286 0.036 189.5)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.757 0.155 95.6) 0%, oklch(0.757 0.155 95.6 / 0.72) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.468 0.065 190.9) 0%, oklch(0.468 0.065 190.9 / 0.82) 56%, transparent 100%)",
glow: "oklch(0.831 0.167 96.2)",
form: "strong",
},
"gold-dark": {
ground: "oklch(0.16 0.04 270)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.29 0.06 100) 0%, oklch(0.27 0.06 101 / 0.7) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.23 0.07 269) 0%, oklch(0.23 0.07 269 / 0.8) 56%, transparent 100%)",
},
mint: {
ground: "oklch(0.315 0.06368 314.9)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.875 0.09651 145.0) 0%, oklch(0.850 0.10049 145.3 / 0.7) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.365 0.07263 313.9) 0%, oklch(0.365 0.07263 313.9 / 0.8) 56%, transparent 100%)",
},
rose: {
ground: "oklch(0.315 0.04852 149.9)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.875 0.07355 340.0) 0%, oklch(0.850 0.07658 340.3 / 0.7) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.365 0.05535 148.9) 0%, oklch(0.365 0.05535 148.9 / 0.8) 56%, transparent 100%)",
},
sky: {
ground: "oklch(0.315 0.04989 29.9)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.875 0.07562 220.0) 0%, oklch(0.850 0.07874 220.3 / 0.7) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.365 0.05691 28.9) 0%, oklch(0.365 0.05691 28.9 / 0.8) 56%, transparent 100%)",
},
lilac: {
ground: "oklch(0.315 0.03869 99.9)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.875 0.05864 290.0) 0%, oklch(0.850 0.06106 290.3 / 0.7) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.365 0.04413 98.9) 0%, oklch(0.365 0.04413 98.9 / 0.8) 56%, transparent 100%)",
},
pewter: {
ground: "oklch(0.240 0.022 91.8)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.577 0.031 306.8) 0%, oklch(0.524 0.029 305.5 / 0.75) 54%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.263 0.022 329.5) 0%, oklch(0.263 0.022 329.5 / 0.85) 56%, transparent 100%)",
glow: "oklch(0.964 0.006 308.4)",
form: "medium",
period: "nocturne",
},
oxblood: {
ground: "oklch(0.247 0.023 277.2)",
upper:
"radial-gradient(ellipse 140% 110% at 50% 45%, oklch(0.456 0.136 21.1) 0%, oklch(0.456 0.136 21.1 / 0.5) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 100% at 50% 55%, oklch(0.655 0.090 76.4) 0%, oklch(0.655 0.090 76.4 / 0.5) 55%, transparent 100%)",
},
heather: {
ground: "oklch(0.561 0.203 32.9)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.923 0.021 48.5) 0%, oklch(0.915 0.019 38.1 / 0.75) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.550 0.091 357.3) 0%, oklch(0.602 0.095 359.5 / 0.8) 55%, transparent 100%)",
glow: "oklch(0.940 0.017 44.8)",
form: "strong",
},
chambray: {
ground: "oklch(0.280 0.110 251.6)",
upper: "oklch(0.905 0.040 251.6)",
lower: "oklch(0.450 0.155 251.6)",
glow: "oklch(0.840 0.075 251.6)",
form: "strong",
},
lichen: {
ground: "oklch(0.258 0.027 329.1)",
upper:
"radial-gradient(ellipse 140% 110% at 50% 45%, oklch(0.551 0.058 87.6) 0%, oklch(0.551 0.058 87.6 / 0.5) 55%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 100% at 50% 55%, oklch(0.234 0.035 278.5) 0%, oklch(0.234 0.035 278.5 / 0.5) 55%, transparent 100%)",
period: "nocturne",
},
mallow: {
ground: "oklch(0.250 0.050 325)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.87 0.06 350) 0%, oklch(0.80 0.07 340 / 0.8) 52%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.34 0.09 320) 0%, oklch(0.28 0.07 325 / 0.85) 56%, transparent 100%)",
glow: "oklch(0.88 0.07 350)",
form: "medium",
},
kiln: {
ground: "oklch(0.408 0.085 48.6)",
upper:
"radial-gradient(ellipse 135% 105% at 50% 35%, oklch(0.757 0.089 60.2) 0%, oklch(0.757 0.089 60.2 / 0.75) 53%, transparent 100%)",
lower:
"radial-gradient(ellipse 130% 95% at 50% 80%, oklch(0.583 0.121 44.5) 0%, oklch(0.583 0.121 44.5 / 0.8) 55%, transparent 100%)",
glow: "oklch(0.834 0.088 72.9)",
form: "strong",
},
}
/** One line per palette, for pickers and captions. */
const ORBITAL_PALETTE_NOTES: Record<OrbitalPaletteName, string> = {
gold: "pale gold over indigo, the Orbital default",
delft: "cream over blue",
warmth: "gold over terracotta",
marigold: "gold over rust",
vesper: "pale peach over violet",
aurora: "mint over deep green",
gesso: "warm white over red-orange",
plaster: "rose over plaster",
moss: "sky over warm grey",
tidepool: "teal over deep blue",
vermillion: "cream over oxblood",
cocoa: "pale sand over cocoa",
linen: "pale sand over umber",
tarn: "gold over deep teal",
"gold-dark": "dim gold over near-black blue",
mint: "pale mint over plum",
rose: "pale pink over deep green",
sky: "pale blue over dark brown",
lilac: "pale lilac over dark olive",
pewter: "grey lilac over dark umber",
oxblood: "oxblood over ochre",
heather: "warm white over dusty rose",
chambray: "pale blue over deep blue",
lichen: "khaki over dark indigo",
mallow: "pale pink over plum",
kiln: "apricot over terracotta",
}
export { ORBITAL_PALETTES, ORBITAL_PALETTE_NOTES }
export type { OrbitalPalette, OrbitalPaletteName }
pnpm dlx shadcn@latest add @01orbital/noise-displaced-scene-teal-over-mauvenpx shadcn@latest add @01orbital/noise-displaced-scene-teal-over-mauveyarn dlx shadcn@latest add @01orbital/noise-displaced-scene-teal-over-mauvebunx --bun shadcn@latest add @01orbital/noise-displaced-scene-teal-over-mauveAPI reference
Full-bleed art layer — drop inside a relative parent; sits behind content.
Prop
Type
It also accepts the HTML attributes of the element it renders.
Dependencies
npm: cn. The CLI installs it for you.
Requires these pieces. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
Last updated on