Commit 77b0fc29 by PLN (Algolia)

404: shuffle-bag rotation (no rerun until all seen), one visit in five gets the…

404: shuffle-bag rotation (no rerun until all seen), one visit in five gets the DustyHalley treatment on a random star photo, fantome opts out via void flag
parent 0555a87e
...@@ -9,12 +9,11 @@ export const metadata = { ...@@ -9,12 +9,11 @@ export const metadata = {
robots: { index: false, follow: false }, robots: { index: false, follow: false },
}; };
/** The void is a gallery: every StarryNights sketch in content/hydras is /** The void is a gallery: every sketch in content/hydras is resolved at
* resolved at build (same pipeline as /hydra/[id]) and embedded, so each * build (same pipeline as /hydra/[id]) and embedded, so each visit boots
* visit boots one of the real pieces — and a sketch that won't boot yields * one of the real pieces — and a sketch that won't boot yields to another,
* to another, never to a stock photo. Non-StarryNights works (fantome, * never to a stock photo. A sketch opts out of the void with `void: false`
* glitchpool…) stay in the /hydra gallery; the void only rotates the * in its frontmatter (fantôme only, for now); everything else rotates.
* étoilées.
* Asset refs are rewritten to the static copies in /images/hydra (see * Asset refs are rewritten to the static copies in /images/hydra (see
* scripts/hydra-assets.mjs): the git-raw originals are cross-origin and * scripts/hydra-assets.mjs): the git-raw originals are cross-origin and
* case-fragile, and backgrounds vanished for some visitors. */ * case-fragile, and backgrounds vanished for some visitors. */
...@@ -31,7 +30,7 @@ async function loadSketches() { ...@@ -31,7 +30,7 @@ async function loadSketches() {
for (const f of fs.readdirSync(dir).filter((name) => name.endsWith('.md'))) { for (const f of fs.readdirSync(dir).filter((name) => name.endsWith('.md'))) {
const { data } = matter(fs.readFileSync(path.join(dir, f), 'utf8')); const { data } = matter(fs.readFileSync(path.join(dir, f), 'utf8'));
if (!data.source) continue; if (!data.source) continue;
if (!data.source.includes('/StarryNights/')) continue; // the void rotates the étoilées only if (data.void === false) continue; // frontmatter opt-out (see fantôme)
const sketch = await resolveHydraSketch(data.source); const sketch = await resolveHydraSketch(data.source);
if (sketch) { if (sketch) {
out.push({ out.push({
......
...@@ -21,11 +21,69 @@ function sanitize(source) { ...@@ -21,11 +21,69 @@ function sanitize(source) {
const STAGE_W = 1280; const STAGE_W = 1280;
const STAGE_H = 720; const STAGE_H = 720;
const SEEN_KEY = 'espace-404-seen';
const GENERATIVE_RATE = 0.2;
/** DustyHalley's treatment, let loose on a random NASA star photo — the
* one generative visit in five, so the void sometimes dreams instead of
* showing a framed work. */
function generativePiece() {
const star = `/images/404/star-${String(1 + Math.floor(Math.random() * 31)).padStart(2, '0')}.jpg`;
return {
id: null,
title: 'poussière d’étoiles',
source: `// traitement DustyHalley sur une photo d'étoile au hasard
s0.initImage("${star}")
src(s0).out(o0)
src(o0)
.modulate(src(o0),() => Math.sin(time/100) / 10)
.out(o1)
src(o1)
.modulateScale(osc(1,0.4),0.05)
.blend(noise(100,0.92).colorama(),0.07)
.out(o2)
src(o2)
.blend(src(o2).thresh(), () => 0.5 + 0.125 * Math.sin(time / 100 % 180))
.scrollX(-0.05)
.scale(1.08)
.out(o3)
render(o3)`,
};
}
/** Shuffle-bag over localStorage: rotate through everything before any
* rerun. Returns up to n unseen sketches (fresh bag once all are seen). */
function bag(sketches, n) {
let seen;
try {
seen = JSON.parse(localStorage.getItem(SEEN_KEY) || '[]');
} catch {
seen = [];
}
const valid = new Set(sketches.map((s) => s.id));
seen = seen.filter((id) => valid.has(id));
let pool = sketches.filter((s) => !seen.includes(s.id));
if (pool.length === 0) {
pool = [...sketches];
seen = [];
}
for (let i = pool.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[pool[i], pool[j]] = [pool[j], pool[i]];
}
const picked = pool.slice(0, n);
picked.forEach((p) => seen.push(p.id));
try {
localStorage.setItem(SEEN_KEY, JSON.stringify(seen));
} catch {
/* private mode: rotation just forgets, the room still plays */
}
return picked;
}
export default function NotFoundHydra({ sketches }) { export default function NotFoundHydra({ sketches }) {
const canvasRef = useRef(null); const canvasRef = useRef(null);
const wrapRef = useRef(null); const wrapRef = useRef(null);
const bootedRef = useRef([]);
const [codeOpen, setCodeOpen] = useState(false); const [codeOpen, setCodeOpen] = useState(false);
const [current, setCurrent] = useState(null); const [current, setCurrent] = useState(null);
...@@ -63,11 +121,13 @@ export default function NotFoundHydra({ sketches }) { ...@@ -63,11 +121,13 @@ export default function NotFoundHydra({ sketches }) {
import('hydra-synth') import('hydra-synth')
.then((Hydra) => { .then((Hydra) => {
HydraModule = Hydra; HydraModule = Hydra;
// a failing sketch yields to another one — no stock photo, ever // one visit in five dreams (generative); the rest rotate the works
for (let attempt = 0; attempt < 3 && !instance; attempt++) { // via the shuffle-bag — a failing boot falls to the next candidate
const remaining = sketches.filter((s) => !bootedRef.current.includes(s)); const candidates = Math.random() < GENERATIVE_RATE
const pool = remaining.length > 0 ? remaining : sketches; ? [generativePiece()]
boot(pool[Math.floor(Math.random() * pool.length)]); : bag(sketches, 3);
for (const piece of candidates) {
if (boot(piece)) break;
} }
}) })
.catch((ex) => { .catch((ex) => {
...@@ -142,10 +202,12 @@ export default function NotFoundHydra({ sketches }) { ...@@ -142,10 +202,12 @@ export default function NotFoundHydra({ sketches }) {
<a href="/" onClick={(e) => e.stopPropagation()} style={barLink}> <a href="/" onClick={(e) => e.stopPropagation()} style={barLink}>
← accueil ← accueil
</a> </a>
{current && ( {current?.id ? (
<a href={`/hydra/${current.id}`} onClick={openWork} style={barLink}> <a href={`/hydra/${current.id}`} onClick={openWork} style={barLink}>
{current.title} · h = code {current.title} · h = code
</a> </a>
) : (
current && <span style={barLink}>{current.title} · h = code</span>
)} )}
</div> </div>
{codeOpen && current && ( {codeOpen && current && (
......
--- ---
void: false
title: Le fantôme title: Le fantôme
source: https://git.plnech.fr/pln/Hydra/raw/1604fce7f6f19d76d997abe4a360fb38569a4062/LeFantome.js source: https://git.plnech.fr/pln/Hydra/raw/1604fce7f6f19d76d997abe4a360fb38569a4062/LeFantome.js
link: https://nech.pl/fantome link: https://nech.pl/fantome
......
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