# Code: the best dither through a filter

Part one (a still dither) is this folder; part two (a dither that changes every frame) is [`time/`](./time/README.md),
with its own README. Python 3 with numpy for everything, and a C compiler for the annealer. Run each from its folder.

| file | what it does | how to run |
|---|---|---|
| `filters.py` | The filters, as tap lists: Starlock's painterly pass linearised (`kuwahara`), boxes, Gaussians, a centre share plus a Gaussian, the 13-point Lee ball; and their frequency response. | imported |
| `lattice.py` | The exact error of a lattice dither `((A x + B y) mod N + 1/2) / N` through a filter, the exhaustive search over (A, B), and the three floors (any threshold array, any irrational lattice, any dither at all). | imported |
| `simulate.py` | Brute force, independent of the formulas: dither, round, filter, compare; flats and ramps. | imported |
| `check.py` | The formula against brute force, and the cases where a lattice tiles its window exactly. | `python3 check.py` (`out/check.txt`, seconds) |
| `starlock.py` | Starlock's pass: the floors, the best lattice by number of levels, where R2 ranks among all 786,432 lattices with 1024 levels. | `python3 starlock.py` (`out/starlock.txt`, about a minute) |
| `sweep.py` | A family of filters: best lattice against the floors. | `python3 sweep.py` (`out/sweep.txt`, seconds) |
| `strides.py` | White noise, Bayer, blue noise, IGN, R2 and the best lattice through the pass at pixel ratios 1, 2 and 3, by brute force. | `python3 strides.py` (`out/strides.txt`, about 1.5 minutes) |
| `bluenoise.py` | A void-and-cluster blue-noise tile (from the previous entry). | imported |
| `anneal.c`, `kernel.py`, `k5.txt` | The best general threshold tile by simulated annealing, with the exact per-pixel error; `k5.txt` is the pass per tap (`python3 kernel.py > k5.txt`). | `cc -O2 -o anneal anneal.c -lm && ./anneal 16 1500000 3e-6 3` |
| `independent/` | The fresh check's own code, written without our reasoning: its taps (`mytaps.py`), the formula against an exact integral over levels on 48 cases (`c1.py`), the floor by optimisation (`floor.py`, needs scipy), and a C search over every lattice (`search.c`). | `cd independent && python3 c1.py` (`out/independent-formula.txt`) |
| `maps.py` | The page's explorer data: the pass per tap (`taps.json`) and the two maps (`hmap.png`, `jmap.png`). | `python3 maps.py <out-dir>` |
| `time/` | Part two: the formula, floors, search and comparison with a time axis, Starlock's real glow path frame by frame, the browser check of the shipped flip, and its own fresh check. | see [`time/README.md`](./time/README.md) |

Everything is deterministic except the annealer's random walk (seeded) and `simulate.white`.
