Radial wave
effect · background · delight · T0 · v1.0.0 · readyAbout
A background of wedge-shaped rays bent along a sine wave, radiating from the centre of its box and turning slowly, so the waves seem to flow. On mount the pattern grows out of the centre. Anything passed as children sits still in the middle. The shapes are computed while rendering: no script runs in the browser.
Layers
- Native
- No gated feature: supported everywhere.
- Static
- The full pattern, still.
Skin
| Variable | Default | Meaning |
|---|---|---|
--radial-wave-color | #7c6cf0 | Colour of the rays. |
--radial-wave-background | #141414 | Colour between the rays. |
--radial-wave-duration | 60s | Time for one full turn of the pattern. |
--radial-wave-intro-duration | 1.2s | How long the pattern takes to grow out of the centre on mount. |
Accessibility
Static layer: the full pattern, still, without the intro.
Decorative: the pattern is aria-hidden. High-contrast rays turning across the whole box can be uncomfortable; keep the turn slow and the contrast moderate, and never put text over it without a solid backing.
Sources
- reel · thedesignshop.tds · "Easter Eggs" reel; technique only (P6).
Code
Self-contained: copy every file, keeping the folder structure.
mechanism.module.css/* web-effects radial-wave 1.0.0 · MIT-0 */
/* Mechanism of the radial wave (D2.8, D3.11), shared by both styling variants.
.field fills .root and is a size container; the SVG pattern inside is a square of side
142cqmax, centred: at least the box's diagonal, so turning it never uncovers a corner. The
whole SVG element turns (a compositor transform), never its paths. .field also carries the
intro, a scale-up from the centre, on its own element so the two transforms compose.
L1: CSS animations, run by every supported browser, so the native layer has no feature gate
and there is no L2. L3 (base rules): the full pattern, still. */
.root {
--_radial-wave-color: var(--radial-wave-color, #7c6cf0);
--_radial-wave-background: var(--radial-wave-background, #141414);
--_radial-wave-duration: var(--radial-wave-duration, 60s);
--_radial-wave-intro-duration: var(--radial-wave-intro-duration, 1.2s);
position: relative;
display: grid;
place-items: center;
overflow: hidden;
background: var(--_radial-wave-background);
}
.field {
position: absolute;
inset: 0;
container-type: size;
}
/* Centred by position and margins, not grid alignment: an item larger than its grid area grows
the track instead of centring. Layout only, so it stays independent of the rotation. */
.pattern {
position: absolute;
top: 50%;
left: 50%;
width: 142cqmax;
height: 142cqmax;
margin: -71cqmax 0 0 -71cqmax;
fill: var(--_radial-wave-color);
}
/* Above the pattern, still. */
.center {
position: relative;
}
@keyframes turn {
to {
transform: rotate(1turn);
}
}
@keyframes grow {
from {
transform: scale(0.2);
opacity: 0;
}
}
/* L1 native (gated on the override attribute, D3.6a). */
:root:not([data-fx-layer]) .pattern,
:root[data-fx-layer="native"] .pattern {
animation: turn var(--_radial-wave-duration) linear infinite;
}
:root:not([data-fx-layer]) .root[data-intro] .field,
:root[data-fx-layer="native"] .root[data-intro] .field {
animation: grow var(--_radial-wave-intro-duration)
cubic-bezier(0.22, 1, 0.36, 1) both;
}
/* L3 under reduced motion (unless forced). */
@media (prefers-reduced-motion: reduce) {
:root:not([data-fx-layer]) .pattern,
:root:not([data-fx-layer]) .root[data-intro] .field {
animation: none;
}
}
pattern.tsx// web-effects radial-wave 1.0.0 · MIT-0
import { useId } from "react";
import mechanism from "./mechanism.module.css";
import { rayAngles, rayPath, type WaveShape } from "./rays";
// The pattern, shared by both styling variants (P8): one ray as a path (rays.ts), repeated
// around the centre with <use>, computed while rendering, so no script runs in the browser.
export function Pattern(shape: WaveShape) {
// useId's delimiters are not safe in a URL fragment; the remaining characters stay unique.
const id = `radial-wave-${useId().replace(/[^\w-]/g, "")}`;
return (
<div className={mechanism.field}>
<svg
className={mechanism.pattern}
viewBox="-100 -100 200 200"
aria-hidden="true"
focusable="false"
>
<defs>
<path id={id} d={rayPath(shape)} />
</defs>
{rayAngles(shape.rays).map((angle) => (
<use key={angle} href={`#${id}`} transform={`rotate(${angle})`} />
))}
</svg>
</div>
);
}
rays.ts// web-effects radial-wave 1.0.0 · MIT-0
// Geometry of the radial wave (pure, unit-tested), in a viewBox from -100 to 100. All rays are
// one shape turned around the centre, so only one is computed: a wedge along the x axis, bent
// sideways along a sine wave. Its centre line sits at angle
// θ(r) = amplitude · sin(2π · waves · r / 100); its edges a fixed angle either side of it, so the
// ray widens outwards. Edges are smoothed with quadratic curves; coordinates are rounded.
export type WaveShape = {
/** Number of rays around the circle. */
rays: number;
/** Full waves along a ray, centre to edge. */
waves: number;
/** Largest sideways bend, in radians. */
amplitude: number;
/** Share of each ray's sector it fills (0–1); the rest is gap. */
fill: number;
};
/** Rays start a little off the centre, where they would merge into a blot. */
const inner = 6;
/** The pattern reaches the circle the rotating square is cut from. */
const outer = 100;
/** Points per ray edge: smooth at full-screen size. */
const samples = 48;
/** A tenth of a viewBox unit: under a pixel even when the pattern fills a large screen. */
const round = (n: number) => Math.round(n * 10) / 10;
type Point = [number, number];
const polar = (r: number, angle: number): Point => [
r * Math.cos(angle),
r * Math.sin(angle),
];
const format = ([x, y]: Point) => `${round(x)} ${round(y)}`;
const mid = (a: Point, b: Point): Point => [
(a[0] + b[0]) / 2,
(a[1] + b[1]) / 2,
];
/**
* A smooth curve along the samples: straight to the first midpoint, then quadratic segments with
* each inner sample as control point and the next midpoint as anchor (continuous tangents), then
* straight to the last sample. Symmetric: reversing the samples traces the same curve.
* `start` is "M" for the first edge, "L" to continue the outline.
*/
function smooth(points: Point[], start: "M" | "L"): string {
const last = points.length - 1;
let d = `${start}${format(points[0])}L${format(mid(points[0], points[1]))}`;
for (let i = 1; i < last; i++)
d += `Q${format(points[i])} ${format(mid(points[i], points[i + 1]))}`;
return `${d}L${format(points[last])}`;
}
/** SVG path data of the ray along the x axis (angle 0), as a closed shape. */
export function rayPath({ rays, waves, amplitude, fill }: WaveShape): string {
const half = (Math.PI / rays) * fill;
const radii = Array.from(
{ length: samples + 1 },
(_, i) => inner + ((outer - inner) * i) / samples,
);
const centre = radii.map(
(r) => amplitude * Math.sin((2 * Math.PI * waves * r) / outer),
);
const left = radii.map((r, i) => polar(r, centre[i] - half));
const right = radii.map((r, i) => polar(r, centre[i] + half)).reverse();
return `${smooth(left, "M")}${smooth(right, "L")}Z`;
}
/** Rotation of each ray, in degrees. */
export function rayAngles(rays: number): number[] {
return Array.from({ length: rays }, (_, i) => round((360 * i) / rays));
}
tailwind/RadialWave.tsx// web-effects radial-wave 1.0.0 · MIT-0
import type { ReactNode } from "react";
import mechanism from "../mechanism.module.css";
import { Pattern } from "../pattern";
/**
* Wavy rays radiating from the centre of the box, turning slowly; `children` sit still in the
* middle. The box takes its size from the host (give it a height). `rays`: count; `waves`: full
* waves centre to edge; `amplitude`: sideways bend in radians; `fill`: share of each sector the
* ray covers; `intro`: grow out of the centre on mount.
*/
export function RadialWave({
children,
rays = 48,
waves = 4,
amplitude = 0.12,
fill = 0.5,
intro = true,
className = "",
}: {
children?: ReactNode;
rays?: number;
waves?: number;
amplitude?: number;
fill?: number;
intro?: boolean;
className?: string;
}) {
return (
<div
data-intro={intro || undefined}
className={`${mechanism.root} ${className}`}
>
<Pattern rays={rays} waves={waves} amplitude={amplitude} fill={fill} />
{children !== undefined && (
<div className={mechanism.center}>{children}</div>
)}
</div>
);
}