contrast

package
v0.2.0-beta Latest Latest
Warning

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

Go to latest
Published: Oct 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 finds a darker tone meeting the specified contrast ratio.

Params:

  • tone: Base tone value (0-100).
  • ratio: Desired contrast ratio (1-21).

Returns float64 - Darker tone in [0,100]. Returns -1 if ratio cannot be met.

func DarkerUnsafe

func DarkerUnsafe(tone, ratio float64) float64

DarkerUnsafe finds a darker tone attempting to meet contrast ratio.

Unlike Darker, always returns a valid tone even if ratio cannot be met. Params:

  • tone: Base tone value (0-100).
  • ratio: Desired contrast ratio (1-21).

Returns float64 - Darker tone in [0,100]. Returns 0 if ratio cannot be met.

func Lighter

func Lighter(tone float64, ratio float64) float64

Lighter finds a lighter tone meeting the specified contrast ratio.

Params:

  • tone: Base tone value (0-100).
  • ratio: Desired contrast ratio (1-21).

Returns float64 - Lighter tone in [0,100]. Returns -1 if ratio cannot be met.

func LighterUnsafe

func LighterUnsafe(tone, ratio float64) float64

LighterUnsafe finds a lighter tone attempting to meet contrast ratio.

Unlike Lighter, always returns a valid tone even if ratio cannot be met. Params:

  • tone: Base tone value (0-100).
  • ratio: Desired contrast ratio (1-21).

Returns float64 - Lighter tone in [0,100]. Returns 100 if ratio cannot be met.

func RatioOfTones

func RatioOfTones(toneA, toneB float64) float64

RatioOfTones calculates the contrast ratio between two tones.

Params:

  • toneA: First tone value (0-100).
  • toneB: Second tone value (0-100).

Returns float64 - Contrast ratio in range [1, 21]. Values outside [0,100] are clamped.

func RatioOfYs

func RatioOfYs(y1, y2 float64) float64

RatioOfYs calculates the contrast ratio between two relative luminance values.

Params:

  • y1: First relative luminance value.
  • y2: Second relative luminance value.

Returns float64 - Ratio 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