contrast

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 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 darker than the given tone and that meets the specified contrast ratio. The tone must be in the range [0, 100] and ratio must be in the range [1, 21]. It returns -1 if the ratio cannot be met.

func DarkerUnsafe

func DarkerUnsafe(tone, ratio float64) float64

DarkerUnsafe is like Darker but always returns a valid tone even if the ratio cannot be met. If the ratio cannot be met, it returns 0.

func Lighter

func Lighter(tone float64, ratio float64) float64

Lighter returns a tone lighter than the given tone and that meets the specified contrast ratio. The tone must be in the range [0, 100] and ratio must be in the range [1, 21]. It returns -1 if the ratio cannot be met.

func LighterUnsafe

func LighterUnsafe(tone, ratio float64) float64

LighterUnsafe is like Lighter but always returns a valid tone even if the ratio cannot be met. If the ratio cannot be met, it returns 100.

func RatioOfTones

func RatioOfTones(toneA, toneB float64) float64

RatioOfTones calculates the contrast ratio between two tones. toneA and toneB should be in the range [0, 100]. Values outside this range are clamped. The return value is the contrast ratio in the range [1, 21].

func RatioOfYs

func RatioOfYs(y1, y2 float64) float64

RatioOfYs calculates the contrast ratio between two relative luminance values. The ratio is computed 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