From 1eaf5ae82a5202707c2f71bf32a5253214a35806 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 19 Jun 2015 10:37:57 -0700 Subject: [PATCH 1/3] fixed utilities file to be able to be referenced by other files --- examples/utilities.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/utilities.js b/examples/utilities.js index 3844e23e14..3c2423c914 100644 --- a/examples/utilities.js +++ b/examples/utilities.js @@ -9,7 +9,13 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -function hslToRgb(hslColor) { +////***************** UTILITIES ************************************* + +map = function(value, min1, max1, min2, max2) { + return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); +} + +hslToRgb = function (hslColor) { var h = hslColor.hue; var s = hslColor.sat; var l = hslColor.light; @@ -42,15 +48,13 @@ function hslToRgb(hslColor) { } -function map(value, min1, max1, min2, max2) { - return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); -} -function randFloat(low, high) { + +randFloat = function(low, high) { return low + Math.random() * (high - low); } -function randInt(low, high) { +randInt = function(low, high) { return Math.floor(randFloat(low, high)); } \ No newline at end of file From 18014e968df0f19b69dd862e83d24bb505844ea5 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 19 Jun 2015 19:00:42 -0700 Subject: [PATCH 2/3] removed horizontal "line break" style comment blocks --- examples/utilities.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/utilities.js b/examples/utilities.js index 3c2423c914..b60576b23e 100644 --- a/examples/utilities.js +++ b/examples/utilities.js @@ -9,13 +9,13 @@ // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -////***************** UTILITIES ************************************* + map = function(value, min1, max1, min2, max2) { return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); } -hslToRgb = function (hslColor) { +hslToRgb = function(hslColor) { var h = hslColor.hue; var s = hslColor.sat; var l = hslColor.light; From 8fcff2d64875f766e1306ba454324cd069ddcdb2 Mon Sep 17 00:00:00 2001 From: ericrius1 Date: Fri, 19 Jun 2015 19:03:47 -0700 Subject: [PATCH 3/3] changed indent spacing to 4 spaces --- examples/utilities.js | 58 +++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/examples/utilities.js b/examples/utilities.js index b60576b23e..85e27079a8 100644 --- a/examples/utilities.js +++ b/examples/utilities.js @@ -12,49 +12,49 @@ map = function(value, min1, max1, min2, max2) { - return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); + return min2 + (max2 - min2) * ((value - min1) / (max1 - min1)); } hslToRgb = function(hslColor) { - var h = hslColor.hue; - var s = hslColor.sat; - var l = hslColor.light; - var r, g, b; + var h = hslColor.hue; + var s = hslColor.sat; + var l = hslColor.light; + var r, g, b; - if (s == 0) { - r = g = b = l; // achromatic - } else { - var hue2rgb = function hue2rgb(p, q, t) { - if (t < 0) t += 1; - if (t > 1) t -= 1; - if (t < 1 / 6) return p + (q - p) * 6 * t; - if (t < 1 / 2) return q; - if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6; - return p; + if (s == 0) { + r = g = b = l; // achromatic + } else { + var hue2rgb = function hue2rgb(p, q, t) { + if (t < 0) t += 1; + if (t > 1) t -= 1; + if (t < 1 / 6) return p + (q - p) * 6 * t; + if (t < 1 / 2) return q; + if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6; + return p; + } + + var q = l < 0.5 ? l * (1 + s) : l + s - l * s; + var p = 2 * l - q; + r = hue2rgb(p, q, h + 1 / 3); + g = hue2rgb(p, q, h); + b = hue2rgb(p, q, h - 1 / 3); } - var q = l < 0.5 ? l * (1 + s) : l + s - l * s; - var p = 2 * l - q; - r = hue2rgb(p, q, h + 1 / 3); - g = hue2rgb(p, q, h); - b = hue2rgb(p, q, h - 1 / 3); - } - - return { - red: Math.round(r * 255), - green: Math.round(g * 255), - blue: Math.round(b * 255) - }; + return { + red: Math.round(r * 255), + green: Math.round(g * 255), + blue: Math.round(b * 255) + }; } randFloat = function(low, high) { - return low + Math.random() * (high - low); + return low + Math.random() * (high - low); } randInt = function(low, high) { - return Math.floor(randFloat(low, high)); + return Math.floor(randFloat(low, high)); } \ No newline at end of file