Skip to contents

Makes a colour lighter on a dark surface, or darker on a light one, until its contrast with the surface, as contrast_ratio() measures it, reaches ratio: by default 2:1, enough to see a part of a ring whose name and share the legend gives in words. It steps the lightness of the colour in OKLab, a colour space whose lightness follows the eye, and keeps its hue.

Usage

visible_color(hex, surface, ratio = 2)

Arguments

hex

The colour, as "#RRGGBB".

surface

The colour of the surface.

ratio

The contrast to reach.

Value

The colour, as "#RRGGBB": hex itself when it stands out enough already.

Examples

rghcard:::visible_color("#012456", "#0d1117")   # PowerShell on GitHub's dark mode: lighter
#> [1] "#24487D"
rghcard:::visible_color("#F1E05A", "#ffffff")   # JavaScript on its light mode: darker
#> [1] "#CAB927"
rghcard:::visible_color("#198CE7", "#0d1117")   # R: as it is
#> [1] "#198CE7"