Paint anything as coloured ASCII.
~6 KB · ZERO DEPENDENCIESZERO DEPS · WEBGL2
Any image, video, canvas or three.js scene, painted in coloured glyphs. Move across the picture above to resolve it.
Install
01 INSTALL
$ npm i asciipaintAdd asciipaint to this project: a library that paints an image, video, canvas or three.js scene as coloured ASCII glyphs on WebGL2. 1. Settle the brief: what gets painted (the source), where it goes on the page, and the colour behind it. Ask me for whichever of the three my request leaves out. 2. Install asciipaint with this project's package manager. 3. Pick one entry point by source: - A still image or logo: import "asciipaint/element", then use <ascii-img src alt width height> in place of <img>. It takes its background from the page. In React with TypeScript, declare the element once, as the docs show. - A video, a canvas, or anything that moves: asciipaint(canvas, options) from "asciipaint", with autoRender(paint, () => paint.draw(source)) as the frame loop. - A three.js scene: asciipaintThree(renderer) from "asciipaint/three", with paint.render(scene, camera) where renderer.render was. Needs three 0.170 or newer. 4. Read https://asciipaint.prafficoding.workers.dev/llms-full.txt for the exact API of the entry point you picked. The library is new, so these docs are the only reliable source for its options and methods. 5. Wire it up so that each of these that applies holds: - It runs in client-side code (useEffect, onMount, an Astro island). - The canvas has a CSS width and height. - background is the colour behind the canvas, in every colour scheme the page has. - Geist Mono at weight 600 is loaded. With asciipaint() or asciipaintThree(), font may name a monospace font the page already has instead. - A source from another origin is served with CORS headers and loaded with crossOrigin = "anonymous". - Unmounting calls loop.stop() and paint.dispose(). - The plain source shows when WebGL2 is missing: asciipaint() sits in a try/catch, and <ascii-img> is registered only after a WebGL2 check. 6. Done when the project's type check and build pass, every applicable line of step 5 holds, and you've told me where to look to see it painted.
02 PAINT
import { asciipaint } from "asciipaint"
;
const paint = asciipaint(canvas);
paint.draw(picture);03 PLAYGROUND
Drop your own picture onto the stage. It is painted on your machine and never uploaded.
— × — CELLS
SOURCE
RAMP DARK → BRIGHT
BACKGROUND
SPARKLE
YOUR SETTINGSupdates as you drag
import { asciipaint, autoRender } from "asciipaint";
const paint = asciipaint(canvas, { cell: [2.4, 3.4], ramp: "-=+*#%@", background: "#000000", sparkle: true });
autoRender(paint, () => paint.draw(sketch));04 ONE TAG
Import the element once, then use it like <img>. Every <ascii-img> on the page shares one WebGL context, so a whole wall of them costs one GPU setup.
orbit.svgSVG
chevrons.pngPNG
petals.svgSVG
hex.pngPNG
tide.svgSVG
moon.pngPNG
diamonds.svgSVG
dawn.pngPNG
leaf.svgSVG
steps.pngPNG
cross.svgSVG
nest.pngPNG
LOGOS.HTML
import "asciipaint/element";
<ascii-img src="orbit.svg"></ascii-img>
<ascii-img src="chevrons.png"></ascii-img>- SVG with only a viewBox, or a transparent PNG
- Transparent pixels stay paper
- One shared WebGL context for every tag
- Fires paint and error events, like <img>
05 THREE.JS
Swap renderer.render for pass.render. Same scene, same camera, painted in the same frame.
pass.render(scene, camera)
SCENE.TS
import { asciipaintThree }
from "asciipaint/three";
const pass = asciipaintThree(renderer);
pass.render(scene, camera);Graded with ACES Filmic and output as sRGB, so lit scenes keep their highlights.