Apply filters to colors to simulate things like color blindness and night vision.
This project is maintained by skratchdot
Apply filters to colors to simulate things like color blindness and night vision. Tries to mimic the behavior of the svg feColorMatrix filter.
For more information about svg feColorMatrix:
This library uses modified logic from the following 3 resources:
Author: skratchdot
License: MIT
Copyright: Copyright (c) 2014 skratchdot.com
Example
var ColorMatrix = require('color-matrix').ColorMatrix;
var matrix = new ColorMatrix();
matrix.transform([222, 0, 173, 255], 'deuteranopia'); // returns [139, 155, 121, 1]
function
object
Stores a matrix in the list of available filters
Kind: inner property of ColorMatrix
Param | Type | Description |
---|---|---|
name | string |
the name of the filter |
filter | function |
a function that returns a 20 item array representing a matrix with 4 rows and 5 columns |
Example
colorMatrix.addFilter('myIndentityMatrix', function () {
return [
1, 0, 0, 0, 0,
0, 1, 0, 0, 0,
0, 0, 1, 0, 0,
0, 0, 0, 1, 0
];
}); // now you can call: colorMatrix.transform('myIndentityMatrix');
function
Gets the filter with the given name. Returns an identity matrix when not found.
Kind: inner property of ColorMatrix
Returns: function
- A function that returns a 5x4 matrix
Param | Type | Description |
---|---|---|
name | string |
the name of the filter |
Example
var fn = colorMatrix.getFilter('deuteranopia');
var result = fn([255, 0, 0, 255]); // result contains an rgba array
object
Kind: inner property of ColorMatrix
Returns: object
- A hash of all the filter functions.
Example
var filterFunctions = colorMatrix.getFilters();
var result = filterFunctions.cool([255, 0, 0, 255]);
Kind: inner property of ColorMatrix
Param | Type | Description |
---|---|---|
rgba | array |
An RGBA array |
filter | string |
The name of the filter function |
value | number | array |
The value to pass to the filter function |
Example
var result1 = colorMatrix.transform([255, 0, 0, 255], 'invert');
var result2 = colorMatrix.transform([255, 0, 0, 255], 'hueRotate', 180);