gradient-gauss
A library to generate a color in a gradient using a Gaussian function. The gradient gauss library is provided a range of numbers and will then calculate the respective color for a given number with the range.
Simple demo showing the changes the gradient when certain parameters are tweaked.
Getting Started
Download the package via NPM
npm install gradient-gauss
import GradientGauss from 'gradient-gauss
or
const GradientGauss = require('gradient-gauss');
Examples
let gradient = new GradientGauss(1, 100);
let color = gradient.getColor(50);
Options can be provided to GradientGauss to modify the behavior when calculating the colors. The following are the values that can be provided via the options:
min
: the minimum value of your rangemax
: the maximum value of your rangeoutputFormat
: the result format of the color. Options are either 'rgba'
(for an rgba string) or 'array'
(for an array in the format [r,g,b,a])redCenterFactor
: the location of the red bell curve center within the range providedblueCenterFactor
: the location of the blue bell curve center withiin the range providedgreenCenterFactor
: the location of the green bell curve center withini the range providedrangeDivisor
: the number by which the number range will be divided the color bell curve widths
Note: The min and max options are not be used during instantiation. Check the documentation for more information on the options and default values.
options = {
outputFormat: 'array',
rangeDivisor: 4
};
let gradient = new GradientGauss(1, 100, options);
Options can also be provided to the getColors
function as one-time overrides. For permanent changes to the values, provide those options during instantiation.
options = {
max: 50,
};
new GradientGauss(1, 100).getColor(25, options);
Refer to the documentation for more information.
Documentation
Basic documentation
More to come.
License
Licensed under the MIT license.