---
title: "Two-Ink Dither · Playground · Drew Minns"
description: "Two inks on offset grids, weaving into each other."
url: https://reallygood.work/playground/two-ink-dither/
---

Playground · 02

# Two-Ink Dither

Two inks on offset grids, weaving into each other.

Live piece: Ultramarine and orange ordered dither, drifting.

First ink

#0044ff

Second ink

#ff4a1c

Grid offset

4

Dot size

2px

Ink

1.00

Speed

1.0

How it works

Smooth tone becomes dots of ink on a fixed grid: there's no grey, only ink or paper.

The second ink sits on a grid offset by half a cell, so where the two shapes meet their dots weave rather than cover, and where both land they darken.

```js
// two inks on offset Bayer grids, so their dots weave into each other's gaps
const on1 = tone1 > B8[y & 7][x & 7];
const on2 = tone2 > B8[(y + 4) & 7][(x + 4) & 7];
const colour = on1 && on2 ? both : on1 ? ink1 : on2 ? ink2 : paper;
```

Make it yourself

The whole thing in one file, with no libraries. Save it as an .html file and open it. The settings at the top follow the controls above, so tune it there, then copy.

two-ink-dither.html

```html
<!doctype html>
<meta charset="utf-8">
<title>Two-Ink Dither</title>
<style>
  html, body { margin: 0; height: 100%; background: #ede9df; }
  canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; }
</style>
<canvas id="plate"></canvas>
<script>
const settings = {
  ink1: '#0044ff',       // the first ink
  ink2: '#ff4a1c',       // the second ink
  dot: 2,         // size of one dot, in CSS pixels
  offset: 4,   // how far the second ink's grid is shifted (4 is half a cell: the dots weave)
  speed: 1,     // how fast the shapes drift
  gain: 1,       // how much ink: higher fills more of the paper
};
const paper = [237, 233, 223];

// an 8×8 Bayer matrix: a threshold for every pixel, so smooth tone becomes an even pattern of dots
const bayer = n => { let m = [[0]]; while (m.length < n) { const s = m.length; m = Array.from({ length: s * 2 }, (_, y) => Array.from({ length: s * 2 }, (_, x) => 4 * m[y % s][x % s] + [0, 2, 3, 1][(y >= s ? 2 : 0) + (x >= s ? 1 : 0)])); } return m.map(r => r.map(v => (v + 0.5) / (n * n))); };
const B8 = bayer(8);
const hex = h => [1, 3, 5].map(i => parseInt(h.slice(i, i + 2), 16));

// each ink's shape is a few soft blobs drifting on slow sine paths
const blobsA = [{ x: .30, y: .42, r: .34, s: .9, p: 0 }, { x: .68, y: .58, r: .30, s: .7, p: 2.1 }, { x: .52, y: .22, r: .24, s: 1.1, p: 4.2 }, { x: .18, y: .80, r: .26, s: .8, p: 3.3 }];
const blobsB = [{ x: .62, y: .30, r: .30, s: .7, p: 5.0 }, { x: .85, y: .70, r: .28, s: .9, p: .7 }, { x: .40, y: .78, r: .22, s: .6, p: 2.6 }];
function tone(blobs, u, v, aspect, t, gain) {
  let sum = 0;
  for (const b of blobs) {
    const dx = (u - b.x - 0.16 * Math.sin(t * 0.22 * b.s + b.p)) * aspect, dy = v - b.y - 0.13 * Math.cos(t * 0.17 * b.s + b.p * 1.3);
    sum += Math.exp(-(dx * dx + dy * dy) / (b.r * b.r));
  }
  return Math.min(1, sum * gain);
}

const canvas = document.getElementById('plate'), ctx = canvas.getContext('2d');
let clock = 3, last = 0;

function draw(now) {
  clock += (now - last) / 1000 * settings.speed; last = now;
  // one canvas pixel per dot; CSS scales it up without smoothing
  const w = canvas.width = Math.ceil(innerWidth / settings.dot), h = canvas.height = Math.ceil(innerHeight / settings.dot);
  const img = ctx.createImageData(w, h), d = img.data, o = settings.offset;
  const i1 = hex(settings.ink1), i2 = hex(settings.ink2), both = i1.map((v, k) => (v + i2[k]) / 2 * 0.55);   // overprint darkens
  for (let y = 0, i = 0; y < h; y++) {
    for (let x = 0; x < w; x++, i += 4) {
      const u = x / w, v = y / h;
      // two inks on offset Bayer grids, so their dots weave into each other's gaps
      const on1 = tone(blobsA, u, v, w / h, clock, 0.8 * settings.gain) > B8[y & 7][x & 7];
      const on2 = tone(blobsB, u, v, w / h, clock, 1.05 * settings.gain) > B8[(y + o) & 7][(x + o) & 7];
      const c = on1 && on2 ? both : on1 ? i1 : on2 ? i2 : paper;
      d[i] = c[0]; d[i + 1] = c[1]; d[i + 2] = c[2]; d[i + 3] = 255;
    }
  }
  ctx.putImageData(img, 0, 0);
  setTimeout(() => requestAnimationFrame(draw), 40);   // 25 frames a second is plenty for print
}
requestAnimationFrame(t => { last = t; draw(t); });
</script>
```

-   [Previous piece — Glass Field](https://reallygood.work/playground/glass-field/)
-   [Next piece — Ink Gain](https://reallygood.work/playground/ink-gain/)
