Files

27 lines
1.1 KiB
Python

def lin(c):
c/=255
return c/12.92 if c<=0.03928 else ((c+0.055)/1.055)**2.4
def L(hex):
hex=hex.lstrip("#"); r,g,b=int(hex[0:2],16),int(hex[2:4],16),int(hex[4:6],16)
return 0.2126*lin(r)+0.7152*lin(g)+0.0722*lin(b)
def ratio(a,b):
la,lb=L(a),L(b); hi,lo=max(la,lb),min(la,lb)
return (hi+0.05)/(lo+0.05)
pairs=[
("ink-soft op paper","#5b6a70","#f6fafb","body"),
("ink-soft op paper-soft","#5b6a70","#eef4f7","body"),
("ink-soft op tint","#5b6a70","#e3f6fd","body"),
("ink op paper","#1f2a2e","#f6fafb","body"),
("action-deep link op paper","#0055ce","#f6fafb","body"),
("action(blue) tekst op paper","#0069ff","#f6fafb","body/eyebrow"),
("wit op action (CTA)","#ffffff","#0069ff","ui"),
("on-dark-soft op petrol","#c7dae0","#1d4852","body"),
("brand cyaan op petrol-deep","#4ebfd9","#15363d","label"),
("nav wit86 op petrol-deep","#dfe6e8","#15363d","nav"),
("apanel desc wit82 op petrol","#d6dee0","#1d4852","body"),
]
for name,fg,bg,kind in pairs:
r=ratio(fg,bg)
aa = "AA-ok" if r>=4.5 else ("AA-large-ok" if r>=3 else "FAIL")
print(f"{r:4.2f} {aa:12} {name}")