Advertisement
NovaYoshi

really complicated nick colorizer

Oct 27th, 2014
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. function ColorizeNick(Nick) {
  2. local hash1 = api.Num(api.MD5(Nick).slice(0, 8),16);
  3. local hash2 = api.Num(api.MD5(Nick).slice(8, 16),16);
  4. local hash3 = api.Num(api.MD5(Nick).slice(16, 24),16);
  5. local hash4 = api.Num(api.MD5(Nick).slice(24, 32),16);
  6. local hash = abs(hash1+hash2+hash3+hash4)/2;
  7. local sat = 0.8 + abs(hash1.tofloat()/(-1>>>1))*0.2;
  8. local light = 0.4 + abs(hash4.tofloat()/(-1>>>1))*0.2;
  9. local hue = hash.tofloat()/(-1>>>1);
  10. local rgb = HSL2RGB(hue, sat, light);
  11. return format("\x0004%.2x%.2x%.2x%s\x000f", rgb[0], rgb[1], rgb[2], Nick);
  12. }
  13.  
  14. function HSL2RGB(h, s, l) {
  15. // from http://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion
  16. local r, g, b;
  17. if(!s){
  18. r = g = b = l; // achromatic
  19. } else {
  20. function hue2rgb(p, q, t) {
  21. if(t < 0) t++;
  22. if(t > 1) t--;
  23. if(t < 1.0/6) return p + (q - p) * 6.0 * t;
  24. if(t < 1.0/2) return q;
  25. if(t < 2.0/3) return p + (q - p) * (2.0/3 - t) * 6.0;
  26. return p;
  27. }
  28. local q = l < 0.5 ? l * (1.0 + s) : l + s - l * s;
  29. local p = 2.0 * l - q;
  30. r = hue2rgb(p, q, h + 1.0/3);
  31. g = hue2rgb(p, q, h);
  32. b = hue2rgb(p, q, h - 1.0/3);
  33. }
  34. return [(r * 255).tointeger(), (g * 255).tointeger(), (b * 255).tointeger()];
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement