What does Colour-Vision Deficiency and Discriminability conclude, in numbers, about “Closing the Loop: a Colour-Vision Check in the Front-End Style Library, the Colour-Vision-Safe Palette Checker and a Pre-Registered Test”?
Answer: Chapter 8 writes the rules as four colour-vision checks for a front-end style library, gives the distilled Colour-Vision-Safe Palette Checker and a pre-registered test, and states which results would overturn the core claim. Marked boxes separate published evidence, runnable Python calculations (21 programs), classical sources and the author's hypotheses.
Scope of the numbers: Marked boxes separate published evidence, runnable Python calculations (21 programs), classical sources and the author's hypotheses.
Data table
The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python only
| C1 btn-danger label white CR | 4.98 PASS |
| C1 btn-success label white CR | 5.13 PASS |
| C1 btn-ok-light label black CR 12.78 PASS | |
| C1 btn-primary label white CR | 5.75 PASS |
| C2 btn-danger vs btn-success icon=n least | 9.06 FAIL |
| C2 btn-danger vs btn-success icon=y least | 9.06 PASS |
| C2 btn-danger vs btn-ok-light icon=n least 26.18 PASS | |
| C3 four chart series, least | 1.25 FAIL: add marker shapes |
| C4 btn-danger next to btn-ok-light 3.03 | 1 PASS |
Show the full program
# Chapter 8. p81: a colour-vision check for a style library's tokens.
# Model: rules C1 to C4 of Chapter 8. C1 label contrast >= 4.5:1; C2
# semantic pairs need least CIEDE2000 >= 10 over the Machado 2009 views,
# or else a redundant icon and word; C3 chart series need >= 10, or else
# marker shapes; C4 adjacent controls >= 3:1. Tokens are illustrative.
import math
def lin(c):
v = c / 255.0
if v <= 0.04045:
return v / 12.92
return ((v + 0.055) / 1.055) ** 2.4
def rgb(h):
h = h.lstrip("#")
return tuple(lin(int(h[i:i + 2], 16)) for i in (0, 2, 4))
def lum(c):
return math.fsum((0.2126 * c[0], 0.7152 * c[1], 0.0722 * c[2]))
def contrast(a, b):
hi, lo = sorted((lum(a), lum(b)), reverse=True)
return (hi + 0.05) / (lo + 0.05)
# Machado, Oliveira and Fernandes 2009, Table 1, severity 1.0 (rows).
MACHADO = {
"protan": ((0.152286, 1.052583, -0.204868),
(0.114503, 0.786281, 0.099216),
(-0.003882, -0.048116, 1.051998)),
"deutan": ((0.367322, 0.860646, -0.227968),
(0.280085, 0.672501, 0.047413),
(-0.011820, 0.042940, 0.968881)),
"tritan": ((1.255528, -0.076749, -0.178779),
(-0.078411, 0.930809, 0.147602),
(0.004733, 0.691367, 0.303900)),
}
def sim(c, kind):
# applied to linear sRGB, then clipped to the display range
if kind == "normal":
return tuple(c)
out = []
for row in MACHADO[kind]:
v = math.fsum(m * x for m, x in zip(row, c))
out.append(min(1.0, max(0.0, v)))
return tuple(out)
SRGB_XYZ = ((0.4124, 0.3576, 0.1805),
(0.2126, 0.7152, 0.0722),
(0.0193, 0.1192, 0.9505))
def xyz(c):
return tuple(math.fsum(m * x for m, x in zip(row, c))
for row in SRGB_XYZ)
WHITE = xyz((1.0, 1.0, 1.0))
def _f(t):
d = 6.0 / 29.0
if t > d ** 3:
return t ** (1.0 / 3.0)
return t / (3.0 * d * d) + 4.0 / 29.0
def lab(c):
fx, fy, fz = (_f(v / w) for v, w in zip(xyz(c), WHITE))
return (116.0 * fy - 16.0, 500.0 * (fx - fy), 200.0 * (fy - fz))
def de00(p, q):
# CIEDE2000 with kL = kC = kH = 1 (Sharma, Wu and Dalal 2005)
l1, a1, b1 = p
l2, a2, b2 = q
cm = (math.hypot(a1, b1) + math.hypot(a2, b2)) / 2.0
g = 0.5 * (1.0 - math.sqrt(cm ** 7 / (cm ** 7 + 25.0 ** 7)))
a1p, a2p = (1.0 + g) * a1, (1.0 + g) * a2
c1p, c2p = math.hypot(a1p, b1), math.hypot(a2p, b2)
h1p = math.degrees(math.atan2(b1, a1p)) % 360.0 if c1p else 0.0
h2p = math.degrees(math.atan2(b2, a2p)) % 360.0 if c2p else 0.0
dl, dc = l2 - l1, c2p - c1p
if c1p * c2p == 0.0:
dhp = 0.0
else:
dhp = h2p - h1p
if dhp > 180.0:
dhp -= 360.0
elif dhp < -180.0:
dhp += 360.0
dh = 2.0 * math.sqrt(c1p * c2p) * math.sin(math.radians(dhp / 2.0))
lm, cmp_ = (l1 + l2) / 2.0, (c1p + c2p) / 2.0
if c1p * c2p == 0.0:
hm = h1p + h2p
elif abs(h1p - h2p) <= 180.0:
hm = (h1p + h2p) / 2.0
elif h1p + h2p < 360.0:
hm = (h1p + h2p + 360.0) / 2.0
else:
hm = (h1p + h2p - 360.0) / 2.0
r = math.radians
t = math.fsum((1.0, -0.17 * math.cos(r(hm - 30.0)),
0.24 * math.cos(r(2.0 * hm)),
0.32 * math.cos(r(3.0 * hm + 6.0)),
-0.20 * math.cos(r(4.0 * hm - 63.0))))
dtheta = 30.0 * math.exp(-((hm - 275.0) / 25.0) ** 2)
rc = 2.0 * math.sqrt(cmp_ ** 7 / (cmp_ ** 7 + 25.0 ** 7))
sl = 1.0 + 0.015 * (lm - 50.0) ** 2 / math.sqrt(20.0 + (lm - 50.0) ** 2)
sc = 1.0 + 0.045 * cmp_
sh = 1.0 + 0.015 * cmp_ * t
rt = -math.sin(2.0 * r(dtheta)) * rc
x, y, z = dl / sl, dc / sc, dh / sh
return math.sqrt(math.fsum((x * x, y * y, z * z, rt * y * z)))
def de76(p, q):
return math.sqrt(math.fsum((u - v) ** 2 for u, v in zip(p, q)))
VIEWS = ("protan", "deutan", "tritan")
LABEL = {"white": (1.0, 1.0, 1.0), "black": (0.0, 0.0, 0.0)}
BUTTONS = (("btn-danger", "D32F2F", "white"),
("btn-success", "2E7D32", "white"),
("btn-ok-light", "A5D6A7", "black"),
("btn-primary", "1565C0", "white"))
PAIRS = (("btn-danger", "btn-success", False),
("btn-danger", "btn-success", True),
("btn-danger", "btn-ok-light", False))
SERIES = ("1F77B4", "FF7F0E", "2CA02C", "D62728")
def least(a, b):
return min(de00(lab(sim(a, k)), lab(sim(b, k))) for k in VIEWS)
if __name__ == "__main__":
tok = {n: (rgb(h), LABEL[t]) for n, h, t in BUTTONS}
for n, h, t in BUTTONS:
cr = contrast(tok[n][0], tok[n][1])
print("C1 {:<13s} label {:<5s} CR {:5.2f} {}".format(
n, t, cr, "PASS" if cr >= 4.5 else "FAIL"))
for a, b, icon in PAIRS:
d = least(tok[a][0], tok[b][0])
ok = d >= 10.0 or icon
print("C2 {} vs {} icon={} least {:5.2f} {}".format(
a, b, "y" if icon else "n", d, "PASS" if ok else "FAIL"))
worst = min(least(rgb(SERIES[i]), rgb(SERIES[j]))
for i in range(len(SERIES))
for j in range(i + 1, len(SERIES)))
print("C3 four chart series, least {:5.2f} {}".format(
worst, "PASS" if worst >= 10.0 else "FAIL: add marker shapes"))
cr = contrast(tok["btn-danger"][0], tok["btn-ok-light"][0])
print("C4 btn-danger next to btn-ok-light {:4.2f}:1 {}".format(
cr, "PASS" if cr >= 3.0 else "FAIL"))Single source and citation
Fan, Y. (2026). Simulating Colour-Vision Deficiency and Colour Discriminability: Buttons and Charts as Seen by Red-Green Colour-Deficient Users (Version 1.0.0), Chapter 8: Closing the Loop: a Colour-Vision Check in the Front-End Style Library, the Colour-Vision-Safe Palette Checker and a Pre-Registered Test. 5D Library. DOI pending
DOI pending · monograph page goes live after publication · 5DL-B-324 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026324,
author = {Fan, Yafu},
title = {Simulating Colour-Vision Deficiency and Colour Discriminability: Buttons and Charts as Seen by Red-Green Colour-Deficient Users},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}Other chapter answers in this book
- Chapter 1 · Eight Per Cent and Four and a Half to One: Why Red and Green Buttons That Pass Contrast Still Collide
- Chapter 2 · Linear Light and Relative Luminance: What WCAG Contrast Computes and What It Leaves Out
- Chapter 3 · The Machado Matrices: Simulating Three Kinds of Dichromacy in Linear sRGB
- Chapter 4 · CIELAB and CIEDE2000: Turning "a Visible Difference" into a Number
- Chapter 5 · Safe Colours for Right and Wrong Buttons: a Hue Search and a Luminance-Only Scheme
- Chapter 6 · Chart Palettes: Discriminability Matrices and How Many Series Colour Can Carry
- Chapter 7 · Classical Sources East and West: the Paired Colours of the Kaogong ji and Dalton's 1798 Account