Constellation
Points wandering on slow loops, joined by a fine line whenever two come close.
Everything connects.
Wandering points that link up whenever two drift close.
Options
Code
import { useEffect, useRef } from "react";
import "./constellation.css";
function paint(ctx, w, h, t, colour) {
const rnd = (i) => { const x = Math.sin(i * 127.1 + 311.7) * 43758.5453; return x - Math.floor(x); };
const reach = 170;
const points = [];
for (let i = 0; i < 64; i++) {
points.push([
w * (0.5 + 0.48 * Math.sin(t * (0.05 + rnd(i) * 0.08) + rnd(i + 1) * 6.283)),
h * (0.5 + 0.46 * Math.cos(t * (0.04 + rnd(i + 2) * 0.08) + rnd(i + 3) * 6.283)),
]);
}
ctx.strokeStyle = colour;
ctx.fillStyle = colour;
ctx.lineWidth = 1;
for (let a = 0; a < points.length; a++) {
for (let b = a + 1; b < points.length; b++) {
const distance = Math.hypot(points[a][0] - points[b][0], points[a][1] - points[b][1]);
if (distance > reach) continue;
ctx.globalAlpha = (1 - distance / reach) * 0.45;
ctx.beginPath();
ctx.moveTo(points[a][0], points[a][1]);
ctx.lineTo(points[b][0], points[b][1]);
ctx.stroke();
}
}
ctx.globalAlpha = 0.7;
for (const [x, y] of points) {
ctx.beginPath();
ctx.arc(x, y, 1.8, 0, Math.PI * 2);
ctx.fill();
}
}
export function Constellation({ children }) {
const ref = useRef(null);
useEffect(() => {
const canvas = ref.current;
const ctx = canvas.getContext("2d");
const still = matchMedia("(prefers-reduced-motion: reduce)").matches;
let w = 0;
let h = 0;
let frame = 0;
let seen = true;
const draw = (now) => {
frame = 0;
ctx.clearRect(0, 0, w, h);
ctx.globalAlpha = 1;
paint(ctx, w, h, now / 1000, getComputedStyle(canvas).color);
if (seen && !still) frame = requestAnimationFrame(draw);
};
const start = () => {
if (!frame) frame = requestAnimationFrame(draw);
};
const sized = new ResizeObserver(() => {
const ratio = Math.min(window.devicePixelRatio || 1, 2);
w = canvas.clientWidth;
h = canvas.clientHeight;
canvas.width = w * ratio;
canvas.height = h * ratio;
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
start();
});
const watched = new IntersectionObserver(([entry]) => {
seen = entry.isIntersecting;
if (seen) start();
});
sized.observe(canvas);
watched.observe(canvas);
return () => {
cancelAnimationFrame(frame);
sized.disconnect();
watched.disconnect();
};
}, []);
return (
<section className="dh-links">
<canvas ref={ref} className="dh-links-art" aria-hidden="true" />
<div className="dh-links-content">{children}</div>
</section>
);
}.dh-links {
position: relative;
display: grid;
place-items: center;
overflow: hidden;
min-height: 720px;
background: var(--dh-bg, #fff);
color: var(--dh-fg, #171717);
font-size: 14px;
line-height: 1.5;
}
.dh-links-art {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
/* The drawing takes this colour. */
color: var(--dh-accent, #2563ff);
pointer-events: none;
-webkit-mask-image: radial-gradient(ellipse 80% 90% at 50% 50%, #000 45%, transparent 100%);
mask-image: radial-gradient(ellipse 80% 90% at 50% 50%, #000 45%, transparent 100%);
}
.dh-links-content {
position: relative;
isolation: isolate;
padding: 32px;
text-align: center;
}
/* A soft clearing behind the words, so they stay easy to read. */
.dh-links-content::before {
content: "";
position: absolute;
inset: -24px -96px;
z-index: -1;
background: radial-gradient(closest-side, var(--dh-bg, #fff) 45%, transparent);
}
.dh-links h1 {
margin: 0;
font-size: 44px;
font-weight: 500;
line-height: 1.08;
letter-spacing: -0.04em;
}
.dh-links p {
max-width: 360px;
margin: 14px auto 0;
color: var(--dh-muted, #6b6b6b);
font-size: 15px;
}
@media (max-width: 640px) {
.dh-links h1 { font-size: 32px; }
}<section class="dh-links">
<canvas class="dh-links-art" aria-hidden="true"></canvas>
<div class="dh-links-content">
<h1>Everything connects.</h1>
<p>Wandering points that link up whenever two drift close.</p>
</div>
</section>.dh-links {
position: relative;
display: grid;
place-items: center;
overflow: hidden;
min-height: 720px;
background: var(--dh-bg, #fff);
color: var(--dh-fg, #171717);
font-size: 14px;
line-height: 1.5;
}
.dh-links-art {
position: absolute;
inset: 0;
width: 100%;
height: 100%;
/* The drawing takes this colour. */
color: var(--dh-accent, #2563ff);
pointer-events: none;
-webkit-mask-image: radial-gradient(ellipse 80% 90% at 50% 50%, #000 45%, transparent 100%);
mask-image: radial-gradient(ellipse 80% 90% at 50% 50%, #000 45%, transparent 100%);
}
.dh-links-content {
position: relative;
isolation: isolate;
padding: 32px;
text-align: center;
}
/* A soft clearing behind the words, so they stay easy to read. */
.dh-links-content::before {
content: "";
position: absolute;
inset: -24px -96px;
z-index: -1;
background: radial-gradient(closest-side, var(--dh-bg, #fff) 45%, transparent);
}
.dh-links h1 {
margin: 0;
font-size: 44px;
font-weight: 500;
line-height: 1.08;
letter-spacing: -0.04em;
}
.dh-links p {
max-width: 360px;
margin: 14px auto 0;
color: var(--dh-muted, #6b6b6b);
font-size: 15px;
}
@media (max-width: 640px) {
.dh-links h1 { font-size: 32px; }
}{
const paint = (ctx, w, h, t, colour) => {
const rnd = (i) => { const x = Math.sin(i * 127.1 + 311.7) * 43758.5453; return x - Math.floor(x); };
const reach = 170;
const points = [];
for (let i = 0; i < 64; i++) {
points.push([
w * (0.5 + 0.48 * Math.sin(t * (0.05 + rnd(i) * 0.08) + rnd(i + 1) * 6.283)),
h * (0.5 + 0.46 * Math.cos(t * (0.04 + rnd(i + 2) * 0.08) + rnd(i + 3) * 6.283)),
]);
}
ctx.strokeStyle = colour;
ctx.fillStyle = colour;
ctx.lineWidth = 1;
for (let a = 0; a < points.length; a++) {
for (let b = a + 1; b < points.length; b++) {
const distance = Math.hypot(points[a][0] - points[b][0], points[a][1] - points[b][1]);
if (distance > reach) continue;
ctx.globalAlpha = (1 - distance / reach) * 0.45;
ctx.beginPath();
ctx.moveTo(points[a][0], points[a][1]);
ctx.lineTo(points[b][0], points[b][1]);
ctx.stroke();
}
}
ctx.globalAlpha = 0.7;
for (const [x, y] of points) {
ctx.beginPath();
ctx.arc(x, y, 1.8, 0, Math.PI * 2);
ctx.fill();
}
};
document.querySelectorAll(".dh-links-art").forEach((canvas) => {
if (canvas.dataset.ready) return;
canvas.dataset.ready = "true";
const ctx = canvas.getContext("2d");
const still = matchMedia("(prefers-reduced-motion: reduce)").matches;
let w = 0;
let h = 0;
let frame = 0;
let seen = true;
const draw = (now) => {
frame = 0;
ctx.clearRect(0, 0, w, h);
ctx.globalAlpha = 1;
paint(ctx, w, h, now / 1000, getComputedStyle(canvas).color);
if (seen && !still) frame = requestAnimationFrame(draw);
};
const start = () => {
if (!frame) frame = requestAnimationFrame(draw);
};
new ResizeObserver(() => {
const ratio = Math.min(window.devicePixelRatio || 1, 2);
w = canvas.clientWidth;
h = canvas.clientHeight;
canvas.width = w * ratio;
canvas.height = h * ratio;
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
start();
}).observe(canvas);
new IntersectionObserver(([entry]) => {
seen = entry.isIntersecting;
if (seen) start();
}).observe(canvas);
});
}Constellation is not in the Figma file yet.
Use the React or HTML code for now.