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

@fantasy-color/map-color-space-polynomial

v2.1.0

Published

Transform a three-tuple from one color space into another passing the coefficients and degree of the transformation

Downloads

17

Readme

@fantasy-color/map-color-space-polynomial

Map a color—a three dimensional tuple—from one color space to another, using polynomials of three independent variables to calculate each new value. The coefficients and degree of the polynomials are provided as arguments.

Usage

To use this function, the first step is to set up the coefficients and the degree of the polynomials.

In this example we are mapping the color from the standard Lab* to a variation of that space that was shifted so that all colors are slightly darker (useful for hover effects). The coefficients have been prepared for a polynomial of degree 2.

import { mapColorSpace } from '@fantasy-color/map-color-space-polynomial'

const coeffiecientsToMakeColorDarker = [
  [
    0.0028677056552058413,
    0.0002710888985503337,
    0.00030448981833043544,
    0.0004481466380241387,
    0.00002270969961606002,
    0.0001960549453038932,
    0.6781866204256397,
    -0.02179539063684411,
    -0.019592068432303808,
    1.1601847789138233,
  ],
  [
    -0.002093257907777501,
    0.000006010969931783787,
    -0.0003537230968659505,
    0.001442450208623714,
    0.0005974009953983765,
    -0.00015450114760720183,
    0.2841642502261257,
    0.8527281695672397,
    -0.023466271722765247,
    -8.08223975280506,
  ],
  [
    0.00023226214448834144,
    -0.00008760828343075633,
    -0.0003061844263532397,
    -0.0006035239404938528,
    0.0026425808332845874,
    0.00016252506133674548,
    -0.015621819880352397,
    0.06772075020928792,
    0.7716542598762682,
    -0.06925734380715776,
  ],
]

const mapLabToDarkerLab = (
  coeffiecientsToMakeColorDarker,
  2 // degree of the polynomials
)

mapLabToDarkerLab([60.16969588191749, 93.55002493980824, -60.498555897447304])
// [56.312232697106005, 88.206939784304, -56.340863699838685]

Note that while this example is meant change colors within the "same" color space, given a degree high enough and sufficient coefficients, any color space transformation can be approximated in this way. The other color functions in the @fantasy-color library are not using this method under the hood because for those transformations, more efficient functions that do not rely on polynomial approximations are already know.

Caveats

There is currently no provided way of getting the coefficients from input data. Functions to do that might be provided in the future.