Skip to content

Commit

Permalink
Merge pull request #19 from kkaefer/gl
Browse files Browse the repository at this point in the history
Add support for generating WebGL colors
  • Loading branch information
gka committed Nov 18, 2013
2 parents 98b90f7 + ddb7a6b commit 764f89a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/api.coffee
Expand Up @@ -39,6 +39,9 @@ chroma.lch = (l,c,h) ->
chroma.hsi = (h,s,i) ->
new Color h,s,i,'hsi'

chroma.gl = (r,g,b,a) ->
new Color r*255,g*255,b*255,a,'gl'

chroma.interpolate = (a,b,f,m) ->
if not a? or not b?
return '#000'
Expand Down
5 changes: 5 additions & 0 deletions src/color.coffee
Expand Up @@ -90,6 +90,8 @@ class Color
# create color
if m == 'rgb'
me._rgb = [x,y,z,a]
else if m == 'gl'
me._rgb = [x*255,y*255,z*255,a]
else if m == 'hsl'
me._rgb = hsl2rgb x,y,z
me._rgb[3] = a
Expand Down Expand Up @@ -137,6 +139,9 @@ class Color
hsi: ->
rgb2hsi @_rgb

gl: ->
[@_rgb[0]/255, @_rgb[1]/255, @_rgb[2]/255, @_rgb[3]]

luminance: ->
luminance @_rgb

Expand Down
4 changes: 4 additions & 0 deletions test/apha-test.coffee
Expand Up @@ -53,6 +53,10 @@ vows
'rgb output': (topic) -> assert.deepEqual topic.rgb(), [255,0,0]
'rgba output': (topic) -> assert.deepEqual topic.rgba(), [255,0,0,0.25]

'gl output':
topic: -> chroma.gl 1, 0, 0, 0.25
'gloutput': (topic) -> assert.deepEqual topic.gl(), [1, 0, 0, 0.25]

'rgba css output':
topic: -> chroma.css 'hsla(0,100%,50%,0.25)'
'cssoutput': -> (topic) -> assert.equal topic.css(), 'rgba(255,0,0,0.25)'
Expand Down

0 comments on commit 764f89a

Please sign in to comment.