Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nano-color

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nano-color

HSV <-> RGB colors conversion utility library. HSV filter, coloring filter, gradients generating.

  • 1.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

nano-color

HSV <-> RGB colors conversion utility library. HSV filter, coloring filter, gradients generating.

NPM version [Build status] [travis-url][Test coverage] coveralls-url Dependency Status License Downloads

Functions

Common parameter names

  • R,G,B,A -- integer channel value (0..255);
  • h -- hue value (0..359);
  • s,v,a -- saturation, volume, alpha value (0..1);
  • g -- gamma value;
  • RGB -- [ R, G, B ];
  • RGBA -- [ R, G, B, A ];
  • IRGBA -- 0xRRGGBBAA;
  • IRGB -- 0xRRGGBB;
  • data -- array of bytes;
  • addr -- offset in an array of bytes.

setGamma(g)

set Gamma correction value

rgb2hsv(R,G,B)

Converts RGB to HSV. Returns array [ h, s, v ].

hsv2rgb(h,s,v)

Returns [ R, G, B ].

hsva2rgba(h,s,v,a)

Returns [ R, G, B, A ].

rgba2hsva(R,G,B,A)

Returns [ h, s, v, a ].

rgb2hex(RGB)

Return CSS hex color string -- '#RRGGBB'.

rgba2hex(RGBA)

Return SVN hex color string -- '#RRGGBBAA'.

hex2rgb(h)

Returns [ R, G, B ]. Eats '#RGB', '#RGBA', '#RRGGBB' and '#RRGGBBAA' formats.

hex2rgba(hex)

Returns [ R, G, B, A ]. Eats '#RGB', '#RGBA', '#RRGGBB' and '#RRGGBBAA' formats.

irgb2array(IRGB)

Returns [ R, G, B ].

irgba2array(IRGBA)

Returns [ R, G, B, A ].

hsva2irgba(h,s,v,a)

Returns 0xRRGGBBAA.

put_rgb(data, addr, RGBA)

Put or mix in RGBA to the RGB bitmap array (data).

put_rgba(data, addr, RGBA)

Put or mix in RGBA to the RGBA bitmap array (data).

hsv_filter(data, addr, h, s, v)

Applyes HSV filter to the bitmap pixel.

colorify_filter(data, addr, h, s, v)

Applyes Colorify filter to the bitmap pixel.

There are special case for v < 0. A result volume will be calculated by the formula (.21*r + .72*g + .07*b) * -val.

gradient(first_pos, last_pos, stops, fn)

  • {stops} -- Object with color stops like:
{ 0: '#000', 4000: '#1234', 6000: 0x33445566, 10000: [ 255, 255, 255, 255 ] }

where, keys of object should be numeric value in bounds between 0 and 10000, that means from 0 to 1.0.

  • {fn(position, RGBA)} -- callback function

Example:

> var c = require('nano-color');
c.gradient(0, 10, {
		0: '#000',
		4000: '#1234',
		6500: 0x33445566,
		10000: [ 255, 255, 7, 255 ]
	}, function (pos, RGBA) {
		console.log('%s: [ %s ]', pos, RGBA.join(', '));
	});

will produce console output:

0: [ 0, 0, 0, 255 ]
1: [ 4, 9, 13, 208 ]
2: [ 9, 17, 26, 162 ]
3: [ 13, 26, 38, 115 ]
4: [ 17, 34, 51, 68 ]
5: [ 31, 48, 65, 82 ]
6: [ 48, 65, 82, 99 ]
7: [ 80, 95, 74, 124 ]
8: [ 138, 148, 52, 168 ]
9: [ 197, 202, 29, 211 ]
10: [ 255, 255, 7, 255 ]

Keywords

FAQs

Package last updated on 17 Jan 2016

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc