netbeast / colorsys

:art: Minimalistic color converter for RGB, HSV, HSL, CMYK, HEX and CSS strings
http://getyeti.co
MIT License
57 stars 16 forks source link

Move API to a Class format #1

Closed jsdario closed 8 years ago

jsdario commented 8 years ago

As suggested by github user @eduardo-costa we could implement an API more like the following:

var colorsys = require('colorsys')
colorsys.rgb.hsv({ r: 255, g: 255, b: 255 })
colorsys.hsv.rgb(...)

//also vector format (good for webgl)
colorsys.rgb.vec({ r: 255, g: 255, b: 255 }); //returns [1.0,1.0,1.0] or new Float32Array(...)
//Alpha for some applications is important
colorsys.rgb.vec({ r: 255, g: 255, b: 255, a: 128 }); //returns [1.0,1.0,1.0,0.5] or new Float32Array(...)

color.rgb.int({ r: 255, g: 255, b: 255 }); //returns 0xffffff
color.rgb.int({ r: 255, g: 255, b: 255, a:128 }); //returns 0x80ffffff ARGB
color.rgb.int({ r: 255, g: 255, b: 255, a:128 },true); //returns 0xffffff80 RGBA

color.int.rgb(0xffffff); //returns { r: 255, g: 255, b: 255 }

//lerp
color.rgb.lerp({rgb},{rgb},ratio); // blend 2 colors
color.int.lerp(...,r)
color.hsv.lerp(...,r)

//gradient (this one is useful some times)
color.rgb.gradient([{rgb},{rgb},{rgb},{rgb},...],r); //returns the correct blend between color intervals

Maybe we should keep the repo for the lightest version and open another one slightly more elaborated, written in ES6.

jsdario commented 8 years ago

Closing for lack of discussion.