Advertisement
raphael76280

Untitled

Apr 11th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. function application:rgbToHex(rgb)
  2. local hexadecimal = '0X'
  3.  
  4. for key, value in pairs(rgb) do
  5. local hex = ''
  6.  
  7. while(value > 0)do
  8. local index = math.fmod(value, 16) + 1
  9. value = math.floor(value / 16)
  10. hex = string.sub('0123456789ABCDEF', index, index) .. hex
  11. end
  12.  
  13. if(string.len(hex) == 0)then
  14. hex = '00'
  15.  
  16. elseif(string.len(hex) == 1)then
  17. hex = '0' .. hex
  18. end
  19.  
  20. hexadecimal = hexadecimal .. hex
  21. end
  22.  
  23. return hexadecimal
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement