Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Color = {};
- Color.__index = Color;
- function Color:toDecimal(Color3Value)
- local r,g,b = Color3Value.r, Color3Value.g, Color3Value.b
- -- Just a small check to ensure that our r,g,b values are in our 0-255 component range.
- if (r < 1 and g < 1 and b < 1) and (r > 0 or g > 0 and b > 0) then
- r *= 255
- g *= 255
- b *= 255
- end
- return r*(256*256)+g*256+b -- 256 is used here because we want to keep the next component from overlapping the previous component.
- end
- function Color:toColor3(Decimal)
- local b = Decimal % 256
- local g_0 = (Decimal % 65536 - b)
- local r_0 = Decimal - g_0 - b
- local g = g_0 / 256
- local r = r_0 / 65536
- print(("Conversion: Decimal %q to Color3 R: %q G: %q B: %q"):format(Decimal, r, g, b))
- return Color3.fromRGB(r,g,b)
- end
- return Color
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement