Commit e41b29f8 by PLN (Algolia)

404: the void is a gallery — boots a random StarryNights piece per visit

All 23 content/hydras sketches resolve at build (same pipeline as
/hydra/[id]) and embed into the 404 island: each visit boots one of the
real pieces, credited in the corner. The NASA star photo stays as the
no-WebGL fallback; cinema mode and click-anywhere-home unchanged.
parent 23ceb1eb
import fs from 'fs';
import path from 'path';
import matter from 'gray-matter';
import Link from 'next/link'; import Link from 'next/link';
import NotFoundHydra from '@/components/not-found-hydra'; import NotFoundHydra from '@/components/not-found-hydra';
import { resolveHydraSketch } from '@/lib/hydra-sketch';
export const metadata = { export const metadata = {
title: '404 | Vous êtes dans l’espace entre les pages', title: '404 | Vous êtes dans l’espace entre les pages',
robots: { index: false, follow: false }, robots: { index: false, follow: false },
}; };
/** The void: a composed hydra scene (different every visit, mouse-reactive) /** The void is a gallery: every StarryNights sketch in content/hydras is
* behind one line. Click anywhere — the whole page is the door home. */ * resolved at build (same pipeline as /hydra/[id]) and embedded, so each
export default function NotFound() { * visit boots one of the real pieces — never the same twice in a row. */
async function loadSketches() {
const dir = path.join(process.cwd(), 'content', 'hydras');
const out = [];
for (const f of fs.readdirSync(dir).filter((name) => name.endsWith('.md'))) {
const { data } = matter(fs.readFileSync(path.join(dir, f), 'utf8'));
if (!data.source) continue;
const sketch = await resolveHydraSketch(data.source);
if (sketch) {
out.push({
title: sketch.credits?.title || data.title || f.replace(/\.md$/, ''),
source: sketch.source,
});
}
}
return out;
}
export default async function NotFound() {
const sketches = await loadSketches();
return ( return (
<Link <Link
href="/" href="/"
aria-label="Retour à l’accueil" aria-label="Retour à l’accueil"
className="block relative min-h-[100dvh] cursor-pointer" className="block relative min-h-[100dvh] cursor-pointer"
> >
<NotFoundHydra /> <NotFoundHydra sketches={sketches} />
<div
aria-hidden="true"
className="bg-[var(--surface)] opacity-50"
style={{ position: 'fixed', inset: 0, zIndex: 0 }}
/>
<main <main
className="relative min-h-[100dvh] flex flex-col items-center justify-center px-6 text-center" className="relative min-h-[100dvh] flex flex-col items-center justify-center px-6 text-center"
style={{ zIndex: 1 }} style={{ zIndex: 1 }}
> >
<h1 className="text-7xl font-bold tracking-tight text-[var(--text-primary)]"> <h1 className="text-7xl font-bold tracking-tight text-[var(--text-primary)] [text-shadow:0_0_24px_var(--surface)]">
404 404
</h1> </h1>
<p className="mt-6 text-lg text-[var(--text-primary)] text-balance"> <p className="mt-6 text-lg text-[var(--text-primary)] text-balance [text-shadow:0_1px_12px_var(--surface)]">
Vous êtes dans l’espace entre les pages. Vous êtes dans l’espace entre les pages.
</p> </p>
</main> </main>
......
...@@ -2,91 +2,24 @@ ...@@ -2,91 +2,24 @@
import React, { useEffect, useRef } from 'react'; import React, { useEffect, useRef } from 'react';
/** The 404 backdrop: one random NASA star picture (public domain, 31 in /** The 404 canvas: boots one real StarryNights sketch per visit (embedded
* /images/404/, attribution in manifest.json) glitched through hydra. * at build by app/not-found.js). Cinema: the theme switcher sits out, and
* Sources have no .layer() — only outputs do — so compositing here is * if hydra or WebGL can't run, the piece degrades to a random NASA star
* .blend/.mask chains into the single default output (render() would tile * photo — the room is never black. */
* a 2x2 grid). Colors: HSL harmony around a seeded base hue; every scene
* reads the mouse; blend amounts drift with time. */
function mulberry32(seed) { function sanitize(source) {
let a = seed >>> 0; return source
return () => { .replace(/<[^>]*>/g, '')
a |= 0; .replace(/```javascript|```/g, '')
a = (a + 0x6d2b79f5) | 0; .trim();
let t = Math.imul(a ^ (a >>> 15), 1 | a);
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
} }
/** h in [0,1) → [r,g,b] triple hydra's color() can eat. */ export default function NotFoundHydra({ sketches }) {
function hslToRgb(h, s = 0.7, l = 0.5) {
const f = (n) => {
const k = (n + h * 12) % 12;
const a = s * Math.min(l, 1 - l);
return +(l - a * Math.max(-1, Math.min(k - 3, 9 - k, 1))).toFixed(3);
};
return [f(0), f(8), f(4)];
}
const rgb = (c) => c.map((v) => v.toFixed(3)).join(', ');
function composeSource(seed, star) {
const rnd = mulberry32(seed);
const base = rnd();
const [C0, C1, C2] = [base, (base + 0.5) % 1, (base + 0.083) % 1].map((h) => hslToRgb(h));
const f1 = 30 + rnd() * 90;
const f2 = 4 + rnd() * 22;
const s1 = 0.015 + rnd() * 0.04;
const s2 = 0.04 + rnd() * 0.1;
const k = 2 + Math.floor(rnd() * 5);
const c0 = rgb(C0);
const c1 = rgb(C1);
const c2 = rgb(C2);
// star comes in as a parameter — the fallback background must show the
// same photo the sketch uses
const scenes = [
// the sky breathed: scaled by the cursor, a traveling generative veil
`s0.initImage('${star}')
s0.scale(1.1, () => 1.05 + mouse.y * 0.2).rotate(() => time * 0.01 + mouse.x * 0.5)
.modulate(osc(${f2}, ${s2}), () => 0.1 + mouse.x * 0.25)
.blend(osc(${f1}, ${s1}).color(${c1})
.mask(shape(${k}, 0.35).rotate(() => time * 0.08)), 0.8)
.out()`,
// double exposure: the sky diffed against its kaleid ghost
`s0.initImage('${star}')
s0.kaleid(${k}).color(${c0})
.diff(s0.rotate(() => time * 0.02 + mouse.x).hue(() => ${base} + 0.15))
.modulate(voronoi(${f2}, ${s2}), () => 0.08 + mouse.y * 0.2)
.out()`,
// eclipse: a generative disc eating the stars, blend drifting over minutes
`s0.initImage('${star}')
s0.hue(() => ${base} + mouse.x * 0.25)
.mult(shape(2, 0.9, () => 0.4 + mouse.y * 0.3).scale(2).repeat(${k}, ${k}).rotate(() => time * 0.05))
.blend(osc(${f2}, ${s2} * 2).color(${c2})
.mask(shape(${k + 1}, 0.4).scale(() => 0.6 + 0.3 * Math.sin(time * 0.05 + mouse.x))), 0.7)
.blend(osc(${f1}, ${s1}).color(${c1}), () => 0.15 + 0.15 * Math.sin(time * 0.04))
.out()`,
// purely generative fallback — the field without the sky
`voronoi(${f2}, ${s2}, ${rnd()}).colorama(0.004).color(${c0})
.hue(() => ${base} + mouse.x * 0.3)
.blend(osc(${f1}, ${s1}).color(${c1})
.diff(shape(${k}, 0.3).repeat(${k}, ${k}).rotate(() => -time * 0.04 + mouse.y)), 0.8)
.out()`,
];
const speed = 0.35 + rnd() * 0.4;
return `speed = ${speed.toFixed(2)}
${scenes[Math.floor(rnd() * scenes.length)]}`;
}
export default function NotFoundHydra() {
const canvasRef = useRef(null); const canvasRef = useRef(null);
const wrapRef = useRef(null); const wrapRef = useRef(null);
useEffect(() => { useEffect(() => {
if (!canvasRef.current) return; if (!canvasRef.current || !sketches?.length) return;
// cinema: the theme switcher sits this one out // cinema: the theme switcher sits this one out
const pill = document.querySelector('[class*="ThemeSwitcher"], [class*="themeSwitcher"]'); const pill = document.querySelector('[class*="ThemeSwitcher"], [class*="themeSwitcher"]');
const prev = pill?.style.display; const prev = pill?.style.display;
...@@ -105,7 +38,16 @@ export default function NotFoundHydra() { ...@@ -105,7 +38,16 @@ export default function NotFoundHydra() {
width: canvas.width, width: canvas.width,
height: canvas.height, height: canvas.height,
}); });
instance.eval(composeSource(Date.now(), star)); const piece = sketches[Math.floor(Math.random() * sketches.length)];
instance.eval(sanitize(piece.source));
if (piece.title) {
const credit = document.createElement('div');
credit.textContent = `hydra · ${piece.title}`;
credit.setAttribute('aria-hidden', 'true');
credit.style.cssText =
'position:fixed;right:1rem;bottom:0.9rem;z-index:1;font-size:0.75rem;opacity:0.55;color:var(--text-muted)';
wrapRef.current?.appendChild(credit);
}
}) })
.catch((ex) => { .catch((ex) => {
// no WebGL / no hydra? the raw photo still falls — cinema never black // no WebGL / no hydra? the raw photo still falls — cinema never black
...@@ -118,7 +60,7 @@ export default function NotFoundHydra() { ...@@ -118,7 +60,7 @@ export default function NotFoundHydra() {
if (instance && typeof instance.close === 'function') instance.close(); if (instance && typeof instance.close === 'function') instance.close();
if (pill && prev !== undefined) pill.style.display = prev; if (pill && prev !== undefined) pill.style.display = prev;
}; };
}, []); }, [sketches]);
return ( return (
<div ref={wrapRef} style={{ position: 'fixed', inset: 0, zIndex: 0 }}> <div ref={wrapRef} style={{ position: 'fixed', inset: 0, zIndex: 0 }}>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment