npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rgbetween

v0.0.2

Published

Lightweight colormaps using RGB color interpolation.

Downloads

3

Readme

rgbetween

npm version

rgbetween is a compact JavaScript package for creating colormaps using RGB color interpolation.

If more advanced features are needed, the package culori is recommended.

Installation

The module is available on npm:

npm install rgbetween

Examples of use

Opaque colors:

The colors must be encoded in a hexadecimal format. If stop values are not specified, the colors will be evenly distributed over the interval [0, 1].

const RGBetween = require("rgbetween");

const cmap = new RGBetween(["#ff0000", "#0000ff"]);
console.log(cmap.evaluate(0.5)); // Color halfway between red and blue

Custom stops:

Custom stop values can be specified in the second parameter of the constructor. These values should generally be increasing, but two consecutive stops can have the same value (leading to sharp transitions). Values below the first stop, or above the last stop, are mapped to the first and last colors, respectively.

const colors = ["#000083", "#00ffff", "#ffff00", "#ff0000", "#7f0000"];
const stops = [0.1, 0.5, 0.5, 0.7, 0.9];
const cmap = new RGBetween(colors, stops);

console.log(cmap.evaluate(0.05)); // Prints #000083

Custom stops and transparency:

Alternatively, the colors and stop values can be specified as an array of color-stop pairs. Transparency is handled by including the alpha channel in the hex format (e.g. #FF000080 is red with 50% transparency).

The method setEasing controls the amount of easing to apply during the interpolation, and expects a value between 0 and 1. By default, easing is disabled.

const colors = [
    ["#3b3b3b00", 0],
    ["#07564aff", 0.2],
    ["#435fabff", 0.3],
    ["#f901ffff", 0.6],
    ["#fdab0000", 1]
];
const cmap = new RGBetween(colors);
cmap.setEasing(0.2);

API

Constructor

new RGBetween(colors[, stops])

  • colors : The colors to interpolate between. Either an array of colors encoded as hex strings, or an array of arrays containing pairs of colors and stop values (e.g. [["#ff0000", 0], ["#00ff00", 1]]), required
  • stops : The stop positions of the colors
const cmap = new RGBetween(["#ff0000", "#0000ff"]);
const cmap = new RGBetween([["#ff0000", 0.2], ["#0000ff", 0.8]]);
const cmap = new RGBetween(["#ff0000", "#0000ff"], [0.2, 0.8]);

Method

cmap.evaluate(t, returnHex = true)

Evaluates the colormap. t is the position to evaluate, usually a number between 0 and 1.

When returnHex is true, the returned color is encoded as a hex color string. Otherwise, the return value is an array containing RGB(A) values (scaled to the interval [0, 1]).

const color = cmap.evaluate(0.3);
const [r, g, b] = cmap.evaluate(0.7, false);

cmap.setEasing(value)

Sets the amount of easing to use when interpolating between two colors. value should be between 0 and 1, where 0 is no easing and 1 is the highest amount possible.

cmap.setEasing(0.2);