关于「感知均匀的色阶:明度阶、对比度约束、色域裁剪与暗色反转」,《跨站设计令牌与感知色彩》给出的定量结论是什么?

结论:在 sRGB 码值上插值的阶不均匀,在线性光上插值的阶更不均匀,OKLab 明度等距的阶最均匀,但它会把品牌主色挤出阶外,所以本章把主色锚定成阶上的一档,彩度取相对彩度,绿色这类尖点高的色相再加上限。对比度方面,任何颜色配黑字或白字至少一边有 4.583;同明度不同色相的对比度并不相同,必须逐族核算;「隔 6 档保证 4.5」这类档距规则可以写成令牌代数,而且不必为此牺牲感知均匀。越界颜色保持明度与色相降彩度,不做逐通道截断。暗色主题按角色重新求解,不做阶号对调。最后,三十个站点只该引用同一条阶上的档名:R07 的主色只差 2.13,派生出的阶却差到 6.76。下一章离开颜色本身,去看这些颜色在 50 毫秒之内给人留下什么印象,以及这个印象离成交还有多远。

数据口径:多站视觉漂移用令牌偏离数、色差与第一印象评分三个量描述,不合成总分;证据分为五级,每一次统一工程预先登记十项内容。 全部品牌、站点、颜色与评分都是虚构样本,全部计算由书中程序生成;涉及法规之处只写一般框架,不是法律意见。

English version

对照数据表

下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 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
查看完整验算程序
# 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)))

唯一数据源与引用

范雅福(Fan, Y.). (2026). 《跨三十站设计令牌代数、色彩感知均匀空间与品牌权威第一印象毫秒学》第 4 章「感知均匀的色阶:明度阶、对比度约束、色域裁剪与暗色反转」(版本 0.1.0). 5D Library. DOI 待发布

DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 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}
}

本书其他章节结论