Skip to main content
@spa-tools/utilities

tone

The tone function adds gray to a color.

Usage

import { tone } from '@spa-tools/utilities';

const redTonedExponentially = tone('#FF0000', 0.2);
console.log(redTonedExponentially.toHex());
// --> #eb3939
const redTonedLinearly = tone('#FF0000', 0.2, true);
console.log(redTonedLinearly.toHex());
// --> #e61a1a

Arguments

NameTypeRequired?DefaultDescription
rgbOrRgbaOrHexstringyes-RGB(A) or hex color string
rationumberyes-Interpolation ratio between 0 and 1
linearbooleannofalseIf true uses a linear interpolation algorithm; otherwise, exponential interpolation will be used

Returns

ColorObject object.