Giter VIP home page Giter VIP logo

alpha-blend's Introduction

@napolab/alpha-blend

@napolab/alpha-blend library image

A TypeScript package to perform the alpha blending of two colors based on the given mathematical formulas.

Formulas

The blending is calculated using the following formulas:

$$\begin{align} \alpha &= \alpha_b \alpha_f + \alpha_b (1 - \alpha_f) + (1 - \alpha_b) \alpha_f \tag{1} \\\ &= \alpha_b + \alpha_f - \alpha_b \alpha_f \\\ &= \alpha_b (1 - \alpha_f) + \alpha_f \\\ C &= \frac{\alpha_b (1 - \alpha_f) C_b + \alpha_f C_f}{\alpha} \tag{4} \end{align}$$

For a detailed explanation, please refer to this article.

Usage

Features

  • Blend two colors with their respective alpha values.
  • Get the resulting color in HEX format.
  • Handle both HEX and RGBA input formats.

Sample Code

import { alphaBlend } from "@napolab/alpha-blend";

const foregroundColor = "#ff5733";
const backgroundColor = "rgba(255, 87, 51, 0.5)";
const blendedColor = alphaBlend(foregroundColor, backgroundColor);

// Outputs: '#ff5733ff'.
blendedColor;

Installation

To install the package, use:

npm install @napolab/alpha-blend

or

yarn add @napolab/alpha-blend

License

This project is licensed under the MIT License.

alpha-blend's People

Contributors

github-actions[bot] avatar naporin0624 avatar

alpha-blend's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.