Skip to content
← All writing

/ 3 min read

Dot matrix icons from code: 19 SVG icons on a 13 by 13 grid

How I drew an icon set as dots: a handful of drawing primitives, a tiny pixel font, and an SVG renderer. Why outlines have to be sampled, what a 13 by 13 grid cannot show, and the icons I had to redraw.

In this article

The Uses page of this site shows each tool with an icon made of dots. I did not draw them in a design tool. Each icon is a few lines of code on a 13 by 13 grid, which keeps the set consistent and lets the dots be drawn in order as you scroll.

An icon is a set of cells

The data model is deliberately tiny: an icon is a list of [x, y] cells that are lit. A pen object offers the primitives an icon needs, and each icon is a function that calls them.

type Pen = {
  put: (x: number, y: number) => void
  line: (x0: number, y0: number, x1: number, y1: number) => void
  ring: (cx: number, cy: number, r: number) => void
  disc: (cx: number, cy: number, r: number) => void
  ellipse: (cx: number, cy: number, rx: number, ry: number, rot?: number) => void
  rect: (x0: number, y0: number, x1: number, y1: number, fill?: boolean) => void
}

const ICONS = {
  postgres: (p) => {
    p.rect(1, 2, 11, 10)
    p.line(1, 5, 11, 5)
    p.line(1, 8, 11, 8)
    p.line(6, 2, 6, 10)
  },
}
A table, drawn with one rectangle and three lines.

Outlines must be sampled, not scanned

My first version drew rings and ellipses by scanning every cell and keeping those within a threshold of the curve. On a grid this small the threshold produced bands two or three dots thick, and the React atom came out as a solid blob. The fix is to walk along the curve and light the cell under each step, so the outline is one dot thick however small the grid is.

for (let t = 0; t < Math.PI * 2; t += 0.02) {
  const u = rx * Math.cos(t)
  const v = ry * Math.sin(t)
  put(cx + u * Math.cos(rot) - v * Math.sin(rot), cy + u * Math.sin(rot) + v * Math.cos(rot))
}
Sampling an ellipse outline, with a rotation.

Straight lines work the same way: step from one end to the other by the longer of the two distances and round each position to a cell.

A pixel font for monograms

Some tools are best recognised by a letter. A five by seven font with only the letters the set needs, T, S, N and Z, is a few strings, and the letters are drawn by the same put function as everything else. TypeScript is the letters TS; the Next.js icon is an N inside a ring.

Rendering: unlit dots make it read as a display

The renderer is one SVG with a 13 by 13 viewBox. It draws every cell of the grid as a faint small dot, then the lit cells on top as larger dots. The unlit grid is what makes the icon read as a dot matrix display and not as a scatter of points, and it costs 169 tiny circles.

<svg viewBox="0 0 13 13" aria-hidden>
  {Array.from({ length: 169 }, (_, n) => (
    <circle key={n} cx={(n % 13) + 0.5} cy={Math.floor(n / 13) + 0.5} r={0.14} className="dot-icon-off" />
  ))}
  {cells.map(([x, y]) => (
    <circle key={`${x}-${y}`} cx={x + 0.5} cy={y + 0.5} r={0.38} className="dot-icon-on" />
  ))}
</svg>
The whole renderer.

Because the icons are generated, the cells are computed once per icon and cached, and the lit dots keep the order in which the pen put them. That order is what the scroll animation uses to draw an icon stroke by stroke.

What 13 by 13 cannot show

I redrew several icons after looking at them at full size. The React atom, three overlapping orbits, was unreadable at this resolution, so it became an N in a ring. A first Playwright icon of two overlapping circles looked like noise; a play triangle inside a ring says "run the tests" better. The Vercel triangle was lopsided until I made each row grow by exactly one dot per side every second row, which keeps it symmetric around the centre column.

The lesson is to review the whole set side by side, at a larger size than it will ship. A contact sheet of all nineteen icons showed problems that were invisible one at a time, and it took four rounds before the set looked even.

When this is worth doing

  • It suits a small, consistent set that shares a visual language with the rest of the site.
  • It gives you animation for free, since the icon is already a list of ordered dots.
  • It is a poor fit for detailed logos. If a mark needs curves and fine detail, use the real SVG.

You can see the result on the Uses page, where the icons are drawn dot by dot as you scroll.

Next article ↗

Automated accessibility checks with axe: what they found on this site