Advertisement
stuppid_bot

Функции для работы с цветом [fixed]

Sep 3rd, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function hexRgb(h) {
  2.     h = h.match(/^#?([\da-f]{3}|[\da-f]{6})$/i);
  3.     if (!h) return null;
  4.     h = h[1];
  5.     h = parseInt(h.length == 3 ? h.replace(/(.)/g, '$1$1') : h, 16);
  6.     return {
  7.         r: h >> 16,
  8.         g: h >> 8 & 0xff,
  9.         b: h & 0xff
  10.     };
  11. }
  12.  
  13. function rgbHex(r, g, b) {
  14.     function h(v) {
  15.         return v &= 0xff, (v < 16 ? '0' : '') + v.toString(16);
  16.     }
  17.     return '#' + h(r) + h(g) + h(b);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement