From 6a532c29fec587fa85406f2c662d004e7467f9e5 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Sat, 18 Jul 2015 10:56:01 +0930 Subject: [PATCH] Add some comments --- framework/core/js/lib/utils/stringToColor.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/core/js/lib/utils/stringToColor.js b/framework/core/js/lib/utils/stringToColor.js index e67614bde..0067ff27c 100644 --- a/framework/core/js/lib/utils/stringToColor.js +++ b/framework/core/js/lib/utils/stringToColor.js @@ -34,12 +34,16 @@ function hsvToRgb(h, s, v) { export default function stringToColor(string) { let num = 0; + // Convert the username into a number based on the ASCII value of each + // character. for (let i = 0; i < string.length; i++) { num += string.charCodeAt(i); } + // Construct a color using the remainder of that number divided by 360, and + // some predefined saturation and value values. const hue = num % 360; const rgb = hsvToRgb(hue / 360, 0.3, 0.9); return '' + rgb.r.toString(16) + rgb.g.toString(16) + rgb.b.toString(16); -}; +}