invert()
The invert
function allows you to get a negative color.
This function returns a new Spectrum
instance representing the inverted color.
Usage
import Spectrum, { invert } from '@snipshot/spectrum';
const yellow = new Spectrum('rgb', [255, 255, 0]);const negativeColor = invert(yellow, 1); // 1 is a weight of the inverted color
console.log(negativeColor.rgb); // { r: 0, g: 0, b: 255, a: 1 } - blue
Parameters
invert(color1Obj, weight)
Parameter | Type | Required | Valid range | Description |
---|---|---|---|---|
colorObj | Spectrum instance | true | - | The initial color |
weight | number | true | [0; 1] | The weight of the inverted color in the result |
Return Value
The invert
function returns a new Spectrum
instance representing the negative color.
Examples
Weight is 0.5
When the weight
value is equal to 0.5 (50% of initial color and 50% of inverted color),
it will always produce grey color (#808080
).
import Spectrum, { invert } from '@snipshot/spectrum';
const yellow = new Spectrum('rgb', [255, 255, 0]);const negativeYellow = invert(yellow, 0.5);
console.log(negativeYellow.hex); // #808080
const crimson = new Spectrum('hex', '#DC143C');const negativeCrimson = invert(crimson, 0.5);
console.log(negativeCrimson.hex); // #808080
Weight is 0
import Spectrum, { invert } from '@snipshot/spectrum';
const yellow = new Spectrum('rgb', [255, 255, 0]);const negativeColor = invert(yellow, 0);
console.log(negativeColor.rgb); // { r: 255, g: 255, b: 0, a: 1 } - initial color