Live preview · fully interactive
The prompt
Build a constellation background. ## Look 40 points, 1.6px, fill #f2f2f7. Links are rgba(196,181,253) and fade out by 120px. Page #08080d. ## Behavior Each point drifts at most 0.4px per frame and bounces off the edges. Draw a line when two points are closer than 120px. ## Design tokens - Points #f2f2f7; links #c4b5fd; page #08080d. ## Motion - Continuous frame loop. Link alpha is (1 - distance/120) * 0.7. ## Constraints - Single self-contained HTML file. No libraries. Canvas 2D. - Honor prefers-reduced-motion: reduce by skipping the loop and leaving a readable static frame - Readable at 390px width with no horizontal page scroll
The code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { min-height: 100%; }
body {
background: #08080d; color: #f2f2f7; font-family: Inter, system-ui, sans-serif;
min-height: 100vh; overflow: hidden;
}
.hint { position: absolute; left: 16px; top: 16px; z-index: 5; font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: #8a8a99; }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; }
@media (max-width: 420px) {
.hint { font-size: 10px; letter-spacing: 0.08em; }
}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
</style>
</head>
<body>
<canvas id="c"></canvas>
<script>
var reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
var canvas = document.getElementById("c");
var ctx = canvas.getContext("2d");
var pts = [];
function resize() {
canvas.width = window.innerWidth; canvas.height = window.innerHeight;
}
resize();
window.addEventListener("resize", resize);
for (var i = 0; i < 40; i++) {
pts.push({ x: Math.random() * window.innerWidth, y: Math.random() * window.innerHeight, vx: (Math.random() - 0.5) * 0.4, vy: (Math.random() - 0.5) * 0.4 });
}
function frame() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
pts.forEach(function (p) {
if (!reduce) { p.x += p.vx; p.y += p.vy; }
if (p.x < 0 || p.x > canvas.width) p.vx *= -1;
if (p.y < 0 || p.y > canvas.height) p.vy *= -1;
});
for (var a = 0; a < pts.length; a++) {
for (var b = a + 1; b < pts.length; b++) {
var dx = pts[a].x - pts[b].x, dy = pts[a].y - pts[b].y;
var dist = Math.hypot(dx, dy);
if (dist < 120) {
ctx.strokeStyle = "rgba(196,181,253," + (1 - dist / 120) * 0.7 + ")";
ctx.beginPath(); ctx.moveTo(pts[a].x, pts[a].y); ctx.lineTo(pts[b].x, pts[b].y); ctx.stroke();
}
}
ctx.fillStyle = "#f2f2f7";
ctx.beginPath(); ctx.arc(pts[a].x, pts[a].y, 1.6, 0, Math.PI * 2); ctx.fill();
}
if (!reduce) requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
</script>
</body>
</html>About this effect
Forty points drift slowly. Segments draw when two points are within 120px, brighter when closer. A quiet background for AI and data pages.