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

gamma-gradient

v1.0.0

Published

A TypeScript library providing gamma-corrected and HSL-corrected gradients for richer color transitions.

Downloads

4

Readme

Gamma Gradients

CSS gradients are lacklusture.

Notice how transitioning from red to green leaves a dull greyish-brown color in the middle.

That's because these gradients are calculated using linear interpolation in the RGB space, leading to unnatural blending that doesn't model how colors blur in the real world.

This Gamma Gradients library provides two methods to produce vivid gradients in CSS.

Gamma-Correction: This method involves linear interpolation subsequent to gamma correction. The result is a gradient that aligns more closely with human visual perception in the real world.

HSL-Correction: By interpolating across the HSL color space, this method maintains richer hues than RGB interpolation.

Installation

npm install gamma-gradients

or

yarn add gamma-gradients

Usage

Importing the Library

To start using the library, import the functions you need:

import {
  getGammaGradientString,
  calculateGammaCorrectedGradientSteps,
  getHSLGradientString,
  calculateHSLGradientSteps,
} from "gamma-gradients";

Gamma Corrected Gradient

Generate a gradient that transitions linearly in perceived brightness. This is achieved by gamma correcting the gradient stops, then linearly interpolating between them, and finally undoing the gamma correction.

Functions:

  • calculateGammaCorrectedGradientSteps(color1, color2, steps?, gamma?): Calculates the steps for a gamma-corrected gradient.
  • getGammaGradientString(color1, color2, direction?, steps?, gamma?): Generates a CSS gradient string for a gamma-corrected gradient.

Example:

const gradient = getGammaGradientString("#FF0000", "#0000FF");
console.log(gradient);

HSL Gradient

Generate a gradient that transitions linearly in the HSL color space.

Functions:

  • calculateHSLGradientSteps(color1, color2, steps?, reverse?): Calculates the steps for an HSL gradient. The reverse parameter helps determine the shortest path of transition.
  • getHSLGradientString(color1, color2, direction?, steps?, reverse?): Generates a CSS gradient string for an HSL gradient.

Example:

const hslGradient = getHSLGradientString("#FF0000", "#00FF00");
console.log(hslGradient);

Inspiration, maths, and playground

This library was inspried by a video from Henry Reich at MinutePhysics, which provides an explanation of gamma-corrected color blending.

Visit https://gradients.fnt.hm for a playground to explore the different parameters offered by these functions.


Coming soon

  1. Gradient corrections with more than 2 starting colors
  2. SASS plugin

Contributing

If you're interested in contributing, feel free to open a pull request or raise issues on the GitHub repository.

License

This project is licensed under the MIT License.