Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ColorizeNick(Nick) {
- local hash1 = api.Num(api.MD5(Nick).slice(0, 8),16);
- local hash2 = api.Num(api.MD5(Nick).slice(8, 16),16);
- local hash3 = api.Num(api.MD5(Nick).slice(16, 24),16);
- local hash4 = api.Num(api.MD5(Nick).slice(24, 32),16);
- local hash = abs(hash1+hash2+hash3+hash4)/2;
- local sat = 0.8 + abs(hash1.tofloat()/(-1>>>1))*0.2;
- local light = 0.4 + abs(hash4.tofloat()/(-1>>>1))*0.2;
- local hue = hash.tofloat()/(-1>>>1);
- local rgb = HSL2RGB(hue, sat, light);
- return format("\x0004%.2x%.2x%.2x%s\x000f", rgb[0], rgb[1], rgb[2], Nick);
- }
- function HSL2RGB(h, s, l) {
- // from http://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion
- local r, g, b;
- if(!s){
- r = g = b = l; // achromatic
- } else {
- function hue2rgb(p, q, t) {
- if(t < 0) t++;
- if(t > 1) t--;
- if(t < 1.0/6) return p + (q - p) * 6.0 * t;
- if(t < 1.0/2) return q;
- if(t < 2.0/3) return p + (q - p) * (2.0/3 - t) * 6.0;
- return p;
- }
- local q = l < 0.5 ? l * (1.0 + s) : l + s - l * s;
- local p = 2.0 * l - q;
- r = hue2rgb(p, q, h + 1.0/3);
- g = hue2rgb(p, q, h);
- b = hue2rgb(p, q, h - 1.0/3);
- }
- return [(r * 255).tointeger(), (g * 255).tointeger(), (b * 255).tointeger()];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement