OT: Type on Background - Contrast Ratios
hh
hh at hyperhh.de
Thu Oct 6 17:34:22 EDT 2016
> Jacqueline L.G. wrote:
> Does this work well enough?:
>
> function luminanceRatio c1,c2 -- pass two RGB triplets
> put calcLuminance(c1) into tL1
> put calcLuminance(c2) into tL2
> return max(tL1,tL2) / min(tL1,tL2)
> end luminanceRatio
>
> function calcLuminance pRGB
> -- wikipedia: Y = 0.2126 R + 0.7152 G + 0.0722 B
> put item 1 of pRGB * 0.2126 into tR
> put item 2 of pRGB * 0.7152 into tG
> put item 3 of pRGB * 0.0722 into tB
> return sum(tR,tG,tB)
> # if sum(tR,tG,tB) > 125 then return "black"
> # else return "white"
> end calcLuminance
In case black is also an option as color then the following
ratio, known as contrast ratio, avoids dividing by zero:
function contrastRatio c1,c2 -- pass two RGB triplets
put calcLuminance(c1) into tL1
put calcLuminance(c2) into tL2
return (0.05 + max(tL1,tL2)) / (0.05 + min(tL1,tL2))
end contrastRatio
More information about the use-livecode
mailing list