OT: Type on Background - Contrast Ratios

J. Landman Gay jacque at hyperactivesw.com
Thu Oct 6 15:21:13 EDT 2016


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



On 10/6/16 12:58 PM, Sannyasin Brahmanathaswami wrote:
> For the RGB wizards… what is the algorithm to determine the luminance ratio between two colors?
>
> See w3C recommendations posted in today's Adobe's XD newsletter (useful feed) below.
>
> I'm thinking the total value of all three will serve.
>
>
> The WC3 sets minimum standards for contrast ratios, which represent how different a color is from another color (commonly written as 1:1 or 21:1, the higher the difference between the two numbers in the ratio, the greater the difference in relative luminance between the colors). The W3C recommends the following contrast ratios for body text and image text:
>
>   *   Small text should have a contrast ratio of at least 4.5:1 against its background. A ratio of 7:1 is preferred.
>   *   Large text (at 14 pt bold/18 pt regular and up) should have a contrast ratio of at least 3:1 against its background.
>
>
>
>
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


-- 
Jacqueline Landman Gay         |     jacque at hyperactivesw.com
HyperActive Software           |     http://www.hyperactivesw.com





More information about the use-livecode mailing list