💄 Chat > Improve colors
This commit is contained in:
+58
-4
@@ -153,14 +153,68 @@ class Chat
|
|||||||
|
|
||||||
getRandomColor()
|
getRandomColor()
|
||||||
{
|
{
|
||||||
const r = (Math.round(Math.random() * 127) + 127).toString(16)
|
const rgb = this.hslToRgb(Math.random(), 0.5, 0.5)
|
||||||
const g = (Math.round(Math.random() * 127) + 127).toString(16)
|
|
||||||
const b = (Math.round(Math.random() * 127) + 127).toString(16)
|
rgb[0] = Math.round(rgb[0] * 0.7 + 255 * 0.3).toString(16)
|
||||||
const color = '#' + r + g + b
|
rgb[1] = Math.round(rgb[1] * 0.7 + 255 * 0.3).toString(16)
|
||||||
|
rgb[2] = Math.round(rgb[2] * 0.7 + 255 * 0.3).toString(16)
|
||||||
|
|
||||||
|
const color = `#${rgb[0]}${rgb[1]}${rgb[2]}`
|
||||||
|
|
||||||
return color
|
return color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hslToRgb(h, s, l)
|
||||||
|
{
|
||||||
|
let r
|
||||||
|
let g
|
||||||
|
let b
|
||||||
|
|
||||||
|
if(s === 0)
|
||||||
|
{
|
||||||
|
r = g = b = l
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const hue2rgb = function hue2rgb(_p, _q, _t)
|
||||||
|
{
|
||||||
|
let t = _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
|
||||||
|
}
|
||||||
|
|
||||||
|
const q = l < 0.5 ? l * (1 + s) : l + s - l * s
|
||||||
|
const p = 2 * l - q
|
||||||
|
|
||||||
|
r = hue2rgb(p, q, h + 1 / 3)
|
||||||
|
g = hue2rgb(p, q, h)
|
||||||
|
b = hue2rgb(p, q, h - 1 / 3)
|
||||||
|
}
|
||||||
|
|
||||||
|
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)]
|
||||||
|
}
|
||||||
|
|
||||||
getRandomName()
|
getRandomName()
|
||||||
{
|
{
|
||||||
// Refill robot names if no more name available
|
// Refill robot names if no more name available
|
||||||
|
|||||||
Reference in New Issue
Block a user