mirror of
https://github.com/flarum/framework.git
synced 2025-03-04 09:43:28 +08:00
Add some comments
This commit is contained in:
parent
9db026de95
commit
6a532c29fe
@ -34,12 +34,16 @@ function hsvToRgb(h, s, v) {
|
|||||||
export default function stringToColor(string) {
|
export default function stringToColor(string) {
|
||||||
let num = 0;
|
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++) {
|
for (let i = 0; i < string.length; i++) {
|
||||||
num += string.charCodeAt(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 hue = num % 360;
|
||||||
const rgb = hsvToRgb(hue / 360, 0.3, 0.9);
|
const rgb = hsvToRgb(hue / 360, 0.3, 0.9);
|
||||||
|
|
||||||
return '' + rgb.r.toString(16) + rgb.g.toString(16) + rgb.b.toString(16);
|
return '' + rgb.r.toString(16) + rgb.g.toString(16) + rgb.b.toString(16);
|
||||||
};
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user