color-style
Quickly get an rgba()
or hsla()
string for CSS and 2D context, without string concatenation.
var rgb = ;contextfillStyle = ;
Usage
var rgb = rgb;var hsl = hsl; //... somewhere in your render loopcontextfillStyle = ; // "rgba(255,0,0,1.0)"contextfillStyle = ; // "rgba(255,0,0,0.5)" contextfillStyle = ; // "rgba(255, 128, 0, 0.8)"contextfillStyle = ; // "rgba(0,0,0,1.0)" contextfillStyle = ; // "hsla(230,50%,20%,0.5)"
Color components default to 0 if not specified; alpha will default to 1.0.
You can also pass an array or string to all methods:
;;;
methods
colorStyle(r, g, b, a)
The same as colorStyle.rgb
below.
colorStyle.rgb(r, g, b, a)
Returns a "rgba(..)"
string. This is also exported as the main function.
colorStyle.hsl(h, s, l, a)
Returns a "hsla(..)"
string.
colorStyle.rgba(r, g, b, a)
colorStyle.hsla(h, s, l, a)
Included for completeness; just aliases for the above functions.
License
MIT, see LICENSE.md for details.