diff options
Diffstat (limited to 'js')
| -rw-r--r-- | js/color_code.js | 40 | ||||
| -rw-r--r-- | js/util.js | 4 |
2 files changed, 43 insertions, 1 deletions
diff --git a/js/color_code.js b/js/color_code.js index 55a284f..c8e8b84 100644 --- a/js/color_code.js +++ b/js/color_code.js @@ -18,7 +18,42 @@ var MircColor = (function(){ [127,127,127], [210,210,210] ] - + var HUES = [ + [255,255,255], + [0,0,0], + [0,0,127], + [0,147,0], + [255,0,0], + [127,0,0], + [156,0,156], + [252,127,0], + [255,255,0], + [0,252,0], + [0,147,147], + [0,255,255], + [0,0,252], + [255,0,255], + null, + null, + ] + var GRAYS = [ + [255,255,255], + [0,0,0], + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + null, + [127,127,127], + [210,210,210] + ] function closest_to(pixel){ return COLORS.reduce(function(prev, curr, index) { var d = distance(pixel, curr) @@ -31,6 +66,7 @@ var MircColor = (function(){ } function distance(u, v){ + if (! v) return Math.Infinity var r = u[0] - v[0] var g = u[1] - v[1] var b = u[2] - v[2] @@ -137,6 +173,8 @@ var MircColor = (function(){ return { colors: COLORS, + hues: HUES, + grays: GRAYS, closest_to: closest_to, distance: distance, fromUrl: fromUrl, @@ -115,6 +115,10 @@ function weave(a){ reverse(aa[1]).forEach(function(el){ b.push(el) }) return b } +function cssRule (selector, declaration) { + var x = document.styleSheets, y = x.length-1; + x[y].insertRule(selector+"{"+declaration+"}", x[y].cssRules.length); +} // easing functions function circular (t) { return Math.sqrt( 1 - ( --t * t ) ) } |
