Skip to content

letiantian/color-mixture.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

mix two color with specified ratio

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published