What does Design-Token Algebra conclude, in numbers, about “Perceptually Uniform Ramps: Lightness Steps, Contrast Constraints, Gamut Clipping and Dark-Theme Inversion”?

Answer: Ramps interpolated on sRGB codes are uneven, ramps interpolated in linear light are more uneven, and ramps with even OKLab lightness are the most even but squeeze the brand primary off the ramp. So this chapter anchors the primary as a stop, uses relative chroma, and adds a cap for hues with high cusps such as green. On contrast: every colour reaches at least 4.583 with black or white text; at equal lightness, different hues give different contrast, so each family must be computed; distance rules such as "six stops apart guarantees 4.5" can be written as token algebra without giving up perceptual evenness. Out-of-gamut colours keep lightness and hue and lose chroma; they are never clamped channel by channel. Dark themes are solved role by role, never by swapping stop numbers. Finally, thirty sites should reference stop names on one shared ramp: R07's primary is only 2.13 off, but the ramp derived from it is 6.76 off. The next chapter leaves colour itself and asks what impression these colours leave within 50 milliseconds, and how far that impression is from a sale.

Scope of the numbers: All brands, sites, colours and ratings are invented, every calculation comes from the book's programs, and legal matters are described only in general terms, not as legal advice. Each hypothesis states what would refute it.

中文版

Data table

The numbers below are printed verbatim by the chapter's Python program and can be reproduced by running it. standard-library Python onlyprinted values that match the answer: 4.5, 4.583, 50

luminance equally far from white and black: Y = sqrt(1.05 x 0.05) - 0.050.17913
its contrast with both4.583; so every colour reaches at least 4.583 with white or black
white text needs Y <0.18333 for 4.5; black text needs Y >= 0.17500 for 4.5
highest OKLab L that still reaches each contrast against white, lowest L for 4.5 against black
family hue3.0 white 4.5 white 7.0 white 4.5 black
boutique17.6 0.6873 0.5884 0.4823 0.5798
report254.6 0.6710 0.5706 0.4655 0.5603
course161.9 0.6549 0.5573 0.4551 0.5482
card297.5 0.6784 0.5805 0.4759 0.5706
neutral -0.6682 0.5676 0.4658 0.5607
spread of the 4.5-on-white lightness over the four families0.0311; even ramp step 0.0730
report blue, end stops Y 0.9153 and 0.0135; ramp G per-stop contrast ratio r1.3128
stop ramp E OK L ramp G OK L
50 #F0F6FD0.9706 #EFF6FD 0.9699
100 #CADFFA0.8966 #C2DBF9 0.8826
200 #A4C8F60.8227 #97C0F5 0.7976
300 #7DB1F30.7501 #6CA8F2 0.7216
400 #539AF00.6792 #4190EE 0.6497
500 #2D82E20.6058 #2B7CD8 0.5857
600 #246CBE0.5310 #2368B8 0.5177
700 #1C589C0.4598 #1B569A 0.4535
800 #14447B0.3865 #14457D 0.3904
900 #0C315B0.3128 #0D335F 0.3213
950 #051F3D0.2388 #051F3D 0.2388
ramp E even OKLab L
worst contrast by stop distance 1..101.25 1.59 2.04 2.66 3.57 4.87 6.60 9.01 12.02 15.20
best contrast by stop distance 1..101.37 1.85 2.52 3.38 4.51 5.89 7.58 9.62 12.16 15.20
distance that guarantees 3.0 / 4.5 / 7.0 for every pair5 / 6 / 8
Show the full program
# Chapter 4. p42: Picking stops under contrast constraints: what a stop distance guarantees, two ways.
# WCAG 2.1 contrast is (Y1 + 0.05) / (Y2 + 0.05), Y = relative luminance. Part 1: the colour that is
# equally far from white and black, and the OKLab L each brand hue needs for 3.0, 4.5 and 7.0 against
# white and for 4.5 against black (hue held, relative chroma as in p41).
# Part 2: two 11-stop neutral-tinted ramps for the report blue with the same end stops:
#   ramp E spaces OKLab L evenly (the p41 rule);
#   ramp G spaces ln(Y + 0.05) evenly, so every pair of stops k apart has the same contrast r ** k.
# For each ramp: the worst-case contrast for each stop distance, and the smallest distance that
# guarantees 3.0, 4.5 and 7.0 for every pair; plus how even the perceptual (Delta E OK) gaps stay.
import math


def dec(c):
    return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4


def enc(v):
    v = min(1.0, max(0.0, v))
    return 12.92 * v if v <= 0.0031308 else 1.055 * v ** (1 / 2.4) - 0.055


def hex2rgb(h):
    return tuple(int(h[i:i + 2], 16) / 255 for i in (1, 3, 5))


def rgb2hex(rgb):
    return "#" + "".join("{:02X}".format(round(min(1.0, max(0.0, c)) * 255)) for c in rgb)


def oklab(rgb):
    r, g, b = (dec(c) for c in rgb)
    lms = (0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b,
           0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b,
           0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b)
    l_, m_, s_ = (math.copysign(abs(v) ** (1 / 3), v) for v in lms)
    return (0.2104542553 * l_ + 0.7936177850 * m_ - 0.0040720468 * s_,
            1.9779984951 * l_ - 2.4285922050 * m_ + 0.4505937099 * s_,
            0.0259040371 * l_ + 0.7827717662 * m_ - 0.8086757660 * s_)


def ok2lin(L, a, b):
    l_ = L + 0.3963377774 * a + 0.2158037573 * b
    m_ = L - 0.1055613458 * a - 0.0638541728 * b
    s_ = L - 0.0894841775 * a - 1.2914855480 * b
    l, m, s = l_ ** 3, m_ ** 3, s_ ** 3
    return (4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
            -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
            -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s)


def lch2ok(L, C, h):
    return (L, C * math.cos(math.radians(h)), C * math.sin(math.radians(h)))


def ok2lch(p):
    return (p[0], math.hypot(p[1], p[2]), math.degrees(math.atan2(p[2], p[1])) % 360)


def in_gamut(L, C, h, eps=1e-7):
    return all(-eps <= v <= 1 + eps for v in ok2lin(*lch2ok(L, C, h)))


def cmax(L, h):
    lo, hi = 0.0, 0.5
    for _ in range(50):
        mid = (lo + hi) / 2
        lo, hi = (mid, hi) if in_gamut(L, mid, h) else (lo, mid)
    return lo


def to_hex(L, C, h):
    return rgb2hex(tuple(enc(v) for v in ok2lin(*lch2ok(L, C, h))))


def lum(rgb):
    r, g, b = (dec(c) for c in rgb)
    return 0.2126 * r + 0.7152 * g + 0.0722 * b


def contrast(h1, h2):
    y1, y2 = lum(hex2rgb(h1)), lum(hex2rgb(h2))
    return (max(y1, y2) + 0.05) / (min(y1, y2) + 0.05)


def dok(h1, h2):
    p, q = oklab(hex2rgb(h1)), oklab(hex2rgb(h2))
    return math.sqrt(math.fsum((x - y) ** 2 for x, y in zip(p, q)))


NAMES = [50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950]
BRANDS = [("boutique", "#8C2F39"), ("report", "#1F5FA8"), ("course", "#2E7D5B"), ("card", "#6B4FA0")]
TARGETS = (3.0, 4.5, 7.0)


def stop_hex(L, h, rc):
    return to_hex(L, rc * cmax(L, h), h)


def l_for(target, h, rc, against):
    lo, hi = 0.0, 1.0
    for _ in range(40):
        mid = (lo + hi) / 2
        ok = contrast(stop_hex(mid, h, rc), against) >= target
        if against == "#FFFFFF":
            lo, hi = (lo, mid) if not ok else (mid, hi)
        else:
            lo, hi = (mid, hi) if not ok else (lo, mid)
    return lo if against == "#FFFFFF" else hi


ystar = math.sqrt(1.05 * 0.05) - 0.05
print("luminance equally far from white and black: Y = sqrt(1.05 x 0.05) - 0.05 = {:.5f}".format(ystar))
print("   its contrast with both: {:.3f}; so every colour reaches at least {:.3f} with white or black".format(
    1.05 / (ystar + 0.05), 1.05 / (ystar + 0.05)))
print("   white text needs Y <= {:.5f} for 4.5; black text needs Y >= {:.5f} for 4.5".format(
    1.05 / 4.5 - 0.05, 4.5 * 0.05 - 0.05))
print("highest OKLab L that still reaches each contrast against white, lowest L for 4.5 against black")
print("   family    hue    3.0 white  4.5 white  7.0 white  4.5 black")
spread = []
for fam, hx in BRANDS:
    L, C, h = ok2lch(oklab(hex2rgb(hx)))
    rc = C / cmax(L, h)
    cells = [l_for(t, h, rc, "#FFFFFF") for t in TARGETS] + [l_for(4.5, h, rc, "#000000")]
    print("   {:8s}  {:5.1f}  {}".format(fam, h, "  ".join("{:9.4f}".format(c) for c in cells)))
    spread.append(cells[1])
grey = [l_for(t, 0.0, 0.0, "#FFFFFF") for t in TARGETS] + [l_for(4.5, 0.0, 0.0, "#000000")]
print("   {:8s}  {:>5s}  {}".format("neutral", "-", "  ".join("{:9.4f}".format(c) for c in grey)))
print("   spread of the 4.5-on-white lightness over the four families: {:.4f}; even ramp step {:.4f}".format(
    max(spread) - min(spread), (0.97 - 0.24) / 10))

L0, C0, H0 = ok2lch(oklab(hex2rgb("#1F5FA8")))
RC = C0 / cmax(L0, H0)
TOP, BOT = 0.97, 0.24
ytop, ybot = lum(hex2rgb(stop_hex(TOP, H0, RC))), lum(hex2rgb(stop_hex(BOT, H0, RC)))


def l_for_y(y):
    lo, hi = 0.0, 1.0
    for _ in range(40):
        mid = (lo + hi) / 2
        lo, hi = (mid, hi) if lum(hex2rgb(stop_hex(mid, H0, RC))) < y else (lo, mid)
    return (lo + hi) / 2


n = len(NAMES) - 1
ramp_e = [stop_hex(TOP + (BOT - TOP) * i / n, H0, RC) for i in range(n + 1)]
r = ((ytop + 0.05) / (ybot + 0.05)) ** (1 / n)
ramp_g = [stop_hex(l_for_y((ytop + 0.05) / r ** i - 0.05), H0, RC) for i in range(n + 1)]
print("report blue, end stops Y {:.4f} and {:.4f}; ramp G per-stop contrast ratio r = {:.4f}".format(
    ytop, ybot, r))
print("   stop  ramp E   OK L    ramp G   OK L")
for i in range(n + 1):
    print("   {:4d}  {}  {:.4f}  {}  {:.4f}".format(NAMES[i], ramp_e[i], oklab(hex2rgb(ramp_e[i]))[0],
                                                   ramp_g[i], oklab(hex2rgb(ramp_g[i]))[0]))
for name, ramp in (("E even OKLab L", ramp_e), ("G even log-contrast", ramp_g)):
    worst = [min(contrast(ramp[i], ramp[i + k]) for i in range(n + 1 - k)) for k in range(1, n + 1)]
    best = [max(contrast(ramp[i], ramp[i + k]) for i in range(n + 1 - k)) for k in range(1, n + 1)]
    need = [next(k + 1 for k, w in enumerate(worst) if w >= t) for t in TARGETS]
    gaps = [dok(ramp[i], ramp[i + 1]) for i in range(n)]
    print("ramp {}".format(name))
    print("   worst contrast by stop distance 1..10: " + " ".join("{:.2f}".format(w) for w in worst))
    print("   best contrast by stop distance 1..10:  " + " ".join("{:.2f}".format(b) for b in best))
    print("   distance that guarantees 3.0 / 4.5 / 7.0 for every pair: {} / {} / {}".format(*need))
    print("   dEOK gaps min {:.4f} max {:.4f} (max/min {:.2f})".format(
        min(gaps), max(gaps), max(gaps) / min(gaps)))

Single source and citation

Fan, Y. (2026). Design-Token Algebra across Thirty Sites, Perceptually Uniform Colour Spaces and the Millisecond Science of Brand-Authority First Impressions (Version 0.1.0), Chapter 4: Perceptually Uniform Ramps: Lightness Steps, Contrast Constraints, Gamut Clipping and Dark-Theme Inversion. 5D Library. DOI pending

DOI pending · monograph page goes live after publication · 5DL-B-140 · v0.1.0 · CC-BY-NC-ND-4.0

BibTeX
@book{fan2026140,
  author    = {Fan, Yafu},
  title     = {Design-Token Algebra across Thirty Sites, Perceptually Uniform Colour Spaces and the Millisecond Science of Brand-Authority First Impressions},
  year      = {2026},
  publisher = {5D Library},
  edition   = {0.1.0},
  note      = {DOI pending}
}

Other chapter answers in this book