Advertisement
WishNite

Untitled

Oct 28th, 2020
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. local Color = {};
  2. Color.__index = Color;
  3.  
  4. function Color:toDecimal(Color3Value)
  5. local r,g,b = Color3Value.r, Color3Value.g, Color3Value.b
  6. -- Just a small check to ensure that our r,g,b values are in our 0-255 component range.
  7. if (r < 1 and g < 1 and b < 1) and (r > 0 or g > 0 and b > 0) then
  8. r *= 255
  9. g *= 255
  10. b *= 255
  11. end
  12.  
  13. return r*(256*256)+g*256+b -- 256 is used here because we want to keep the next component from overlapping the previous component.
  14. end
  15.  
  16. function Color:toColor3(Decimal)
  17. local b = Decimal % 256
  18. local g_0 = (Decimal % 65536 - b)
  19. local r_0 = Decimal - g_0 - b
  20. local g = g_0 / 256
  21. local r = r_0 / 65536
  22.  
  23. print(("Conversion: Decimal %q to Color3 R: %q G: %q B: %q"):format(Decimal, r, g, b))
  24.  
  25. return Color3.fromRGB(r,g,b)
  26. end
  27.  
  28. return Color
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement