1 ! Copyright (C) 2022 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3 USING: colors kernel math math.functions ;
8 : adjust-color ( u -- v )
9 dup 0.03928 <= [ 12.92 / ] [ 0.055 + 1.055 / 2.4 ^ ] if ;
13 : relative-luminance ( color -- n )
14 >rgba-components drop [ adjust-color ] tri@
15 [ 0.2126 * ] [ 0.7152 * ] [ 0.0722 * ] tri* + + ;
17 : contrast-ratio ( color1 color2 -- n )
18 [ relative-luminance ] bi@
19 2dup < [ swap ] when [ 0.05 + ] bi@ / ;
21 : passes-AA? ( contrast large? -- ? )
24 : passes-AAA? ( contrast large? -- ? )