ASCII
Render an image or a procedural field as a grid of text glyphs drawn from a configurable character ramp.
Overview
ASCII redraws its source as characters. The canvas is divided into monospace cells; each cell samples the source once and picks a glyph from the characters ramp by brightness, so dense glyphs carry the ink and sparse ones let the background through. The glyphs come from a small atlas drawn at runtime with your font, so any characters work: classic ramps, block elements, Braille, or a word repeated.
Glyphs ink the bright areas when the text is lighter than the background (the terminal look) and the shadows when the text is darker (the printed look). colorMode="source" tints each glyph with the color it replaces.
Without src, ASCII renders a slow procedural field, useful as a terminal-style background.
The playground uses free Unsplash photographs by Marc Wieland and Martin Péchy.
Installation
Usage
Procedural background
import { Ascii } from "honestui/shaders"
<Ascii className="h-80 rounded-xl" cellSize={14} color="#9ae6b4" backgroundColor="#06120b" />Image
<Ascii
alt="An alpine lake reflecting an orange sunset between dark mountain ridges."
className="h-80 rounded-xl"
colorMode="source"
characters=" .,:;i1tfLCG08@"
src="https://images.unsplash.com/photo-1776348568867-24146d18b736?auto=format&fit=crop&w=1600&q=85"
/>Order characters from the lightest to the densest glyph; the first is usually a space. Remote image hosts must allow cross-origin use so WebGL can read the pixels. Smaller cells show more of the picture but read less as text; around 10 to 16 pixels keeps both.
Accessibility
The glyphs are pixels on a canvas, not text: screen readers, search, and copy and paste do not see them. Never use ASCII to show words a reader needs; put real text in a separate layer. In image mode, write alt text for the image's purpose, or an empty string when it is decorative. The original image shows until the canvas is ready and remains in the accessibility tree afterwards.
The procedural field moves slowly and stops when the user prefers reduced motion, while the element is offscreen, and while the page is hidden.