Skip to content
Crafts

Drawn in characters

Craft 02 · ASCII, motion

Every character is a shape, not a brightness.

Everything on this page is plain text, redrawn about thirty times a second. Run your pointer through it.

Fig. 1The desert from my home page, 24 rows tall. Move through it: the lizard bolts, the cacti flower when you get close.

Everything here sits on one small engine. A piece is a block of text, and every frame it's redrawn character by character. Each character carries a bit of energy; when the pointer comes within reach it gets kicked away from it, and that energy bleeds off by 7% a frame, so it drifts home instead of snapping back. While it's moving it might show as a speck of dust instead of itself, which is what makes it look scattered rather than shifted.

lib/ascii/piece.ts · ts
let e = this.energy[i] * 0.93;
if (d < radius) {
  const k = 1 - d / radius;
  if (k > e) {
    e = k;
    this.angle[i] = Math.atan2(dy, dx);
  }
}
if (e > 0.06) {
  const push = e * e * 3.2;
  const nc = c + Math.round(Math.cos(this.angle[i]) * push);
  const nr = r + Math.round(Math.sin(this.angle[i]) * push * 0.55);
  out[nr][nc] = Math.random() < e * 0.7 ? pick(AGITATE) : ch;
}
Excerpt. Rows move about half as far as columns, because a character cell is twice as tall as it is wide.

The ground is the part that took longest. It's one ridge, a gentle sine, and each column picks its character from two things: where the line falls inside the cell, and how steep it is there. Steep gets a slash, rising and falling get a tick or a dot, flat gets a dash or an underscore depending on whether the ridge sits high or low in the row. I tried a second, farther ridge; it made the band busy, so it went.

lib/ascii/desert/scene.ts · ts
function heightChar(frac: number, slope: number) {
  if (slope > 0.9) return "\\";
  if (slope < -0.9) return "/";
  if (frac < 0.5) return slope < -0.3 ? "'" : slope > 0.3 ? "`" : "-";
  if (frac < 0.8) return slope < -0.3 || slope > 0.3 ? "." : "-";
  return "_";
}
Fig. 2Threads hanging from the top edge. Push them.

Each thread is a chain of points under Verlet integration: every point remembers where it was last frame, keeps 96% of that motion, and gets a little gravity and a slow sideways breeze. Then eight passes pull each pair back to its rest length, with the top point pinned. The fun part is the drawing. Nothing is rotated; each segment looks at its own angle and picks a character for it.

lib/ascii/rope.ts · ts
const ang = Math.atan2(b.x - a.x, b.y - a.y);
span.textContent = Math.abs(ang) < 0.16 ? "|" : ang > 0 ? "\\" : "/";
Under about nine degrees it hangs straight; past that it leans.
Fig. 3The record player from this site, in characters, 36 frames a turn.

This is the same turntable, rendered into text by shape rather than brightness. The usual way to make ASCII art treats each cell as a pixel and maps its brightness onto a ramp like .:-=+*#, which blurs every edge. Instead, every candidate character is drawn in JetBrains Mono and measured by how much ink lands in six circles laid out two by three. The picture is sampled with the same six circles, ten more reach into the neighbouring cells to sharpen each sample against what's around it, and the closest character wins. That's how a curved edge comes out as .Y' instead of a smear.