From 42923bedf18451ef2454455a63890ba5c80c0f57 Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 25 May 2012 09:35:20 +0200 Subject: [PATCH] rename vars; add tests --- source/Ox/js/Color.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/source/Ox/js/Color.js b/source/Ox/js/Color.js index 3a2471de..de0bb5e4 100644 --- a/source/Ox/js/Color.js +++ b/source/Ox/js/Color.js @@ -16,15 +16,15 @@ Ox.hsl Takes RGB values and returns HSL values [120, 1, 0.5] @*/ Ox.hsl = function(rgb) { + var hsl = [0, 0, 0], max, min; if (arguments.length == 3) { rgb = Ox.toArray(arguments); } - rgb = Ox.clone(rgb).map(function(val) { - return val / 255; + rgb = Ox.clone(rgb).map(function(value) { + return value / 255; }); - var max = Ox.max(rgb), - min = Ox.min(rgb), - hsl = [0, 0, 0]; + max = Ox.max(rgb); + min = Ox.min(rgb); hsl[2] = 0.5 * (max + min); if (max == min) { hsl[0] = 0; @@ -63,13 +63,12 @@ Ox.rgb Takes HSL values and returns RGB values @*/ Ox.rgb = function(hsl) { + var rgb = [0, 0, 0], v1, v2, v3; if (arguments.length == 3) { hsl = Ox.toArray(arguments); } hsl = Ox.clone(hsl); hsl[0] /= 360; - var rgb = [0, 0, 0], - v1, v2, v3; if (hsl[1] == 0) { rgb = [hsl[2], hsl[2], hsl[2]]; } else { @@ -97,25 +96,29 @@ Ox.rgb = function(hsl) { } }); } - return rgb.map(function(v) { - return v * 255; + return rgb.map(function(value) { + return value * 255; }); }; /*@ Ox.toHex Format RGB array as hex value + > Ox.toHex([192, 128, 64]) + 'C08040' @*/ Ox.toHex = function(rgb) { - return rgb.map(function(val) { - return Ox.pad(val.toString(16).toUpperCase(), 2); + return rgb.map(function(value) { + return Ox.pad(value.toString(16).toUpperCase(), 2); }).join(''); }; /*@ Ox.toRGB Format hex value as RGB array + > Ox.toRGB('C08040') + [192, 128, 64] @*/ Ox.toRGB = function(hex) { - return Ox.range(3).map(function(i) { - return parseInt(hex.substr(i * 2, 2), 16); + return Ox.range(3).map(function(index) { + return parseInt(hex.substr(index * 2, 2), 16); }); };