NAME
colour/contrast - Colour contrast helpers.
SYNOPSIS
from colour/contrast import
contrast_ratio,
contrast_passes,
readable_text_colour;
say( contrast_ratio( "black", "white" ) );
say( readable_text_colour( "gold" ) );
DESCRIPTION
This pure-Zuzu module provides WCAG-style relative luminance and contrast ratio helpers. All colour arguments are parsed through std/colour via colour/palette.
EXPORTED FUNCTIONS
relative_luminance(String colour)Return the sRGB relative luminance for
colour.contrast_ratio(String foreground, String background)Return the contrast ratio between two colours.
contrast_passes(String foreground, String background, String level := "AA", Boolean large_text := false)Return whether the pair passes
AAorAAA. Large text uses the corresponding reduced thresholds.contrast_grade(String foreground, String background)Return
AAA,AA,AA Large, orFail.best_contrast(String background, Array colours)Return the candidate colour with the best contrast against
background.readable_text_colour(String background, String dark := "#000000", String light := "#ffffff")Return whichever of
darkorlighthas better contrast againstbackground.
COPYRIGHT AND LICENCE
colour/contrast is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.