Skip to main content

Contrast class

Namespace: Arlecchino.Rendering.Colors · Assembly: Arlecchino.Core

How far apart two colors read, by the ratio the accessibility guidelines are written in. It runs from 1 for a color on itself to 21 for black on white.

public static class Contrast

Fields

MemberSummary
PivotThe luminance at which a background is as far from white as it is from black. Below it a background is dark and wants light text; above it the other way.

Methods

MemberSummary
Between(Rgb, Rgb)The ratio between two colors, whichever way round they are given.
IsDark(Rgb)Whether a background wants light text on it.
Luminance(Rgb)How much light a color sends back, weighted the way an eye weights the three channels.
Reach(Rgb)The most contrast this background can give in the one direction text goes on it. A mid-gray background reaches about 5, so a ladder written for black cannot be had on it at any lightness.

Fields in detail

Pivot

public static readonly double Pivot { get; }

The luminance at which a background is as far from white as it is from black. Below it a background is dark and wants light text; above it the other way.

Type double

Methods in detail

Between(Rgb, Rgb)

public static double Between(Rgb one, Rgb other);

The ratio between two colors, whichever way round they are given.

Parameters

NameTypeDescription
oneRgbThe first color.
otherRgbThe second color.

Returns double — The ratio, from 1 to 21.

IsDark(Rgb)

public static bool IsDark(Rgb background);

Whether a background wants light text on it.

Parameters

NameTypeDescription
backgroundRgbThe color behind the text.

Returns booltrue when the background is the darker side of Contrast.Pivot.

Luminance(Rgb)

public static double Luminance(Rgb color);

How much light a color sends back, weighted the way an eye weights the three channels.

Parameters

NameTypeDescription
colorRgbThe color to measure.

Returns double — Luminance, from 0 for black to 1 for white.

Reach(Rgb)

public static double Reach(Rgb background);

The most contrast this background can give in the one direction text goes on it. A mid-gray background reaches about 5, so a ladder written for black cannot be had on it at any lightness.

Parameters

NameTypeDescription
backgroundRgbThe color behind the text.

Returns double — The ratio against white or black, whichever this background is further from.