Something went wrong. Try again.
doll.systems community website
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758import sharp from 'sharp';import { mkdir, writeFile } from 'node:fs/promises';import { dirname } from 'node:path';
// Native bitmap glyphs in 9×14 cells, matching the display's ASCII grid.const glyphs = [ ['01010', '11111', '01010', '01010', '11111', '01010', '01010'], // # ['00000', '10101', '01110', '11111', '01110', '10101', '00000'], // * ['00000', '00100', '00100', '11111', '00100', '00100', '00000'], // + ['00000', '00100', '00000', '00000', '00100', '00000', '00000'], // : ['00000', '00000', '00000', '00000', '00000', '00100', '00000'], // .];export async function generateDissolve() { const width = 144, height = 112; const masks = []; for (const progress of [0.18, 0.38, 0.58, 0.78]) { const pixels = Buffer.alloc(width * height * 4); for (let row = 0; row < 8; row++) for (let column = 0; column < 16; column++) { const seed = Math.sin(column * 127.1 + row * 311.7) * 43758.5453; const phase = (progress - (seed - Math.floor(seed)) * 0.38) / 0.62; const glyph = glyphs[Math.min(4, Math.max(0, Math.floor(phase * 5)))]; for (let y = 0; y < 14; y++) for (let x = 0; x < 9; x++) { if (phase < 0 || (phase < 1 && glyph[y - 3]?.[x - 2] === '1')) { pixels.set([255, 255, 255, 255], ((row * 14 + y) * width + column * 9 + x) * 4); } } } const png = await sharp(pixels, { raw: { width, height, channels: 4 } }) .png({ palette: true }) .toBuffer(); masks.push(`url('data:image/png;base64,${png.toString('base64')}')`); } const solid = 'linear-gradient(#fff, #fff)'; const frames = [solid, ...masks.map((_, index) => `var(--ascii-mask-${index})`)]; const outgoing = frames .map((mask, i) => `${i * 20}% { mask-image: ${mask}; opacity: ${1 - i * 0.15}; }`) .join('\n'); const incoming = [...frames] .reverse() .map((mask, i) => `${i * 25}% { mask-image: ${mask}; opacity: ${0.15 + (i * 0.85) / 4}; }`) .join('\n'); const output = '.astro/generated/styles/_ascii-dissolve.scss'; await mkdir(dirname(output), { recursive: true }); await writeFile( output, `/* Generated by scripts/generate-dissolve.mjs; no runtime image/filter work. */:root {${masks.map((mask, index) => ` --ascii-mask-${index}: ${mask};`).join('\n')}}@keyframes ascii-depart { ${outgoing} 100% { mask-image: ${frames[4]}; opacity: 0; } }@keyframes ascii-arrive { ${incoming} }`, );}