
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
gamma-gradient
Advanced tools
A TypeScript library providing gamma-corrected and HSL-corrected gradients for richer color transitions.
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.
npm install gamma-gradients
or
yarn add gamma-gradients
To start using the library, import the functions you need:
import {
getGammaGradientString,
calculateGammaCorrectedGradientSteps,
getHSLGradientString,
calculateHSLGradientSteps,
} from "gamma-gradients";
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.
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);
Generate a gradient that transitions linearly in the HSL color space.
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);
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.
If you're interested in contributing, feel free to open a pull request or raise issues on the GitHub repository.
This project is licensed under the MIT License.
FAQs
A TypeScript library providing gamma-corrected and HSL-corrected gradients for richer color transitions.
We found that gamma-gradient demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.