JSPM

color-mixture

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 87
  • Score
    100M100P100Q72906F
  • License MIT

mix two color with specified ratio

Package Exports

  • color-mixture

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (color-mixture) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

color-mixture.js

To mix two color with specified ratio. This is a mirror of hexo/lib/plugins/helper/tagcloud.js.

Install

$ npm install color-mixture

Usage

Define a color

mixture.Color(color_string)

var mixture = require('color-mixture');

// hex
new mixture.Color('#0ff') // Color { r: 0, g: 255, b: 255, a: 1 }
new mixture.Color('#00ffff')  // Color { r: 0, g: 255, b: 255, a: 1 }

// rgb
new mixture.Color('rgb(0, 255, 255)')  // Color { r: 0, g: 255, b: 255, a: 1 }

// rgba
new mixture.Color('rgba(0, 255, 255, 0.1)') // Color { r: 0, g: 255, b: 255, a: 0.1 }

// hsl
new mixture.Color('hsl(2, 100%, 50%)')  // Color { a: 1, r: 255, g: 9, b: 0 }

// hsla
new mixture.Color('hsl(2, 100%, 50%, 0.1)') // Color { a: 0.1, r: 255, g: 9, b: 0 }

// color name
new mixture.Color('red') //Color { r: 255, g: 0, b: 0, a: 1 }

Get r,g,b,a of a color

var c = new mixture.Color('red');
c.r  //255
c.g  //0
c.b  //0
c.a  //1

toString

(new mixture.Color('rgb(0, 255, 255)')).toString()        // '#0ff'

(new mixture.Color('rgba(0, 255, 255, 0.1)')).toString()  // 'rgba(0, 255, 255, 0.1)'

Mix 2 color

color1.mix(color2, ratio)

var color1 = new mixture.Color('#000');  // Color { r: 0, g: 0, b: 0, a: 1 }
var color2 = new mixture.Color('#fff');  // Color { r: 255, g: 255, b: 255, a: 1 }

var mix_color = color1.mix(color2, 0.1);  // Color { r: 26, g: 26, b: 26, a: 1 }

License

The same license as hexo.