Copper Pour
Full-bleed background: copper pigment poured in vertical curtains over deep blue, dimmed behind a painted canvas texture.
import { PourScene } from "@/components/scene/pour-scene"
import { PaintedCanvas } from "@/components/texture/painted-canvas"
const ANCHORS = {
pigment: { l: 0.833, c: 0.218, h: 43.3 },
base: { l: 0.551, c: 0.22, h: 177 },
blend: { l: 0.418, c: 0.246, h: 222.5 },
} as const
const LAYOUT_SEED = 774989887
export default function CopperPour01() {
return (
<div className="dark relative isolate min-h-[32rem] w-full flex-1 overflow-hidden bg-background">
<PourScene
anchors={ANCHORS}
layoutSeed={LAYOUT_SEED}
dampen={0.7}
grain={false}
/>
<PaintedCanvas />
</div>
)
}
import { cn } from "cn"
const GRAIN_FINE = `url("data:image/svg+xml,%3Csvg viewBox='0 0 128 128' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='g3'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='2' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g3)'/%3E%3C/svg%3E")`
const GRAIN_MEDIUM = `url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='g2'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g2)'/%3E%3C/svg%3E")`
const GRAIN_COARSE =
"url(\"data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.7' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23g)'/%3E%3C/svg%3E\")"
/**
* Sealed pastel canvas: three grain blends and a cross-hatch over your
* ground. Full-bleed art layer: drop it inside a `relative` parent; it sits
* behind content.
*/
function PaintedCanvas({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
className={cn("pointer-events-none absolute inset-0", className)}
aria-hidden="true"
data-slot="painted-canvas"
{...props}
>
{/* three grain passes — overlay, soft-light, faint color-dodge bloom */}
<div
className="absolute inset-0 bg-size-[120px] opacity-32 mix-blend-overlay"
style={{ backgroundImage: GRAIN_COARSE }}
/>
<div
className="absolute inset-0 bg-size-[90px] opacity-20 mix-blend-soft-light"
style={{ backgroundImage: GRAIN_MEDIUM }}
/>
<div
className="absolute inset-0 bg-size-[60px] opacity-14 mix-blend-color-dodge"
style={{ backgroundImage: GRAIN_FINE }}
/>
{/* cross-hatch — two diagonal passes (-35°/55°) read as pencil strokes */}
<div
className="absolute inset-0 mix-blend-overlay"
style={{
backgroundImage: [
"repeating-linear-gradient(-35deg, transparent 0px, transparent 3px, oklch(1 0 0 / 0.025) 3px, oklch(1 0 0 / 0.04) 5px)",
"repeating-linear-gradient(55deg, transparent 0px, transparent 5px, oklch(0 0 0 / 0.04) 5px, oklch(0 0 0 / 0.055) 7px)",
].join(", "),
}}
/>
{/* paper warp — faint horizontal striations, like canvas weave */}
<div
className="absolute inset-0 mix-blend-overlay"
style={{
backgroundImage: [
"repeating-linear-gradient(2deg, transparent 0px, transparent 7px, oklch(1 0 0 / 0.02) 7px, oklch(1 0 0 / 0.03) 8px)",
"repeating-linear-gradient(-1deg, transparent 0px, transparent 9px, oklch(0 0 0 / 0.025) 9px, oklch(0 0 0 / 0.035) 10px)",
].join(", "),
}}
/>
</div>
)
}
export { PaintedCanvas }
import { cn } from "cn"
import { clean, type OklchColor } from "@/lib/field-layers"
// Sandpaper grain: an SVG turbulence filter as a data URI.
const SANDPAPER_GRAIN = `url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 100 100'%3E%3Cfilter id='n' color-interpolation-filters='sRGB'%3E%3CfeTurbulence type='turbulence' baseFrequency='2.2' numOctaves='2' seed='5' stitchTiles='stitch' result='n'/%3E%3CfeComponentTransfer result='g'%3E%3CfeFuncR type='linear' slope='2.5' intercept='0.8'/%3E%3CfeFuncG type='linear' slope='2.5' intercept='0.8'/%3E%3CfeFuncB type='linear' slope='2.5' intercept='0.8'/%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")`
// Palette-driven drip series. Pass `seed` for procedural combos or `anchors`
// for a custom palette; seeds render bit-for-bit stable.
const SQUARE_GRAIN = `url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200' viewBox='0 0 100 100'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='turbulence' baseFrequency='2.1' numOctaves='3' seed='11' stitchTiles='stitch' result='n'/%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")`
type Palette = {
field: string
meetingTop: string
meetingHeight: string
meetingBand: string
dripsWideTop: string
dripsWide: string
dripsMidTop: string
dripsMid: string
dripsFineTop: string
dripsFine: string
/**
* Background variant's screen-blended highlights; omitted = the cream
* default.
*/
dripsCrisp?: string
}
const PALETTES = {
"charcoal-on-brick": {
field: `linear-gradient(180deg,
oklch(0.42 0.13 32) 0%, oklch(0.24 0.01 250) 12%, oklch(0.23 0.01 250) 40%,
oklch(0.45 0.015 250) 49%, oklch(0.78 0.012 90) 57%, oklch(0.80 0.01 92) 80%, oklch(0.46 0.14 34) 100%)`,
meetingTop: "42%",
meetingHeight: "18%",
meetingBand:
"linear-gradient(180deg, transparent 0%, oklch(0.55 0.02 60 / 0.5) 50%, transparent 100%)",
dripsWideTop: "44%",
dripsWide: [
"linear-gradient(180deg, oklch(0.24 0.01 250 / 0.85) 0%, oklch(0.60 0.012 80 / 0.55) 50%, transparent 92%) 8% 0/9% 66% no-repeat",
"linear-gradient(180deg, oklch(0.23 0.01 250 / 0.8) 0%, oklch(0.64 0.01 84 / 0.5) 55%, transparent 100%) 22% 0/7% 84% no-repeat",
"linear-gradient(180deg, oklch(0.25 0.01 250 / 0.85) 0%, oklch(0.58 0.012 78 / 0.55) 45%, transparent 85%) 33% 0/11% 52% no-repeat",
"linear-gradient(180deg, oklch(0.23 0.01 250 / 0.8) 0%, oklch(0.66 0.01 86 / 0.5) 52%, transparent 100%) 46% 0/8% 78% no-repeat",
"linear-gradient(180deg, oklch(0.24 0.01 250 / 0.82) 0%, oklch(0.60 0.012 82 / 0.52) 48%, transparent 90%) 57% 0/7% 60% no-repeat",
"linear-gradient(180deg, oklch(0.23 0.01 250 / 0.8) 0%, oklch(0.64 0.01 84 / 0.5) 54%, transparent 100%) 67% 0/10% 88% no-repeat",
"linear-gradient(180deg, oklch(0.24 0.01 250 / 0.84) 0%, oklch(0.59 0.012 80 / 0.52) 46%, transparent 86%) 80% 0/9% 48% no-repeat",
"linear-gradient(180deg, oklch(0.23 0.01 250 / 0.8) 0%, oklch(0.66 0.01 86 / 0.5) 56%, transparent 100%) 91% 0/7% 72% no-repeat",
].join(", "),
dripsMidTop: "45%",
dripsMid: [
"linear-gradient(180deg, oklch(0.26 0.01 250 / 0.8) 0%, oklch(0.62 0.012 82 / 0.55) 50%, transparent 88%) 14% 0/2.5% 56% no-repeat",
"linear-gradient(180deg, oklch(0.23 0.01 250 / 0.78) 0%, oklch(0.66 0.01 84 / 0.5) 55%, transparent 100%) 27% 0/3% 80% no-repeat",
"linear-gradient(180deg, oklch(0.27 0.01 250 / 0.8) 0%, oklch(0.58 0.012 78 / 0.55) 45%, transparent 80%) 39% 0/2% 46% no-repeat",
"linear-gradient(180deg, oklch(0.23 0.01 250 / 0.78) 0%, oklch(0.68 0.01 86 / 0.5) 52%, transparent 100%) 51% 0/3.5% 86% no-repeat",
"linear-gradient(180deg, oklch(0.25 0.01 250 / 0.8) 0%, oklch(0.62 0.012 82 / 0.52) 48%, transparent 86%) 63% 0/2.5% 62% no-repeat",
"linear-gradient(180deg, oklch(0.24 0.01 250 / 0.78) 0%, oklch(0.64 0.01 84 / 0.5) 50%, transparent 100%) 74% 0/2% 72% no-repeat",
"linear-gradient(180deg, oklch(0.26 0.01 250 / 0.8) 0%, oklch(0.60 0.012 80 / 0.52) 46%, transparent 84%) 85% 0/3% 52% no-repeat",
].join(", "),
dripsFineTop: "46%",
dripsFine: [
"linear-gradient(180deg, oklch(0.30 0.01 250 / 0.7) 0%, oklch(0.64 0.012 82 / 0.5) 55%, transparent 92%) 18% 0/0.6% 50% no-repeat",
"linear-gradient(180deg, oklch(0.24 0.01 250 / 0.68) 0%, oklch(0.66 0.01 84 / 0.45) 58%, transparent 100%) 33% 0/0.8% 74% no-repeat",
"linear-gradient(180deg, oklch(0.32 0.01 250 / 0.7) 0%, oklch(0.58 0.012 78 / 0.5) 50%, transparent 86%) 47% 0/0.5% 42% no-repeat",
"linear-gradient(180deg, oklch(0.23 0.01 250 / 0.68) 0%, oklch(0.68 0.01 86 / 0.45) 54%, transparent 100%) 58% 0/0.7% 66% no-repeat",
"linear-gradient(180deg, oklch(0.28 0.01 250 / 0.7) 0%, oklch(0.62 0.012 82 / 0.5) 52%, transparent 90%) 70% 0/0.6% 56% no-repeat",
"linear-gradient(180deg, oklch(0.24 0.01 250 / 0.68) 0%, oklch(0.64 0.01 84 / 0.45) 50%, transparent 100%) 81% 0/0.8% 69% no-repeat",
].join(", "),
},
} as const satisfies Record<string, Palette>
type PourPalette = keyof typeof PALETTES
type DripGeo = {
x: number
w: number
h: number
mid: number
end: number
a: number
am: number
}
const WIDE_GEO: DripGeo[] = [
{ x: 8, w: 9, h: 70, mid: 50, end: 92, a: 0.85, am: 0.6 },
{ x: 22, w: 7, h: 88, mid: 55, end: 100, a: 0.8, am: 0.55 },
{ x: 33, w: 11, h: 56, mid: 45, end: 85, a: 0.85, am: 0.6 },
{ x: 46, w: 8, h: 80, mid: 52, end: 100, a: 0.8, am: 0.55 },
{ x: 57, w: 7, h: 64, mid: 48, end: 90, a: 0.82, am: 0.6 },
{ x: 67, w: 10, h: 92, mid: 54, end: 100, a: 0.8, am: 0.55 },
{ x: 80, w: 9, h: 50, mid: 46, end: 86, a: 0.84, am: 0.6 },
{ x: 91, w: 7, h: 76, mid: 56, end: 100, a: 0.8, am: 0.55 },
]
const MID_GEO: DripGeo[] = [
{ x: 14, w: 2.5, h: 60, mid: 50, end: 88, a: 0.8, am: 0.55 },
{ x: 27, w: 3, h: 84, mid: 55, end: 100, a: 0.78, am: 0.5 },
{ x: 39, w: 2, h: 50, mid: 45, end: 80, a: 0.8, am: 0.55 },
{ x: 51, w: 3.5, h: 90, mid: 52, end: 100, a: 0.78, am: 0.5 },
{ x: 63, w: 2.5, h: 66, mid: 48, end: 86, a: 0.8, am: 0.52 },
{ x: 74, w: 2, h: 76, mid: 50, end: 100, a: 0.78, am: 0.5 },
{ x: 85, w: 3, h: 56, mid: 46, end: 84, a: 0.8, am: 0.52 },
]
const FINE_GEO: DripGeo[] = [
{ x: 18, w: 0.6, h: 54, mid: 55, end: 92, a: 0.7, am: 0.5 },
{ x: 33, w: 0.8, h: 78, mid: 58, end: 100, a: 0.68, am: 0.45 },
{ x: 47, w: 0.5, h: 46, mid: 50, end: 86, a: 0.7, am: 0.5 },
{ x: 58, w: 0.7, h: 70, mid: 54, end: 100, a: 0.68, am: 0.45 },
{ x: 70, w: 0.6, h: 60, mid: 52, end: 90, a: 0.7, am: 0.5 },
{ x: 81, w: 0.8, h: 73, mid: 50, end: 100, a: 0.68, am: 0.45 },
]
type DripGeometry = { wide: DripGeo[]; mid: DripGeo[]; fine: DripGeo[] }
const DEFAULT_GEO: DripGeometry = {
wide: WIDE_GEO,
mid: MID_GEO,
fine: FINE_GEO,
}
function makeRng(seed: number) {
let s = seed | 0
return () => {
s = (s + 0x6d2b79f5) | 0
let t = Math.imul(s ^ (s >>> 15), 1 | s)
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t
return ((t ^ (t >>> 14)) >>> 0) / 4294967296
}
}
function rollDripGeometry(rng: () => number): DripGeometry {
const lerp = (lo: number, hi: number) => lo + rng() * (hi - lo)
const walk = (opts: {
wMin: number
wMax: number
aBase: number
amBase: number
gapScale: number
}): DripGeo[] => {
const out: DripGeo[] = []
let x = lerp(2, 14)
while (x < 96) {
out.push({
x: Math.round(x * 10) / 10,
w: Math.round(lerp(opts.wMin, opts.wMax) * 10) / 10,
h: Math.round(lerp(34, 98)),
mid: Math.round(lerp(42, 58)),
end: Math.round(lerp(82, 100)),
a: Math.round((opts.aBase + lerp(-0.04, 0.04)) * 100) / 100,
am: Math.round((opts.amBase + lerp(-0.05, 0.05)) * 100) / 100,
})
x += (rng() < 0.6 ? lerp(2, 6) : lerp(10, 30)) * opts.gapScale
}
return out
}
return {
wide: walk({ wMin: 4, wMax: 14, aBase: 0.82, amBase: 0.57, gapScale: 1 }),
mid: walk({
wMin: 1.5,
wMax: 4,
aBase: 0.79,
amBase: 0.52,
gapScale: 1.15,
}),
fine: walk({
wMin: 0.4,
wMax: 1,
aBase: 0.69,
amBase: 0.47,
gapScale: 1.3,
}),
}
}
function midpointHue(a: number, b: number) {
const delta = ((b - a + 540) % 360) - 180
return (((a + delta / 2) % 360) + 360) % 360
}
type PourAnchorShape = {
pigment: OklchColor
base: OklchColor
blend: OklchColor
}
type PourColors = Partial<PourAnchorShape>
function rollPourAnchors(rng: () => number, narrow = false): PourAnchorShape {
const lerp = (lo: number, hi: number) => lo + rng() * (hi - lo)
const topHue = rng() * 360
const offsets = [120, 150, 180, 210, 240]
const offset =
(narrow ? 20 + rng() * 20 : offsets[Math.floor(rng() * offsets.length)]) *
(rng() < 0.5 ? 1 : -1)
const bottomHue = (((topHue + offset) % 360) + 360) % 360
const blendHue = midpointHue(topHue, bottomHue)
return narrow
? {
pigment: { l: lerp(0.58, 0.68), c: lerp(0.15, 0.19), h: topHue },
base: { l: lerp(0.16, 0.24), c: lerp(0.07, 0.11), h: bottomHue },
blend: { l: lerp(0.34, 0.46), c: lerp(0.1, 0.14), h: blendHue },
}
: {
pigment: { l: lerp(0.54, 0.62), c: lerp(0.14, 0.18), h: topHue },
base: { l: lerp(0.2, 0.3), c: lerp(0.07, 0.11), h: bottomHue },
blend: { l: lerp(0.32, 0.44), c: lerp(0.1, 0.14), h: blendHue },
}
}
function buildPourPalette(
a: PourAnchorShape,
rng: () => number,
geo: DripGeometry = DEFAULT_GEO
): Palette {
const jitter = (base: number, amt: number) => base + (rng() - 0.5) * 2 * amt
const ok = (l: number, c: number, h: number, alpha?: number) =>
alpha == null
? `oklch(${l.toFixed(2)} ${c.toFixed(3)} ${h.toFixed(0)})`
: `oklch(${l.toFixed(2)} ${c.toFixed(3)} ${h.toFixed(0)} / ${alpha})`
const { l: topL, c: topC, h: topHue } = a.pigment
const { l: botL, c: botC, h: bottomHue } = a.base
const { l: blendL, c: blendC, h: blendHue } = a.blend
const field = `linear-gradient(180deg,
${ok(topL - 0.26, topC - 0.07, topHue)} 0%, ${ok(topL, topC, topHue)} 14%, ${ok(topL + 0.03, topC + 0.01, topHue)} 36%,
${ok(topL - 0.07, topC - 0.01, topHue)} 48%, ${ok(botL + 0.06, botC + 0.02, bottomHue)} 58%, ${ok(botL, botC, bottomHue)} 80%, ${ok(botL - 0.04, botC - 0.01, bottomHue)} 100%)`
const drip = (g: DripGeo, headBoost = 0) =>
`linear-gradient(180deg, ${ok(jitter(topL + headBoost, 0.03), topC, jitter(topHue, 3), g.a)} 0%, ${ok(jitter(blendL, 0.02), blendC, jitter(blendHue, 6), g.am)} ${g.mid}%, transparent ${g.end}%) ${g.x}% 0/${g.w}% ${g.h}% no-repeat`
return {
field,
meetingTop: "0%",
meetingHeight: "100%",
meetingBand: `linear-gradient(180deg, transparent 0%, ${ok(blendL + 0.05, blendC, blendHue, 0.5)} 50%, transparent 100%)`,
dripsWideTop: "0%",
dripsWide: geo.wide.map((g) => drip(g)).join(", "),
dripsMidTop: "0%",
dripsMid: geo.mid.map((g) => drip(g)).join(", "),
dripsFineTop: "0%",
dripsFine: geo.fine.map((g) => drip(g, 0.08)).join(", "),
dripsCrisp: crispDrips(topHue),
}
}
function generatePourPalette(
seed: number,
geo?: DripGeometry,
narrow = false
): Palette {
const rng = makeRng(seed)
return buildPourPalette(rollPourAnchors(rng, narrow), rng, geo)
}
const roundAnchor = (c: OklchColor): OklchColor => ({
l: Math.round(c.l * 1000) / 1000,
c: Math.round(c.c * 1000) / 1000,
h: Math.round(c.h * 10) / 10,
})
const rollDefaultAnchors = (narrow: boolean): PourAnchorShape => {
const a = rollPourAnchors(makeRng(6968), narrow)
return {
pigment: roundAnchor(a.pigment),
base: roundAnchor(a.base),
blend: roundAnchor(a.blend),
}
}
const POUR_DEFAULT_ANCHORS = rollDefaultAnchors(false)
const NARROW_DEFAULT_ANCHORS = rollDefaultAnchors(true)
// Pale highlights in the pigment's hue; named palettes keep the cream (90).
function crispDrips(hue: number) {
const h = hue.toFixed(0)
return `linear-gradient(180deg, oklch(0.97 0.02 ${h} / 0.8) 0%, oklch(0.85 0.05 ${h} / 0.35) 55%, transparent 92%) 29% 0/0.6% 70% no-repeat, linear-gradient(180deg, oklch(0.97 0.02 ${h} / 0.72) 0%, oklch(0.85 0.05 ${h} / 0.3) 50%, transparent 88%) 64% 0/0.5% 56% no-repeat`
}
const GRAIN_MASK =
"linear-gradient(180deg, oklch(0 0 0 / 0.5) 0%, oklch(0 0 0) 22%, oklch(0 0 0) 52%, oklch(0 0 0 / 0.15) 82%, transparent 100%)"
const DRIFT_CSS = `
[data-slot="pour-scene"] .pour-drift-a { animation: pour-drift-a 17s ease-in-out infinite; }
[data-slot="pour-scene"] .pour-drift-b { animation: pour-drift-b 13s ease-in-out infinite; }
[data-slot="pour-scene"] .pour-drift-c { animation: pour-drift-c 10s ease-in-out infinite; }
[data-slot="pour-scene"] .pour-grain-pulse { animation: pour-grain-pulse 5.5s ease-in-out infinite; }
@keyframes pour-drift-a { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-6px) } }
@keyframes pour-drift-b { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-9px) } }
@keyframes pour-drift-c { 0%,100% { transform: translateY(0) } 50% { transform: translateY(-13px) } }
@keyframes pour-grain-pulse { 0%,100% { opacity: 0.55 } 50% { opacity: 0.85 } }
@media (prefers-reduced-motion: reduce) {
[data-slot="pour-scene"] .pour-drift-a, [data-slot="pour-scene"] .pour-drift-b,
[data-slot="pour-scene"] .pour-drift-c, [data-slot="pour-scene"] .pour-grain-pulse { animation: none; }
}`
/**
* Full-bleed art layer — drop inside a `relative` parent; sits behind content.
*/
function PourScene({
palette = "charcoal-on-brick",
seed,
anchors,
layers,
layoutSeed,
variant = "painting",
animate = variant === "background",
vignette = variant === "background",
dampen = 0,
className,
style,
grain = true,
...props
}: Omit<React.ComponentProps<"div">, "children"> & {
/** Set false when stacking your own grain on top. */
grain?: boolean
/**
* The named colors; `charcoal-on-brick` by default. `seed` and `anchors`
* override it.
*/
palette?: PourPalette
/**
* "background": closer hues, dark foot, crisp blooms, grain in the middle.
*/
variant?: "painting" | "background"
/**
* Slow drip drift. Defaults on for the background variant, as does vignette.
*/
animate?: boolean
/** Darkens the edges; on by default for the background variant. */
vignette?: boolean
/** 0 = full intensity, 1 = most dimmed; ~0.5 sits it behind UI. */
dampen?: number
/** Procedural colors, poured from the top of the frame. Overrides `palette`; `anchors` takes precedence. */
seed?: number
/** Rebuilds the colors from pigment, base and blend anchors, poured from the top of the frame. Overrides `seed` and `palette`. */
anchors?: PourColors
/** Raw palette fields patched over whatever the pour resolved to. */
layers?: Partial<Palette>
/** Rolls an irregular drip arrangement (named palettes stay fixed). */
layoutSeed?: number
}) {
const bg = variant === "background"
const geo =
layoutSeed != null ? rollDripGeometry(makeRng(layoutSeed)) : undefined
const resolved: Palette = anchors
? buildPourPalette(
{
...(bg ? NARROW_DEFAULT_ANCHORS : POUR_DEFAULT_ANCHORS),
...clean(anchors),
},
makeRng(seed ?? 6968),
geo
)
: seed !== undefined
? generatePourPalette(seed, geo, bg)
: PALETTES[palette]
const p = layers ? { ...resolved, ...layers } : resolved
const intensity = 1 - Math.max(0, Math.min(1, dampen)) * 0.6
const grainMask = bg ? { maskImage: GRAIN_MASK } : undefined
return (
<div
className={cn(
"pointer-events-none absolute inset-0 overflow-hidden",
className
)}
aria-hidden="true"
style={intensity < 1 ? { opacity: intensity, ...style } : style}
{...props}
// After the spread: the drift CSS selects on it.
data-slot="pour-scene"
>
{animate && (
<style href="pour-scene-drift" precedence="default">
{DRIFT_CSS}
</style>
)}
<div
className="absolute inset-x-0 blur-[30px]"
style={{
top: p.meetingTop,
height: p.meetingHeight,
background: p.meetingBand,
}}
/>
<div
className={cn(
"absolute inset-x-0 bottom-0 opacity-60",
bg ? "blur-sm" : "blur-[7px]",
animate && "pour-drift-a"
)}
style={{ top: p.dripsWideTop, background: p.dripsWide }}
/>
<div
className={cn(
"absolute inset-x-0 bottom-0 opacity-50 blur-[2.5px]",
animate && "pour-drift-b"
)}
style={{ top: p.dripsMidTop, background: p.dripsMid }}
/>
<div
className={cn(
"absolute inset-x-0 bottom-0",
bg ? "opacity-40" : "opacity-38",
animate && "pour-drift-c"
)}
style={{ top: p.dripsFineTop, background: p.dripsFine }}
/>
{bg && (
<>
<div
className={cn(
"absolute inset-x-0 bottom-0 opacity-70 mix-blend-screen",
animate && "pour-drift-c"
)}
style={{
top: p.dripsFineTop,
background: p.dripsCrisp ?? crispDrips(90),
}}
/>
<div
className="absolute inset-0"
style={{
background:
"linear-gradient(180deg, transparent 52%, oklch(0.04 0.01 280 / 0.9) 100%)",
}}
/>
</>
)}
{grain && (
<>
<div
className="absolute inset-0 opacity-25 mix-blend-overlay"
style={{ backgroundImage: SANDPAPER_GRAIN, ...grainMask }}
/>
<div
className={cn(
"absolute inset-0 opacity-80 mix-blend-soft-light",
animate && "pour-grain-pulse"
)}
style={{ backgroundImage: SQUARE_GRAIN, ...grainMask }}
/>
</>
)}
{vignette && (
<div
className="absolute inset-0"
style={{
background:
"radial-gradient(120% 90% at 50% 42%, transparent 55%, oklch(0.02 0.01 280 / 0.5) 100%)",
}}
/>
)}
</div>
)
}
export { PourScene, generatePourPalette, PALETTES as POUR_PALETTES }
export type {
PourPalette,
Palette as PourPaletteShape,
OklchColor as PourOklch,
}
// 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),
}
}
Installation
npx shadcn@latest add @01orbital/copper-pour-01Make it yours
ANCHORSandLAYOUT_SEED, also at the top of the file, hold its lists and settings.- Its look comes from Painted Canvas and Pour Scene; each page lists the props that change it.
Built from
Built from these parts. The CLI adds each one that is missing and won't replace a file you already have unless you choose to:
Last updated on