daily pastebin goal
58%
SHARE
TWEET

Untitled

a guest Jan 15th, 2013 172 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function rgbToHex( %rgb )
  2. {
  3.         %r = _compToHex( 255 * getWord( %rgb, 0 ) );
  4.         %g = _compToHex( 255 * getWord( %rgb, 0 ) );
  5.         %b = _compToHex( 255 * getWord( %rgb, 0 ) );
  6.  
  7.         return %r @ %g @ %b;
  8. }
  9.  
  10. function hexToRgb( %rgb )
  11. {
  12.         %r = _hexToComp( getSubStr( %rgb, 0, 2 ) ) / 255;
  13.         %g = _hexToComp( getSubStr( %rgb, 2, 2 ) ) / 255;
  14.         %b = _hexToComp( getSubStr( %rgb, 4, 2 ) ) / 255;
  15.  
  16.         return %r SPC %g SPC %b;
  17. }
  18.  
  19. function _compToHex( %comp )
  20. {
  21.         %left = mFloor( %comp / 16 );
  22.         %comp = mFloor( %comp - %left * 16 );
  23.  
  24.         %left = getSubStr( "0123456789ABCDEF", %left, 1 );
  25.         %comp = getSubStr( "0123456789ABCDEF", %comp, 1 );
  26.  
  27.         return %left @ %comp;
  28. }
  29.  
  30. function _hexToComp( %hex )
  31. {
  32.         %left = getSubStr( %hex, 0 );
  33.         %comp = getSubStr( %hex, 1 );
  34.  
  35.         %left = striPos( "0123456789ABCDEF", %left );
  36.         %comp = striPos( "0123456789ABCDEF", %comp );
  37.  
  38.         if ( %left < 0 || %comp < 0 )
  39.         {
  40.                 return 0;
  41.         }
  42.  
  43.         return %left * 16 + %comp;
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top