contrast

package
v0.0.4-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Darker

func Darker(tone, ratio float64) float64

Darker returns a tone less than or equal to the given tone that satisfies the specified contrast ratio.

The returned value is in the range [0, 100]. Returns -1 if the desired contrast ratio cannot be achieved with the input tone.

tone must be in the range [0, 100]. Invalid values result in -1. ratio should be in the range [1, 21]; invalid values have undefined behavior.

func DarkerUnsafe

func DarkerUnsafe(tone, ratio float64) float64

DarkerUnsafe returns a tone less than or equal to the given tone that attempts to satisfy the specified contrast ratio.

The returned value is always in the range [0, 100]. Returns 0 if the desired contrast ratio cannot be achieved. Unlike Darker, this function does not fail but may not always satisfy the desired contrast ratio.

func Lighter

func Lighter(tone float64, ratio float64) float64

Lighter returns a tone greater than or equal to the given tone that satisfies the specified contrast ratio.

The returned value is in the range [0, 100]. Returns -1 if the desired contrast ratio cannot be achieved with the input tone.

tone must be in the range [0, 100]. Invalid values result in -1. ratio should be in the range [1, 21]; invalid values have undefined behavior.

func LighterUnsafe

func LighterUnsafe(tone, ratio float64) float64

LighterUnsafe returns a tone greater than or equal to the given tone that attempts to satisfy the specified contrast ratio.

The returned value is always in the range [0, 100]. Returns 100 if the desired contrast ratio cannot be achieved. Unlike Lighter, this function does not fail but may not always satisfy the desired contrast ratio.

func RatioOfTones

func RatioOfTones(toneA, toneB float64) float64

RatioOfTones returns the contrast ratio between two tones, in the range [1, 21].

toneA and toneB should be values between 0 and 100. Values outside this range will be clamped internally.

func RatioOfYs

func RatioOfYs(y1, y2 float64) float64

RatioOfYs returns the contrast ratio between two relative luminance values.

The ratio is calculated as (lighter + 5) / (darker + 5).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL