Files
2026-10-06 13:26:44 -03:00

120 lines
4.0 KiB
HTML

<canvas id="matrix-bg" class="fixed inset-0 h-full w-full bg-[#11111b]" aria-hidden="true"></canvas>
<div id="matrix-spotlight" class="pointer-events-none fixed inset-0" aria-hidden="true"></div>
<div class="pointer-events-none fixed inset-0 bg-[radial-gradient(ellipse_at_center,transparent_0%,rgba(17,17,27,0.6)_100%)]" aria-hidden="true"></div>
<script>
(function () {
const canvas = document.getElementById("matrix-bg");
const spotlight = document.getElementById("matrix-spotlight");
if (!canvas) return;
const ctx = canvas.getContext("2d");
// Catppuccin Mocha
const C = {
base: "#11111b",
lavender: [180, 190, 254],
mauve: [203, 166, 247],
pink: [245, 194, 231],
rosewater: [245, 224, 220],
};
const GAP = 28; // separación de la grilla fija
const RADIUS = 240; // radio de iluminación del cursor
let cols = 0, rows = 0;
let mx = window.innerWidth / 2;
let my = window.innerHeight / 3;
let hasMouse = false;
function resize() {
const dpr = Math.min(window.devicePixelRatio || 1, 2);
canvas.width = Math.floor(window.innerWidth * dpr);
canvas.height = Math.floor(window.innerHeight * dpr);
canvas.style.width = window.innerWidth + "px";
canvas.style.height = window.innerHeight + "px";
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
cols = Math.ceil(window.innerWidth / GAP);
rows = Math.ceil(window.innerHeight / GAP);
}
function setSpotlight(x, y) {
spotlight.style.background =
"radial-gradient(circle " + RADIUS + "px at " + x + "px " + y + "px, " +
"rgba(203,166,247,0.13) 0%, rgba(180,190,254,0.05) 45%, transparent 70%)";
}
setSpotlight(mx, my);
window.addEventListener("resize", resize);
window.addEventListener("pointermove", (e) => {
mx = e.clientX;
my = e.clientY;
hasMouse = true;
setSpotlight(mx, my);
}, { passive: true });
document.addEventListener("pointerleave", () => { hasMouse = false; });
resize();
const reduceMotion = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
function mix(a, b, t) {
return [
Math.round(a[0] + (b[0] - a[0]) * t),
Math.round(a[1] + (b[1] - a[1]) * t),
Math.round(a[2] + (b[2] - a[2]) * t),
];
}
function frame(t) {
requestAnimationFrame(frame);
if (reduceMotion) t = 0; // fondo estático, solo responde al cursor
const W = window.innerWidth;
const H = window.innerHeight;
// fondo opaco: los puntos están fijos, no caen
ctx.shadowBlur = 0;
ctx.fillStyle = C.base;
ctx.fillRect(0, 0, W, H);
for (let j = 0; j < rows; j++) {
const y = j * GAP + GAP / 2;
for (let i = 0; i < cols; i++) {
const x = i * GAP + GAP / 2;
const dx = x - mx;
const dy = y - my;
const dist = hasMouse ? Math.sqrt(dx * dx + dy * dy) : 9999;
let f = Math.max(0, 1 - dist / RADIUS);
f = f * f * (3 - 2 * f); // smoothstep: encendido suave
// respiración sutil del fondo para que no se vea muerto
const tw = reduceMotion ? 0.5 : 0.5 + 0.5 * Math.sin(t * 0.001 + (x + y) * 0.02);
if (f > 0.01) {
// iluminado por el cursor: crece + cambia lavender -> mauve -> rosewater
const c = f > 0.65 ? mix(C.mauve, C.rosewater, (f - 0.65) / 0.35)
: f > 0.3 ? mix(C.lavender, C.mauve, (f - 0.3) / 0.35)
: mix([88, 91, 112], C.lavender, f / 0.3);
const r = 1.2 + f * 1.2;
ctx.shadowBlur = 16 * f;
ctx.shadowColor = "rgba(203,166,247,0.9)";
ctx.fillStyle = "rgba(" + c[0] + "," + c[1] + "," + c[2] + "," + (0.35 + f * 0.65).toFixed(2) + ")";
ctx.beginPath();
ctx.arc(x, y, r, 0, Math.PI * 2);
ctx.fill();
} else {
// fondo: punto fijo tenue con parpadeo leve
ctx.shadowBlur = 0;
ctx.fillStyle = "rgba(88,91,112," + (0.16 + tw * 0.14).toFixed(2) + ")";
ctx.beginPath();
ctx.arc(x, y, 1.2, 0, Math.PI * 2);
ctx.fill();
}
}
}
ctx.shadowBlur = 0;
}
requestAnimationFrame(frame);
})();
</script>