paint-by-the-numbers

1.1.0 • Public • Published

paint-by-the-numbers

A utility based on Microsoft Excel's "Color Scales" conditional formatter for number cells.

Usage

Constructor

You can use the Painter class like this:

const Painter = require("paint-by-the-numbers");

let p = new Painter(min, max, ...colorStops);

where:

  • min: the minimum numeric value of the range
  • max: the maximum numeric value of the range
  • colorStops: a comma-separated list of colors (min. 2). May be any value that can be parsed by Qix-'s color package as a color.

For example:

const Painter = require("paint-by-the-numbers");

let p = new Painter(0, 100, "#F00", "#0F0");

getRGBA(value)

Accepts a number as an argument, and outputs the color as an rgba() string:

e.g.

let color = p.getRGBA(50);
console.log(color); // Prints 'rgba(128, 128, 0, 1)'

Values less than min are set to min, and values greater than max are set to max.

Adding more color stops

You can add more than 2 colors in the Painter constructor. The first and last colors define the colors for the minimum and maximum values respectively. Any other colors in between are used to divide the range in equal segments.

For example, if you write:

let p = new Painter(0, 100, "#F00", "#0F0", "#00F");

then any value between 0 (or lower) and 50 will be in the linear gradient range between #F00 and #0F0. Any value between 50 and 100 will be in the linear gradient range between #0F0 and #00F.

Credits

Thanks to Qix- for his color node package.

/paint-by-the-numbers/

    Package Sidebar

    Install

    npm i paint-by-the-numbers

    Weekly Downloads

    0

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    5.57 kB

    Total Files

    6

    Last publish

    Collaborators

    • lmoustak