summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-02-13 12:41:40 -0500
committerJules Laplace <jules@okfoc.us>2015-02-13 12:41:40 -0500
commitd67f7095d4d3f061431d9ec88996cda0e9b00267 (patch)
tree96fc29ba270cd7d0520888360070d7ef428c87cf /js
parent9a525a25fdb43bc1be866d8b4a50afee7b384c59 (diff)
adding hues
Diffstat (limited to 'js')
-rw-r--r--js/color_code.js40
-rw-r--r--js/util.js4
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,
diff --git a/js/util.js b/js/util.js
index 91055f9..81e8f60 100644
--- a/js/util.js
+++ b/js/util.js
@@ -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 ) ) }