Patterns for building performant ASCII/Unicode terminal animations including character grids, frame loops with requestAnimationFrame, and lifecycle cleanup for SPA frameworks.
Ships in supermodel-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Patterns for building performant, beautiful ASCII/Unicode animations. Examples use TypeScript but every technique is language-agnostic.
Every ASCII animation reduces to a 2D grid of characters updated over time. Three representations, pick based on need:
// Flat string — fastest for "write the whole frame at once"
let frame = rows.map((row) => row.join("")).join("\n");
pre.textContent = frame;
// 2D array — best for per-cell logic
const grid: string[][] = Array.from({ length: height }, () =>
Array(width).fill(" "),
);
// 1D with stride — shader-like per-pixel operations
const cells = new Array(width * height).fill(" ");
const at = (x: number, y: number) => cells[y * width + x];
For DOM rendering, a single <pre> with one textContent assignment per frame is the gold standard — single reflow regardless of how many characters changed. Individual <span> per character collapses above ~500 elements.
requestAnimationFrame is the correct loop primitive. ASCII animations look better at 20-30fps than 60fps — the discrete nature of character changes reads as mechanical when updated too smoothly.
const TARGET_MS = 1000 / 24;
let lastFrame = 0;
let animId = 0;
function loop(now: number) {
if (now - lastFrame >= TARGET_MS) {
lastFrame = now;
updateGrid();
render();
}
if (!settled) {
animId = requestAnimationFrame(loop);
} else {
animId = 0;
}
}
animId = requestAnimationFrame(loop);
The if (!settled) guard is critical — stop the loop entirely when done. A running rAF with an early-return check still costs a function call per frame forever. Zero the ID on settle so cleanup code can check if (animId) to know whether a loop is active.
The most common production performance bug with ASCII animations is leaked rAF loops — not the animation itself being expensive, but stale loops accumulating across page navigations or re-initializations.
In SPA-style frameworks (Astro ClientRouter, React Router, Next.js, etc.), navigating away from a page doesn't necessarily destroy inline scripts or their closures. If the animation script runs again on re-entry without canceling the previous loop, you get multiple concurrent rAF callbacks. Each one updates the DOM independently — compounding frame cost and causing visible lag even after the animation has "finished."
The same applies to event listeners registered for replay/hide commands. Without cleanup, every re-initialization stacks new listeners.
Structure initAnimation() to return a teardown function. Call it before every re-init and on navigate-away:
function initAnimation(): (() => void) | undefined {
const el = document.getElementById("anim-target");
if (!el) return;
let animId = 0;
function runLoop(timeOrigin: number) {
function tick(now: number) {
// ... update + render ...
if (allSettled) {
animId = 0;
return;
}
animId = requestAnimationFrame(tick);
}
animId = requestAnimationFrame(tick);
}
runLoop(performance.now());
function handleReplay() {
if (animId) {
cancelAnimationFrame(animId);
animId = 0;
}
// ... reset state ...
runLoop(performance.now());
}
window.addEventListener("anim-replay", handleReplay);
// Return cleanup
return () => {
if (animId) {
cancelAnimationFrame(animId);
animId = 0;
}
window.removeEventListener("anim-replay", handleReplay);
};
}
Prevent stacking by always tearing down before re-init:
let cleanup: (() => void) | undefined;
function safeInit() {
if (cleanup) {
cleanup();
cleanup = undefined;
}
cleanup = initAnimation();
}
safeInit();
// SPA navigation hook (Astro example — adapt for your router)
document.addEventListener("astro:after-swap", () => {
if (window.location.pathname === "/") {
safeInit();
} else {
if (cleanup) {
cleanup();
cleanup = undefined;
}
}
});
after-swap / route-change listener, not one per initAnimation() call{ once: true } on cleanup listeners unless you're sure they fire exactly once per lifecycleCharacters define the visual language. Useful palettes:
| Purpose | Characters |
|---|---|
| Botanical / organic | ·.,:;*+~'" |
| Box drawing | │┤┐└┘├─┬┴┼╔╗╚╝═║ |
| Dense / noisy | ░▒▓█▄▀■□▪▫ |
| Dot density gradient | .:-=+*#%@ (space to dense) |
| Sparkle / ethereal | ·✦✧⋆˚°. |
| Matrix / digital | ハミヒーウシナモニサワツオリ0123456789 |
When cycling random characters before settling, pick from a charset visually similar to the final target. Cycling through box-drawing characters before settling on box-drawing looks intentional; cycling dense blocks before settling on a delicate dot looks like a glitch.
The most versatile animation pattern: each cell gets its own state machine, decoupling timing from rendering.
type CharState = {
target: string; // final display character
current: string; // current display character
state: "blank" | "cycling" | "settling" | "settled";
delay: number; // ms before animation starts
cycleEnd: number; // timestamp: cycling -> settling
settleEnd: number; // timestamp: settling -> settled
};
Frame update walks every cell, checks state against current timestamp, transitions as needed:
function updateCell(cell: CharState, now: number, elapsed: number) {
if (cell.state === "settled") return;
if (cell.state === "blank" && elapsed >= cell.delay) {
cell.state = "cycling";
cell.cycleEnd = elapsed + randomBetween(CYCLE_MIN, CYCLE_MAX);
}
if (cell.state === "cycling") {
if (elapsed >= cell.cycleEnd) {
cell.state = "settling";
cell.settleEnd = elapsed + randomBetween(SETTLE_MIN, SETTLE_MAX);
cell.current = cell.target;
} else if (Math.random() < FLICKER_PROB) {
cell.current = pickRandom(CYCLING_CHARS);
}
}
if (cell.state === "settling" && elapsed >= cell.settleEnd) {
cell.state = "settled";
cell.current = cell.target;
}
}
The delay assigned to each cell determines the visual shape of the reveal — this is where most artistic expression lives.
Distance from a point — Radial bloom/ripple. Origin can be center (explosion), bottom-center (growing), top-left (typewriter), or arbitrary.
const origin = { x: width / 2, y: height - 1 };
const maxDist = Math.hypot(width, height);
for (const cell of cells) {
const dist = Math.hypot(cell.x - origin.x, cell.y - origin.y);
cell.delay = (dist / maxDist) * BLOOM_SPREAD_MS + randomJitter();
}
Row-by-row — Bottom to top for growing, top to bottom for cascading. Simple and reliable.
Shuffled — Random order, no spatial logic. Good for "materializing from noise" effects.
Density-aware — Animate denser regions first, creating a bloom that follows the shape of the art rather than a geometric pattern.
Always add random jitter to delays. Without it, characters at the same distance animate in lockstep, which looks mechanical. Even +/-30ms breaks the regularity enough to feel organic.
const jitter = (Math.random() - 0.5) * 2 * JITTER_MS;
cell.delay = baseDelay + jitter;
The single biggest cause of animation-related lag is leaked loops, not expensive frames. See Lifecycle & Cleanup above. A single rAF loop updating a 500-cell grid at 24fps costs <1ms per frame. Two or three stacked loops doing the same work cause jank. Always verify with DevTools that exactly one rAF callback is active during animation and zero after settle.
For grids larger than ~2000 cells at 24+ fps:
textContent over innerHTML during animation — 5-10x faster, skips HTML parsingcontain: layout style paint on the container isolates the animation from page layouttextContent animation to innerHTML with colored spans, do it in requestIdleCallback or a 0ms setTimeoutFloat32Array or Uint8Array per property beats array-of-objects for memory locality on large grids (2000+ cells)join() on pre-existing arrays, don't create new arrays each framerequestAnimationFrame callbacks per vsync. One is correct. More than one means leaked loopsDeep-dives for specific techniques. Load when the task calls for it:
What SKILL.md sets; muted values are Claude Code's defaults
22 skills in this plugin
/agent-configCoding agent harness config - Claude Code hooks and settings, Codex config.toml layers, sandbox and approvals, permission profiles, MCP, plugins./analytics-engineeringAnalytics engineering - dbt projects, maintainable SQL as CTE pipelines, event patterns (funnels, sessions, retention, window functions, MATCH_RECOGNIZE)./browser-automationBrowser automation with agent-browser - navigating, forms, screenshots, scraping, web app QA and dogfooding, Electron apps. Version-matched guides served by the CLI./bunBun runtime - native APIs over Node, bun build --compile, single-file HTML bundles, tsconfig. For repos with bun.lock or bun imports./chezmoichezmoi dotfiles - source state, file attributes, templates, run scripts, ignore rules, dry-run verification./context-engineeringAgent context - AGENTS.md, CLAUDE.md, rules, memory, skills, subagents. Session capture, codebase and package mapping, zg and ast-grep code search, agentsview history./supermodel-skills:ascii-animationsfrom supermodel-skills
npx claudepluginhub gwenwindflower/dotfiles --plugin supermodel-skillsOther plugins' skills for the same job