diff --git a/lib/color-scheme.js b/lib/color-scheme.js index d38d564..63fa156 100644 --- a/lib/color-scheme.js +++ b/lib/color-scheme.js @@ -1,11 +1,11 @@ -// Generated by CoffeeScript 1.7.1 +// Generated by CoffeeScript 1.12.3 (function() { var ColorScheme, - __slice = [].slice, - __hasProp = {}.hasOwnProperty; + slice = [].slice, + hasProp = {}.hasOwnProperty; ColorScheme = (function() { - var clone, typeIsArray, word, _i, _len, _ref; + var clone, l, len, ref, typeIsArray, word; typeIsArray = Array.isArray || function(value) { return {}.toString.call(value) === '[object Array]'; @@ -13,9 +13,9 @@ ColorScheme.SCHEMES = {}; - _ref = "mono monochromatic contrast triade tetrade analogic".split(/\s+/); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - word = _ref[_i]; + ref = "mono monochromatic contrast triade tetrade analogic".split(/\s+/); + for (l = 0, len = ref.length; l < len; l++) { + word = ref[l]; ColorScheme.SCHEMES[word] = true; } @@ -56,9 +56,9 @@ }; function ColorScheme() { - var colors, _j; + var colors, m; colors = []; - for (_j = 1; _j <= 4; _j++) { + for (m = 1; m <= 4; m++) { colors.push(new ColorScheme.mutablecolor(60)); } this.col = colors; @@ -77,7 +77,7 @@ (without a leading "#") depending on the color scheme and addComplement parameter. For each set of four, the first is usually the most saturated color, the second a darkened version, the third a pale version and fourth - a less-pale version. + a less-pale version. For example: With a contrast scheme, "colors()" would return eight colors. Indexes 1 and 5 could be background colors, 2 and 6 could be foreground colors. @@ -87,7 +87,7 @@ */ ColorScheme.prototype.colors = function() { - var dispatch, h, i, j, output, used_colors, _j, _k, _ref1; + var dispatch, h, i, j, m, n, output, ref1, used_colors; used_colors = 1; h = this.col[0].get_hue(); dispatch = { @@ -146,8 +146,8 @@ throw "Unknown color scheme name: " + this._scheme; } output = []; - for (i = _j = 0, _ref1 = used_colors - 1; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; i = 0 <= _ref1 ? ++_j : --_j) { - for (j = _k = 0; _k <= 3; j = ++_k) { + for (i = m = 0, ref1 = used_colors - 1; 0 <= ref1 ? m <= ref1 : m >= ref1; i = 0 <= ref1 ? ++m : --m) { + for (j = n = 0; n <= 3; j = ++n) { output[i * 4 + j] = this.col[i].get_hex(this._web_safe, j); } } @@ -210,7 +210,7 @@ ColorScheme.prototype.rgb2hsv = function() { var b, d, g, h, max, min, r, rgb, s, v; - rgb = 1 <= arguments.length ? __slice.call(arguments, 0) : []; + rgb = 1 <= arguments.length ? slice.call(arguments, 0) : []; if ((rgb[0] != null) && typeIsArray(rgb[0])) { rgb = rgb[0]; } @@ -228,8 +228,41 @@ h = (r === max ? (g - b) / d : (g === max ? 2 + (b - r) / d : 4 + (r - g) / d)); h *= 60; h %= 360; - if (h < 0) { - h = 360 - h; + console.log('HSV', h, s, v); + return [h, s, v]; + }; + + ColorScheme.prototype.rgbToHsv = function() { + var b, d, g, h, max, min, r, rgb, s, v; + rgb = 1 <= arguments.length ? slice.call(arguments, 0) : []; + if ((rgb[0] != null) && typeIsArray(rgb[0])) { + rgb = rgb[0]; + } + r = rgb[0], g = rgb[1], b = rgb[2]; + r /= 255; + g /= 255; + b /= 255; + max = Math.max(r, g, b); + min = Math.min(r, g, b); + h = void 0; + s = void 0; + v = max; + d = max - min; + s = max === 0 ? 0 : d / max; + if (max === min) { + h = 0; + } else { + switch (max) { + case r: + h = (g - b) / d + (g < b ? 6 : 0); + break; + case g: + h = (b - r) / d + 2; + break; + case b: + h = (r - g) / d + 4; + } + h /= 6; } return [h, s, v]; }; @@ -246,7 +279,7 @@ */ ColorScheme.prototype.from_hex = function(hex) { - var b, c, g, h, h0, h1, h2, hsv, hsv1, i, i1, i2, k, num, r, rgbcap, s, v, wheelKeys, _ref1, _ref2; + var b, c, g, h, h0, h1, h2, hsv, hsv1, i, i1, i2, k, num, r, ref1, ref2, rgbcap, s, v, wheelKeys; if (hex == null) { throw "from_hex needs an argument"; } @@ -254,25 +287,26 @@ throw "from_hex(" + hex + ") - argument must be in the form of RRGGBB"; } rgbcap = /(..)(..)(..)/.exec(hex).slice(1, 4); - _ref1 = (function() { - var _j, _len1, _results; - _results = []; - for (_j = 0, _len1 = rgbcap.length; _j < _len1; _j++) { - num = rgbcap[_j]; - _results.push(parseInt(num, 16)); + ref1 = (function() { + var len1, m, results; + results = []; + for (m = 0, len1 = rgbcap.length; m < len1; m++) { + num = rgbcap[m]; + results.push(parseInt(num, 16)); } - return _results; - })(), r = _ref1[0], g = _ref1[1], b = _ref1[2]; - hsv = this.rgb2hsv((function() { - var _j, _len1, _ref2, _results; - _ref2 = [r, g, b]; - _results = []; - for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { - i = _ref2[_j]; - _results.push(i / 255); + return results; + })(), r = ref1[0], g = ref1[1], b = ref1[2]; + hsv = this.rgbToHsv((function() { + var len1, m, ref2, results; + ref2 = [r, g, b]; + results = []; + for (m = 0, len1 = ref2.length; m < len1; m++) { + i = ref2[m]; + results.push(i / 255); } - return _results; + return results; })()); + console.log('HSV', hsv); h0 = hsv[0]; h1 = 0; h2 = 1000; @@ -282,24 +316,24 @@ s = null; v = null; wheelKeys = []; - _ref2 = ColorScheme.COLOR_WHEEL; - for (i in _ref2) { - if (!__hasProp.call(_ref2, i)) continue; + ref2 = ColorScheme.COLOR_WHEEL; + for (i in ref2) { + if (!hasProp.call(ref2, i)) continue; wheelKeys.push(i); } for (i in wheelKeys.sort(function(a, b) { return a - b; })) { c = ColorScheme.COLOR_WHEEL[wheelKeys[i]]; - hsv1 = this.rgb2hsv((function() { - var _j, _len1, _ref3, _results; - _ref3 = c.slice(0, 3); - _results = []; - for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { - i = _ref3[_j]; - _results.push(i / 255); + hsv1 = this.rgbToHsv((function() { + var len1, m, ref3, results; + ref3 = c.slice(0, 3); + results = []; + for (m = 0, len1 = ref3.length; m < len1; m++) { + i = ref3[m]; + results.push(i / 255); } - return _results; + return results; })()); h = hsv1[0]; if (h >= h1 && h <= h0) { @@ -331,7 +365,7 @@ add_complement( BOOLEAN ) If BOOLEAN is true, an extra set of colors will be produced using the - complement of the selected color. + complement of the selected color. This only works with the analogic color scheme. The default is false. */ @@ -350,7 +384,7 @@ web_safe( BOOL ) Sets whether the colors returned by L<"colors()"> or L<"colorset()"> will be - web-safe. + web-safe. The default is false. */ @@ -429,12 +463,12 @@ }; ColorScheme.prototype._set_variant_preset = function(p) { - var i, _j, _results; - _results = []; - for (i = _j = 0; _j <= 3; i = ++_j) { - _results.push(this.col[i].set_variant_preset(p)); + var i, m, results; + results = []; + for (i = m = 0; m <= 3; i = ++m) { + results.push(this.col[i].set_variant_preset(p)); } - return _results; + return results; }; clone = function(obj) { @@ -566,60 +600,60 @@ }; mutablecolor.prototype.set_variant_preset = function(p) { - var i, _j, _results; - _results = []; - for (i = _j = 0; _j <= 3; i = ++_j) { - _results.push(this.set_variant(i, p[2 * i], p[2 * i + 1])); + var i, m, results; + results = []; + for (i = m = 0; m <= 3; i = ++m) { + results.push(this.set_variant(i, p[2 * i], p[2 * i + 1])); } - return _results; + return results; }; mutablecolor.prototype.get_hex = function(web_safe, variation) { - var c, color, formatted, i, k, max, min, rgb, rgbVal, s, str, v, _j, _k, _len1, _len2, _ref1; + var c, color, formatted, i, k, len1, len2, m, max, min, n, ref1, rgb, rgbVal, s, str, v; max = Math.max.apply(Math, (function() { - var _j, _len1, _ref1, _results; - _ref1 = ['red', 'green', 'blue']; - _results = []; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - color = _ref1[_j]; - _results.push(this["base_" + color]); + var len1, m, ref1, results; + ref1 = ['red', 'green', 'blue']; + results = []; + for (m = 0, len1 = ref1.length; m < len1; m++) { + color = ref1[m]; + results.push(this["base_" + color]); } - return _results; + return results; }).call(this)); min = Math.min.apply(Math, (function() { - var _j, _len1, _ref1, _results; - _ref1 = ['red', 'green', 'blue']; - _results = []; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - color = _ref1[_j]; - _results.push(this["base_" + color]); + var len1, m, ref1, results; + ref1 = ['red', 'green', 'blue']; + results = []; + for (m = 0, len1 = ref1.length; m < len1; m++) { + color = ref1[m]; + results.push(this["base_" + color]); } - return _results; + return results; }).call(this)); v = (variation < 0 ? this.base_value : this.get_value(variation)) * 255; s = variation < 0 ? this.base_saturation : this.get_saturation(variation); k = max > 0 ? v / max : 0; rgb = []; - _ref1 = ['red', 'green', 'blue']; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - color = _ref1[_j]; + ref1 = ['red', 'green', 'blue']; + for (m = 0, len1 = ref1.length; m < len1; m++) { + color = ref1[m]; rgbVal = Math.min.apply(Math, [255, Math.round(v - (v - this["base_" + color] * k) * s)]); rgb.push(rgbVal); } if (web_safe) { rgb = (function() { - var _k, _len2, _results; - _results = []; - for (_k = 0, _len2 = rgb.length; _k < _len2; _k++) { - c = rgb[_k]; - _results.push(Math.round(c / 51) * 51); + var len2, n, results; + results = []; + for (n = 0, len2 = rgb.length; n < len2; n++) { + c = rgb[n]; + results.push(Math.round(c / 51) * 51); } - return _results; + return results; })(); } formatted = ""; - for (_k = 0, _len2 = rgb.length; _k < _len2; _k++) { - i = rgb[_k]; + for (n = 0, len2 = rgb.length; n < len2; n++) { + i = rgb[n]; str = i.toString(16); if (str.length < 2) { str = "0" + str; @@ -651,4 +685,4 @@ }).call(this); -//# sourceMappingURL=color-scheme.map +//# sourceMappingURL=color-scheme.js.map diff --git a/lib/color-scheme.js.map b/lib/color-scheme.js.map new file mode 100644 index 0000000..7229502 --- /dev/null +++ b/lib/color-scheme.js.map @@ -0,0 +1,10 @@ +{ + "version": 3, + "file": "color-scheme.js", + "sourceRoot": "..", + "sources": [ + "src/lib/color-scheme.coffee" + ], + "names": [], + "mappings": ";AACA;AAAA,MAAA,WAAA;IAAA;;;EAAM;AAGJ,QAAA;;IAAA,WAAA,GAAc,KAAK,CAAC,OAAN,IAAiB,SAAE,KAAF;AAAa,aAAO,EAAE,CAAC,QAAQ,CAAC,IAAZ,CAAkB,KAAlB,CAAA,KAA6B;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AC,GAA1C;MACE,MAAA,CAAO,EAAP,EAAW,SAAA;AACT,eAAO;MADE,CAAX,EADF;KAAA,MAAA;MAIE,MAAM,CAAC,WAAP,GAAqB,YAJvB;KAHF;;AA/gBA" +} \ No newline at end of file diff --git a/lib/color-scheme.min.js b/lib/color-scheme.min.js index b8953a5..86faad7 100644 --- a/lib/color-scheme.min.js +++ b/lib/color-scheme.min.js @@ -1 +1 @@ -(function(){var t,e=[].slice,n={}.hasOwnProperty;t=function(){function t(){var e,n;for(e=[],n=1;4>=n;n++)e.push(new t.mutablecolor(60));this.col=e,this._scheme="mono",this._distance=.5,this._web_safe=!1,this._add_complement=!1}var r,o,a,i,u,s;for(o=Array.isArray||function(t){return"[object Array]"==={}.toString.call(t)},t.SCHEMES={},s="mono monochromatic contrast triade tetrade analogic".split(/\s+/),i=0,u=s.length;u>i;i++)a=s[i],t.SCHEMES[a]=!0;return t.PRESETS={"default":[-1,-1,1,-.7,.25,1,.5,1],pastel:[.5,-.9,.5,.5,.1,.9,.75,.75],soft:[.3,-.8,.3,.5,.1,.9,.5,.75],light:[.25,1,.5,.75,.1,1,.5,1],hard:[1,-1,1,-.6,.1,1,.6,1],pale:[.1,-.85,.1,.5,.1,1,.1,.75]},t.COLOR_WHEEL={0:[255,0,0,100],15:[255,51,0,100],30:[255,102,0,100],45:[255,128,0,100],60:[255,153,0,100],75:[255,178,0,100],90:[255,204,0,100],105:[255,229,0,100],120:[255,255,0,100],135:[204,255,0,100],150:[153,255,0,100],165:[51,255,0,100],180:[0,204,0,80],195:[0,178,102,70],210:[0,153,153,60],225:[0,102,178,70],240:[0,51,204,80],255:[25,25,178,70],270:[51,0,153,60],285:[64,0,153,60],300:[102,0,153,60],315:[153,0,153,60],330:[204,0,153,80],345:[229,0,102,90]},t.prototype.colors=function(){var t,e,n,r,o,a,i,u,s;if(a=1,e=this.col[0].get_hue(),t={mono:function(){return function(){}}(this),contrast:function(t){return function(){return a=2,t.col[1].set_hue(e),t.col[1].rotate(180)}}(this),triade:function(t){return function(){var n;return a=3,n=60*t._distance,t.col[1].set_hue(e),t.col[1].rotate(180-n),t.col[2].set_hue(e),t.col[2].rotate(180+n)}}(this),tetrade:function(t){return function(){var n;return a=4,n=90*t._distance,t.col[1].set_hue(e),t.col[1].rotate(180),t.col[2].set_hue(e),t.col[2].rotate(180+n),t.col[3].set_hue(e),t.col[3].rotate(n)}}(this),analogic:function(t){return function(){var n;return a=t._add_complement?4:3,n=60*t._distance,t.col[1].set_hue(e),t.col[1].rotate(n),t.col[2].set_hue(e),t.col[2].rotate(360-n),t.col[3].set_hue(e),t.col[3].rotate(180)}}(this)},t.monochromatic=t.mono,null==t[this._scheme])throw"Unknown color scheme name: "+this._scheme;for(t[this._scheme](),o=[],n=i=0,s=a-1;s>=0?s>=i:i>=s;n=s>=0?++i:--i)for(r=u=0;3>=u;r=++u)o[4*n+r]=this.col[n].get_hex(this._web_safe,r);return o},t.prototype.colorset=function(){var t,e;for(t=r(this.colors()),e=[];t.length>0;)e.push(t.splice(0,4));return e},t.prototype.from_hue=function(t){if(null==t)throw"from_hue needs an argument";return this.col[0].set_hue(t),this},t.prototype.rgb2hsv=function(){var t,n,r,a,i,u,s,h,l,c;return h=1<=arguments.length?e.call(arguments,0):[],null!=h[0]&&o(h[0])&&(h=h[0]),s=h[0],r=h[1],t=h[2],u=Math.min.apply(Math,[s,r,t]),i=Math.max.apply(Math,[s,r,t]),n=i-u,c=i,n>0?(l=n/i,a=s===i?(r-t)/n:r===i?2+(t-s)/n:4+(s-r)/n,a*=60,a%=360,0>a&&(a=360-a),[a,l,c]):[0,0,c]},t.prototype.from_hex=function(e){var r,o,a,i,u,s,h,l,c,f,p,_,m,d,v,g,b,y,w,E,M;if(null==e)throw"from_hex needs an argument";if(!/^([0-9A-F]{2}){3}$/im.test(e))throw"from_hex("+e+") - argument must be in the form of RRGGBB";g=/(..)(..)(..)/.exec(e).slice(1,4),E=function(){var t,e,n;for(n=[],t=0,e=g.length;e>t;t++)d=g[t],n.push(parseInt(d,16));return n}(),v=E[0],a=E[1],r=E[2],l=this.rgb2hsv(function(){var t,e,n,o;for(n=[v,a,r],o=[],t=0,e=n.length;e>t;t++)f=n[t],o.push(f/255);return o}()),u=l[0],s=0,h=1e3,p=null,_=null,i=null,b=null,y=null,w=[],M=t.COLOR_WHEEL;for(f in M)n.call(M,f)&&w.push(f);for(f in w.sort(function(t,e){return t-e}))o=t.COLOR_WHEEL[w[f]],c=this.rgb2hsv(function(){var t,e,n,r;for(n=o.slice(0,3),r=[],t=0,e=n.length;e>t;t++)f=n[t],r.push(f/255);return r}()),i=c[0],i>=s&&u>=i&&(s=i,p=f),h>=i&&i>=u&&(h=i,_=f);return(0===h||h>360)&&(h=360,_=360),m=h!==s?(u-s)/(h-s):0,i=Math.round(p+m*(_-p)),i%=360,b=l[1],y=l[2],this.from_hue(i),this._set_variant_preset([b,y,b,.7*y,.25*b,1,.5*b,1]),this},t.prototype.add_complement=function(t){if(null==t)throw"add_complement needs an argument";return this._add_complement=t,this},t.prototype.web_safe=function(t){if(null==t)throw"web_safe needs an argument";return this._web_safe=t,this},t.prototype.distance=function(t){if(null==t)throw"distance needs an argument";if(0>t)throw"distance("+t+") - argument must be >= 0";if(t>1)throw"distance("+t+") - argument must be <= 1";return this._distance=t,this},t.prototype.scheme=function(e){if(null==e)return this._scheme;if(null==t.SCHEMES[e])throw"'"+e+"' isn't a valid scheme name";return this._scheme=e,this},t.prototype.variation=function(e){if(null==e)throw"variation needs an argument";if(null==t.PRESETS[e])throw"'$v' isn't a valid variation name";return this._set_variant_preset(t.PRESETS[e]),this},t.prototype._set_variant_preset=function(t){var e,n,r;for(r=[],e=n=0;3>=n;e=++n)r.push(this.col[e].set_variant_preset(t));return r},r=function(t){var e,n,o;if(null==t||"object"!=typeof t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return e="",null!=t.global&&(e+="g"),null!=t.ignoreCase&&(e+="i"),null!=t.multiline&&(e+="m"),null!=t.sticky&&(e+="y"),new RegExp(t.source,e);o=new t.constructor;for(n in t)o[n]=r(t[n]);return o},t.mutablecolor=function(){function e(e){if(null==e)throw"No hue specified";this.saturation=[],this.value=[],this.base_red=0,this.base_green=0,this.base_blue=0,this.base_saturation=0,this.base_value=0,this.set_hue(e),this.set_variant_preset(t.PRESETS["default"])}return e.prototype.hue=0,e.prototype.saturation=[],e.prototype.value=[],e.prototype.base_red=0,e.prototype.base_green=0,e.prototype.base_saturation=0,e.prototype.base_value=0,e.prototype.get_hue=function(){return this.hue},e.prototype.set_hue=function(e){var n,r,o,a,i,u,s,h,l,c;n=function(t,e,n){return t+Math.round((e-t)*n)},this.hue=Math.round(e%360),i=this.hue%15+(this.hue-Math.floor(this.hue)),c=i/15,u=this.hue-Math.floor(i),s=(u+15)%360,o=t.COLOR_WHEEL[u],a=t.COLOR_WHEEL[s],h={red:0,green:1,blue:2,value:3};for(r in h)l=h[r],this["base_"+r]=n(o[l],a[l],c);return this.base_saturation=n(100,100,c)/100,this.base_value/=100},e.prototype.rotate=function(t){var e;return e=(this.hue+t)%360,this.set_hue(e)},e.prototype.get_saturation=function(t){var e,n;return n=this.saturation[t],e=0>n?-n*this.base_saturation:n,e>1&&(e=1),0>e&&(e=0),e},e.prototype.get_value=function(t){var e,n;return n=this.value[t],e=0>n?-n*this.base_value:n,e>1&&(e=1),0>e&&(e=0),e},e.prototype.set_variant=function(t,e,n){return this.saturation[t]=e,this.value[t]=n},e.prototype.set_variant_preset=function(t){var e,n,r;for(r=[],e=n=0;3>=n;e=++n)r.push(this.set_variant(e,t[2*e],t[2*e+1]));return r},e.prototype.get_hex=function(t,e){var n,r,o,a,i,u,s,h,l,c,f,p,_,m,d,v,g;for(u=Math.max.apply(Math,function(){var t,e,n,o;for(n=["red","green","blue"],o=[],t=0,e=n.length;e>t;t++)r=n[t],o.push(this["base_"+r]);return o}.call(this)),s=Math.min.apply(Math,function(){var t,e,n,o;for(n=["red","green","blue"],o=[],t=0,e=n.length;e>t;t++)r=n[t],o.push(this["base_"+r]);return o}.call(this)),p=255*(0>e?this.base_value:this.get_value(e)),c=0>e?this.base_saturation:this.get_saturation(e),i=u>0?p/u:0,h=[],g=["red","green","blue"],_=0,d=g.length;d>_;_++)r=g[_],l=Math.min.apply(Math,[255,Math.round(p-(p-this["base_"+r]*i)*c)]),h.push(l);for(t&&(h=function(){var t,e,r;for(r=[],t=0,e=h.length;e>t;t++)n=h[t],r.push(51*Math.round(n/51));return r}()),o="",m=0,v=h.length;v>m;m++)a=h[m],f=a.toString(16),f.length<2&&(f="0"+f),o+=f;return o},e}(),t}(),"undefined"!=typeof module&&null!==module&&null!=module.exports?module.exports=t:"function"==typeof define&&define.amd?define([],function(){return t}):window.ColorScheme=t}).call(this); \ No newline at end of file +(function(){var t,e=[].slice,n={}.hasOwnProperty;t=function(){function t(){var e,n;for(e=[],n=1;n<=4;n++)e.push(new t.mutablecolor(60));this.col=e,this._scheme="mono",this._distance=.5,this._web_safe=!1,this._add_complement=!1}var r,o,i,a,u,s;for(u=Array.isArray||function(t){return"[object Array]"==={}.toString.call(t)},t.SCHEMES={},a="mono monochromatic contrast triade tetrade analogic".split(/\s+/),o=0,i=a.length;o=u;n=0<=u?++o:--o)for(r=i=0;i<=3;r=++i)a[4*n+r]=this.col[n].get_hex(this._web_safe,r);return a},t.prototype.colorset=function(){var t,e;for(t=r(this.colors()),e=[];t.length>0;)e.push(t.splice(0,4));return e},t.prototype.from_hue=function(t){if(null==t)throw"from_hue needs an argument";return this.col[0].set_hue(t),this},t.prototype.rgb2hsv=function(){var t,n,r,o,i,a,s,h,l,c;return h=1<=arguments.length?e.call(arguments,0):[],null!=h[0]&&u(h[0])&&(h=h[0]),s=h[0],r=h[1],t=h[2],a=Math.min.apply(Math,[s,r,t]),i=Math.max.apply(Math,[s,r,t]),n=i-a,c=i,n>0?(l=n/i,o=s===i?(r-t)/n:r===i?2+(t-s)/n:4+(s-r)/n,o*=60,o%=360,o<0&&(o=360-o),[o,l,c]):[0,0,c]},t.prototype.from_hex=function(e){var r,o,i,a,u,s,h,l,c,f,p,_,m,d,v,g,b,y,w,E,M;if(null==e)throw"from_hex needs an argument";if(!/^([0-9A-F]{2}){3}$/im.test(e))throw"from_hex("+e+") - argument must be in the form of RRGGBB";y=/(..)(..)(..)/.exec(e).slice(1,4),g=function(){var t,e,n;for(n=[],e=0,t=y.length;e=s&&a<=u&&(s=a,p=f),a<=h&&a>=u&&(h=a,_=f);return(0===h||h>360)&&(h=360,_=360),m=h!==s?(u-s)/(h-s):0,a=Math.round(p+m*(_-p)),a%=360,w=l[1],E=l[2],this.from_hue(a),this._set_variant_preset([w,E,w,.7*E,.25*w,1,.5*w,1]),this},t.prototype.add_complement=function(t){if(null==t)throw"add_complement needs an argument";return this._add_complement=t,this},t.prototype.web_safe=function(t){if(null==t)throw"web_safe needs an argument";return this._web_safe=t,this},t.prototype.distance=function(t){if(null==t)throw"distance needs an argument";if(t<0)throw"distance("+t+") - argument must be >= 0";if(t>1)throw"distance("+t+") - argument must be <= 1";return this._distance=t,this},t.prototype.scheme=function(e){if(null==e)return this._scheme;if(null==t.SCHEMES[e])throw"'"+e+"' isn't a valid scheme name";return this._scheme=e,this},t.prototype.variation=function(e){if(null==e)throw"variation needs an argument";if(null==t.PRESETS[e])throw"'$v' isn't a valid variation name";return this._set_variant_preset(t.PRESETS[e]),this},t.prototype._set_variant_preset=function(t){var e,n,r;for(r=[],e=n=0;n<=3;e=++n)r.push(this.col[e].set_variant_preset(t));return r},r=function(t){var e,n,o;if(null==t||"object"!=typeof t)return t;if(t instanceof Date)return new Date(t.getTime());if(t instanceof RegExp)return e="",null!=t.global&&(e+="g"),null!=t.ignoreCase&&(e+="i"),null!=t.multiline&&(e+="m"),null!=t.sticky&&(e+="y"),new RegExp(t.source,e);o=new t.constructor;for(n in t)o[n]=r(t[n]);return o},t.mutablecolor=function(){function e(e){if(null==e)throw"No hue specified";this.saturation=[],this.value=[],this.base_red=0,this.base_green=0,this.base_blue=0,this.base_saturation=0,this.base_value=0,this.set_hue(e),this.set_variant_preset(t.PRESETS.default)}return e.prototype.hue=0,e.prototype.saturation=[],e.prototype.value=[],e.prototype.base_red=0,e.prototype.base_green=0,e.prototype.base_saturation=0,e.prototype.base_value=0,e.prototype.get_hue=function(){return this.hue},e.prototype.set_hue=function(e){var n,r,o,i,a,u,s,h,l,c;n=function(t,e,n){return t+Math.round((e-t)*n)},this.hue=Math.round(e%360),a=this.hue%15+(this.hue-Math.floor(this.hue)),c=a/15,u=this.hue-Math.floor(a),s=(u+15)%360,o=t.COLOR_WHEEL[u],i=t.COLOR_WHEEL[s],h={red:0,green:1,blue:2,value:3};for(r in h)l=h[r],this["base_"+r]=n(o[l],i[l],c);return this.base_saturation=n(100,100,c)/100,this.base_value/=100},e.prototype.rotate=function(t){var e;return e=(this.hue+t)%360,this.set_hue(e)},e.prototype.get_saturation=function(t){var e,n;return n=this.saturation[t],e=n<0?-n*this.base_saturation:n,e>1&&(e=1),e<0&&(e=0),e},e.prototype.get_value=function(t){var e,n;return n=this.value[t],e=n<0?-n*this.base_value:n,e>1&&(e=1),e<0&&(e=0),e},e.prototype.set_variant=function(t,e,n){return this.saturation[t]=e,this.value[t]=n},e.prototype.set_variant_preset=function(t){var e,n,r;for(r=[],e=n=0;n<=3;e=++n)r.push(this.set_variant(e,t[2*e],t[2*e+1]));return r},e.prototype.get_hex=function(t,e){var n,r,o,i,a,u,s,h,l,c,f,p,_,m,d,v,g;for(l=Math.max.apply(Math,function(){var t,e,n,o;for(n=["red","green","blue"],o=[],e=0,t=n.length;e0?g/l:0,_=[],p=["red","green","blue"],h=0,u=p.length;h) so that the @ refers to the right object? - dispatch = + dispatch = mono : () => contrast : () => used_colors = 2; @col[1].set_hue h @col[1].rotate(180) - + triade : () => used_colors = 3 dif = 60 * @_distance @@ -91,7 +91,7 @@ class ColorScheme @col[1].rotate 180 - dif @col[2].set_hue h @col[2].rotate 180 + dif - + tetrade : () => used_colors = 4 dif = 90 * @_distance @@ -101,7 +101,7 @@ class ColorScheme @col[2].rotate 180 + dif @col[3].set_hue h @col[3].rotate dif - + analogic : () => used_colors = if @_add_complement then 4 else 3 dif = 60 * @_distance @@ -114,7 +114,7 @@ class ColorScheme @col[2].rotate 360 - dif @col[3].set_hue h @col[3].rotate 180 - + # Alias for monochromatic dispatch['monochromatic'] = dispatch['mono'] @@ -190,6 +190,8 @@ class ColorScheme d = max - min v = max + # console.log "minmax", min, max, d, v + s if ( d > 0 ) s = d / max @@ -206,8 +208,40 @@ class ColorScheme h *= 60 h %= 360 - if (h < 0) - h = 360 - h + + # if (h < 0) + # h = 360 - h + + console.log 'HSV', h, s, v + + return [h, s, v] + + rgbToHsv: (rgb...) -> + rgb = rgb[0] if rgb[0]? and typeIsArray(rgb[0]) + [r, g, b] = rgb + + r /= 255 + g /= 255 + b /= 255 + max = Math.max(r, g, b) + min = Math.min(r, g, b) + h = undefined + s = undefined + v = max + d = max - min + s = if max == 0 then 0 else d / max + if max == min + h = 0 + # achromatic + else + switch max + when r + h = (g - b) / d + (if g < b then 6 else 0) + when g + h = (b - r) / d + 2 + when b + h = (r - g) / d + 4 + h /= 6 return [h, s, v] @@ -223,13 +257,16 @@ class ColorScheme ### from_hex: (hex) -> + # console.log 'HEX', hex + throw "from_hex needs an argument" if !hex? throw "from_hex(#{hex}) - argument must be in the form of RRGGBB" unless /// ^ ( [0-9A-F]{2} ) {3} $ ///im.test(hex) rgbcap = /(..)(..)(..)/.exec(hex)[1..3] [r, g, b] = (parseInt(num, 16) for num in rgbcap) - hsv = @rgb2hsv( i / 255 for i in [r, g, b] ) + hsv = @rgbToHsv( i / 255 for i in [r, g, b] ) + console.log 'HSV', hsv h0 = hsv[0] h1 = 0 h2 = 1000 @@ -242,8 +279,8 @@ class ColorScheme wheelKeys = []; wheelKeys.push i for own i of ColorScheme.COLOR_WHEEL for i of wheelKeys.sort( (a, b) -> a - b ) c = ColorScheme.COLOR_WHEEL[ wheelKeys[i] ] - - hsv1 = @rgb2hsv( i / 255 for i in c[ 0 .. 2 ] ) + + hsv1 = @rgbToHsv( i / 255 for i in c[ 0 .. 2 ] ) h = hsv1[0] if h >= h1 and h <= h0 h1 = h @@ -258,13 +295,16 @@ class ColorScheme k = if ( h2 != h1 ) then ( h0 - h1 ) / ( h2 - h1 ) else 0 h = Math.round( i1 + k * ( i2 - i1 ) ) + # console.log 'HUE', h h %= 360 s = hsv[1] v = hsv[2] + # console.log 'HUE', h + @from_hue h @_set_variant_preset( [ s, v, s, v * 0.7, s * 0.25, 1, s * 0.5, 1 ] ) - + return this ### @@ -272,7 +312,7 @@ class ColorScheme add_complement( BOOLEAN ) If BOOLEAN is true, an extra set of colors will be produced using the - complement of the selected color. + complement of the selected color. This only works with the analogic color scheme. The default is false. @@ -288,7 +328,7 @@ class ColorScheme web_safe( BOOL ) Sets whether the colors returned by L<"colors()"> or L<"colorset()"> will be - web-safe. + web-safe. The default is false. @@ -338,7 +378,7 @@ class ColorScheme variation( name ) - 'name' must be a valid color variation name. See "Color Variations" + 'name' must be a valid color variation name. See "Color Variations" ### @@ -356,7 +396,7 @@ class ColorScheme return obj if obj instanceof Date - return new Date(obj.getTime()) + return new Date(obj.getTime()) if obj instanceof RegExp flags = '' @@ -364,7 +404,7 @@ class ColorScheme flags += 'i' if obj.ignoreCase? flags += 'm' if obj.multiline? flags += 'y' if obj.sticky? - return new RegExp(obj.source, flags) + return new RegExp(obj.source, flags) newInstance = new obj.constructor() @@ -493,4 +533,4 @@ else define [], () -> return ColorScheme else - window.ColorScheme = ColorScheme \ No newline at end of file + window.ColorScheme = ColorScheme diff --git a/src/lib/color-scheme.js b/src/lib/color-scheme.js deleted file mode 100644 index 1f403eb..0000000 --- a/src/lib/color-scheme.js +++ /dev/null @@ -1,649 +0,0 @@ -// Generated by CoffeeScript 1.7.1 -var ColorScheme, - __slice = [].slice, - __hasProp = {}.hasOwnProperty; - -ColorScheme = (function() { - var clone, typeIsArray, word, _i, _len, _ref; - - typeIsArray = Array.isArray || function(value) { - return {}.toString.call(value) === '[object Array]'; - }; - - ColorScheme.SCHEMES = {}; - - _ref = "mono monochromatic contrast triade tetrade analogic".split(/\s+/); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - word = _ref[_i]; - ColorScheme.SCHEMES[word] = true; - } - - ColorScheme.PRESETS = { - "default": [-1, -1, 1, -0.7, 0.25, 1, 0.5, 1], - pastel: [0.5, -0.9, 0.5, 0.5, 0.1, 0.9, 0.75, 0.75], - soft: [0.3, -0.8, 0.3, 0.5, 0.1, 0.9, 0.5, 0.75], - light: [0.25, 1, 0.5, 0.75, 0.1, 1, 0.5, 1], - hard: [1, -1, 1, -0.6, 0.1, 1, 0.6, 1], - pale: [0.1, -0.85, 0.1, 0.5, 0.1, 1, 0.1, 0.75] - }; - - ColorScheme.COLOR_WHEEL = { - 0: [255, 0, 0, 100], - 15: [255, 51, 0, 100], - 30: [255, 102, 0, 100], - 45: [255, 128, 0, 100], - 60: [255, 153, 0, 100], - 75: [255, 178, 0, 100], - 90: [255, 204, 0, 100], - 105: [255, 229, 0, 100], - 120: [255, 255, 0, 100], - 135: [204, 255, 0, 100], - 150: [153, 255, 0, 100], - 165: [51, 255, 0, 100], - 180: [0, 204, 0, 80], - 195: [0, 178, 102, 70], - 210: [0, 153, 153, 60], - 225: [0, 102, 178, 70], - 240: [0, 51, 204, 80], - 255: [25, 25, 178, 70], - 270: [51, 0, 153, 60], - 285: [64, 0, 153, 60], - 300: [102, 0, 153, 60], - 315: [153, 0, 153, 60], - 330: [204, 0, 153, 80], - 345: [229, 0, 102, 90] - }; - - function ColorScheme() { - var colors, _j; - colors = []; - for (_j = 1; _j <= 4; _j++) { - colors.push(new ColorScheme.mutablecolor(60)); - } - this.col = colors; - this._scheme = 'mono'; - this._distance = 0.5; - this._web_safe = false; - this._add_complement = false; - } - - - /* - - colors() - - Returns an array of 4, 8, 12 or 16 colors in RRGGBB hexidecimal notation - (without a leading "#") depending on the color scheme and addComplement - parameter. For each set of four, the first is usually the most saturated color, - the second a darkened version, the third a pale version and fourth - a less-pale version. - - For example: With a contrast scheme, "colors()" would return eight colors. - Indexes 1 and 5 could be background colors, 2 and 6 could be foreground colors. - - Trust me, it's much better if you check out the Color Scheme web site, whose - URL is listed in "Description" - */ - - ColorScheme.prototype.colors = function() { - var dispatch, h, i, j, output, used_colors, _j, _k, _ref1; - used_colors = 1; - h = this.col[0].get_hue(); - dispatch = { - mono: (function(_this) { - return function() {}; - })(this), - contrast: (function(_this) { - return function() { - used_colors = 2; - _this.col[1].set_hue(h); - return _this.col[1].rotate(180); - }; - })(this), - triade: (function(_this) { - return function() { - var dif; - used_colors = 3; - dif = 60 * _this._distance; - _this.col[1].set_hue(h); - _this.col[1].rotate(180 - dif); - _this.col[2].set_hue(h); - return _this.col[2].rotate(180 + dif); - }; - })(this), - tetrade: (function(_this) { - return function() { - var dif; - used_colors = 4; - dif = 90 * _this._distance; - _this.col[1].set_hue(h); - _this.col[1].rotate(180); - _this.col[2].set_hue(h); - _this.col[2].rotate(180 + dif); - _this.col[3].set_hue(h); - return _this.col[3].rotate(dif); - }; - })(this), - analogic: (function(_this) { - return function() { - var dif; - used_colors = _this._add_complement ? 4 : 3; - dif = 60 * _this._distance; - _this.col[1].set_hue(h); - _this.col[1].rotate(dif); - _this.col[2].set_hue(h); - _this.col[2].rotate(360 - dif); - _this.col[3].set_hue(h); - return _this.col[3].rotate(180); - }; - })(this) - }; - dispatch['monochromatic'] = dispatch['mono']; - if (dispatch[this._scheme] != null) { - dispatch[this._scheme](); - } else { - throw "Unknown color scheme name: " + this._scheme; - } - output = []; - for (i = _j = 0, _ref1 = used_colors - 1; 0 <= _ref1 ? _j <= _ref1 : _j >= _ref1; i = 0 <= _ref1 ? ++_j : --_j) { - for (j = _k = 0; _k <= 3; j = ++_k) { - output[i * 4 + j] = this.col[i].get_hex(this._web_safe, j); - } - } - return output; - }; - - - /* - - colorset() - - Returns a list of lists of the colors in groups of four. This method simply - allows you to reference a color in the scheme by its group isntead of its - absolute index in the list of colors. I am assuming that "colorset()" - will make it easier to use this module with the templating systems that are - out there. - - For example, if you were to follow the synopsis, say you wanted to retrieve - the two darkest colors from the first two groups of the scheme, which is - typically the second color in the group. You could retrieve them with - "colors()" - - first_background = (scheme.colors())[1]; - second_background = (scheme.colors())[5]; - - Or, with this method, - - first_background = (scheme.colorset())[0][1] - second_background = (scheme.colorset())[1][1] - */ - - ColorScheme.prototype.colorset = function() { - var flat_colors, grouped_colors; - flat_colors = clone(this.colors()); - grouped_colors = []; - while (flat_colors.length > 0) { - grouped_colors.push(flat_colors.splice(0, 4)); - } - return grouped_colors; - }; - - - /* - - from_hue( degrees ) - - Sets the base color hue, where 'degrees' is an integer. (Values greater than - 359 and less than 0 wrap back around the wheel.) - - The default base hue is 0, or bright red. - */ - - ColorScheme.prototype.from_hue = function(h) { - if (h == null) { - throw "from_hue needs an argument"; - } - this.col[0].set_hue(h); - return this; - }; - - ColorScheme.prototype.rgb2hsv = function() { - var b, d, g, h, max, min, r, rgb, s, v; - rgb = 1 <= arguments.length ? __slice.call(arguments, 0) : []; - if ((rgb[0] != null) && typeIsArray(rgb[0])) { - rgb = rgb[0]; - } - r = rgb[0], g = rgb[1], b = rgb[2]; - min = Math.min.apply(Math, [r, g, b]); - max = Math.max.apply(Math, [r, g, b]); - d = max - min; - v = max; - s; - if (d > 0) { - s = d / max; - } else { - return [0, 0, v]; - } - h = (r === max ? (g - b) / d : (g === max ? 2 + (b - r) / d : 4 + (r - g) / d)); - h *= 60; - h %= 360; - if (h < 0) { - h = 360 - h; - } - return [h, s, v]; - }; - - - /* - - from_hex( color ) - - Sets the base color to the given color, where 'color' is in the hexidecimal - form RRGGBB. 'color' should not be preceded with a hash (#). - - The default base color is the equivalent of #ff0000, or bright red. - */ - - ColorScheme.prototype.from_hex = function(hex) { - var b, c, g, h, h0, h1, h2, hsv, hsv1, i, i1, i2, k, num, r, rgbcap, s, v, wheelKeys, _ref1, _ref2; - if (hex == null) { - throw "from_hex needs an argument"; - } - if (!/^([0-9A-F]{2}){3}$/im.test(hex)) { - throw "from_hex(" + hex + ") - argument must be in the form of RRGGBB"; - } - rgbcap = /(..)(..)(..)/.exec(hex).slice(1, 4); - _ref1 = (function() { - var _j, _len1, _results; - _results = []; - for (_j = 0, _len1 = rgbcap.length; _j < _len1; _j++) { - num = rgbcap[_j]; - _results.push(parseInt(num, 16)); - } - return _results; - })(), r = _ref1[0], g = _ref1[1], b = _ref1[2]; - hsv = this.rgb2hsv((function() { - var _j, _len1, _ref2, _results; - _ref2 = [r, g, b]; - _results = []; - for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { - i = _ref2[_j]; - _results.push(i / 255); - } - return _results; - })()); - h0 = hsv[0]; - h1 = 0; - h2 = 1000; - i1 = null; - i2 = null; - h = null; - s = null; - v = null; - wheelKeys = []; - _ref2 = ColorScheme.COLOR_WHEEL; - for (i in _ref2) { - if (!__hasProp.call(_ref2, i)) continue; - wheelKeys.push(i); - } - for (i in wheelKeys.sort(function(a, b) { - return a - b; - })) { - c = ColorScheme.COLOR_WHEEL[wheelKeys[i]]; - hsv1 = this.rgb2hsv((function() { - var _j, _len1, _ref3, _results; - _ref3 = c.slice(0, 3); - _results = []; - for (_j = 0, _len1 = _ref3.length; _j < _len1; _j++) { - i = _ref3[_j]; - _results.push(i / 255); - } - return _results; - })()); - h = hsv1[0]; - if (h >= h1 && h <= h0) { - h1 = h; - i1 = i; - } - if (h <= h2 && h >= h0) { - h2 = h; - i2 = i; - } - } - if (h2 === 0 || h2 > 360) { - h2 = 360; - i2 = 360; - } - k = h2 !== h1 ? (h0 - h1) / (h2 - h1) : 0; - h = Math.round(i1 + k * (i2 - i1)); - h %= 360; - s = hsv[1]; - v = hsv[2]; - this.from_hue(h); - this._set_variant_preset([s, v, s, v * 0.7, s * 0.25, 1, s * 0.5, 1]); - return this; - }; - - - /* - - add_complement( BOOLEAN ) - - If BOOLEAN is true, an extra set of colors will be produced using the - complement of the selected color. - - This only works with the analogic color scheme. The default is false. - */ - - ColorScheme.prototype.add_complement = function(b) { - if (b == null) { - throw "add_complement needs an argument"; - } - this._add_complement = b; - return this; - }; - - - /* - - web_safe( BOOL ) - - Sets whether the colors returned by L<"colors()"> or L<"colorset()"> will be - web-safe. - - The default is false. - */ - - ColorScheme.prototype.web_safe = function(b) { - if (b == null) { - throw "web_safe needs an argument"; - } - this._web_safe = b; - return this; - }; - - - /* - - distance( FLOAT ) - - 'FLOAT'> must be a value from 0 to 1. You might use this with the "triade" - "tetrade" or "analogic" color schemes. - - The default is 0.5. - */ - - ColorScheme.prototype.distance = function(d) { - if (d == null) { - throw "distance needs an argument"; - } - if (d < 0) { - throw "distance(" + d + ") - argument must be >= 0"; - } - if (d > 1) { - throw "distance(" + d + ") - argument must be <= 1"; - } - this._distance = d; - return this; - }; - - - /* - - scheme( name ) - - 'name' must be a valid color scheme name. See "Color Schemes". The default - is "mono" - */ - - ColorScheme.prototype.scheme = function(name) { - if (name == null) { - return this._scheme; - } else { - if (ColorScheme.SCHEMES[name] == null) { - throw "'" + name + "' isn't a valid scheme name"; - } - this._scheme = name; - return this; - } - }; - - - /* - - variation( name ) - - 'name' must be a valid color variation name. See "Color Variations" - */ - - ColorScheme.prototype.variation = function(v) { - if (v == null) { - throw "variation needs an argument"; - } - if (ColorScheme.PRESETS[v] == null) { - throw "'$v' isn't a valid variation name"; - } - this._set_variant_preset(ColorScheme.PRESETS[v]); - return this; - }; - - ColorScheme.prototype._set_variant_preset = function(p) { - var i, _j, _results; - _results = []; - for (i = _j = 0; _j <= 3; i = ++_j) { - _results.push(this.col[i].set_variant_preset(p)); - } - return _results; - }; - - clone = function(obj) { - var flags, key, newInstance; - if ((obj == null) || typeof obj !== 'object') { - return obj; - } - if (obj instanceof Date) { - return new Date(obj.getTime()); - } - if (obj instanceof RegExp) { - flags = ''; - if (obj.global != null) { - flags += 'g'; - } - if (obj.ignoreCase != null) { - flags += 'i'; - } - if (obj.multiline != null) { - flags += 'm'; - } - if (obj.sticky != null) { - flags += 'y'; - } - return new RegExp(obj.source, flags); - } - newInstance = new obj.constructor(); - for (key in obj) { - newInstance[key] = clone(obj[key]); - } - return newInstance; - }; - - ColorScheme.mutablecolor = (function() { - mutablecolor.prototype.hue = 0; - - mutablecolor.prototype.saturation = []; - - mutablecolor.prototype.value = []; - - mutablecolor.prototype.base_red = 0; - - mutablecolor.prototype.base_green = 0; - - mutablecolor.prototype.base_saturation = 0; - - mutablecolor.prototype.base_value = 0; - - function mutablecolor(hue) { - if (hue == null) { - throw "No hue specified"; - } - this.saturation = []; - this.value = []; - this.base_red = 0; - this.base_green = 0; - this.base_blue = 0; - this.base_saturation = 0; - this.base_value = 0; - this.set_hue(hue); - this.set_variant_preset(ColorScheme.PRESETS['default']); - } - - mutablecolor.prototype.get_hue = function() { - return this.hue; - }; - - mutablecolor.prototype.set_hue = function(h) { - var avrg, color, colorset1, colorset2, d, derivative1, derivative2, en, i, k; - avrg = function(a, b, k) { - return a + Math.round((b - a) * k); - }; - this.hue = Math.round(h % 360); - d = this.hue % 15 + (this.hue - Math.floor(this.hue)); - k = d / 15; - derivative1 = this.hue - Math.floor(d); - derivative2 = (derivative1 + 15) % 360; - colorset1 = ColorScheme.COLOR_WHEEL[derivative1]; - colorset2 = ColorScheme.COLOR_WHEEL[derivative2]; - en = { - red: 0, - green: 1, - blue: 2, - value: 3 - }; - for (color in en) { - i = en[color]; - this["base_" + color] = avrg(colorset1[i], colorset2[i], k); - } - this.base_saturation = avrg(100, 100, k) / 100; - return this.base_value /= 100; - }; - - mutablecolor.prototype.rotate = function(angle) { - var newhue; - newhue = (this.hue + angle) % 360; - return this.set_hue(newhue); - }; - - mutablecolor.prototype.get_saturation = function(variation) { - var s, x; - x = this.saturation[variation]; - s = x < 0 ? -x * this.base_saturation : x; - if (s > 1) { - s = 1; - } - if (s < 0) { - s = 0; - } - return s; - }; - - mutablecolor.prototype.get_value = function(variation) { - var v, x; - x = this.value[variation]; - v = x < 0 ? -x * this.base_value : x; - if (v > 1) { - v = 1; - } - if (v < 0) { - v = 0; - } - return v; - }; - - mutablecolor.prototype.set_variant = function(variation, s, v) { - this.saturation[variation] = s; - return this.value[variation] = v; - }; - - mutablecolor.prototype.set_variant_preset = function(p) { - var i, _j, _results; - _results = []; - for (i = _j = 0; _j <= 3; i = ++_j) { - _results.push(this.set_variant(i, p[2 * i], p[2 * i + 1])); - } - return _results; - }; - - mutablecolor.prototype.get_hex = function(web_safe, variation) { - var c, color, formatted, i, k, max, min, rgb, rgbVal, s, str, v, _j, _k, _len1, _len2, _ref1; - max = Math.max.apply(Math, (function() { - var _j, _len1, _ref1, _results; - _ref1 = ['red', 'green', 'blue']; - _results = []; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - color = _ref1[_j]; - _results.push(this["base_" + color]); - } - return _results; - }).call(this)); - min = Math.min.apply(Math, (function() { - var _j, _len1, _ref1, _results; - _ref1 = ['red', 'green', 'blue']; - _results = []; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - color = _ref1[_j]; - _results.push(this["base_" + color]); - } - return _results; - }).call(this)); - v = (variation < 0 ? this.base_value : this.get_value(variation)) * 255; - s = variation < 0 ? this.base_saturation : this.get_saturation(variation); - k = max > 0 ? v / max : 0; - rgb = []; - _ref1 = ['red', 'green', 'blue']; - for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { - color = _ref1[_j]; - rgbVal = Math.min.apply(Math, [255, Math.round(v - (v - this["base_" + color] * k) * s)]); - rgb.push(rgbVal); - } - if (web_safe) { - rgb = (function() { - var _k, _len2, _results; - _results = []; - for (_k = 0, _len2 = rgb.length; _k < _len2; _k++) { - c = rgb[_k]; - _results.push(Math.round(c / 51) * 51); - } - return _results; - })(); - } - formatted = ""; - for (_k = 0, _len2 = rgb.length; _k < _len2; _k++) { - i = rgb[_k]; - str = i.toString(16); - if (str.length < 2) { - str = "0" + str; - } - formatted += str; - } - return formatted; - }; - - return mutablecolor; - - })(); - - return ColorScheme; - -})(); - -if ((typeof module !== "undefined" && module !== null) && (module.exports != null)) { - module.exports = ColorScheme; -} else { - if (typeof define === 'function' && define.amd) { - define([], function() { - return ColorScheme; - }); - } else { - window.ColorScheme = ColorScheme; - } -} diff --git a/test/test.coffee b/test/test.coffee index a375b43..00977ea 100644 --- a/test/test.coffee +++ b/test/test.coffee @@ -57,6 +57,13 @@ describe 'ColorScheme instance', -> scheme.from_hex('ad1457') ).should.not.Throw() +describe 'from_hex', -> + scheme = new ColorScheme + + it.only 'should select the correct hue', -> + scheme.from_hex('00ff00') + scheme.col[0].hue.should.equal 180 + # scm = new ColorScheme @@ -70,4 +77,4 @@ describe 'ColorScheme instance', -> # # # console.log eyes.inspect(scm) # list = scm.colors() -# console.log list \ No newline at end of file +# console.log list