> 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 _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode