Skip to content

Instantly share code, notes, and snippets.

@michlbro
Last active February 26, 2023 17:09
Show Gist options
  • Save michlbro/9c145a64930edce11facb390b32b5276 to your computer and use it in GitHub Desktop.
Save michlbro/9c145a64930edce11facb390b32b5276 to your computer and use it in GitHub Desktop.
--[[
31/12/2022
03:17AM
o Created by XxprofessgamerxX cause I am lazy (michlbro#0414)
o Contributions:
capetaanal#1984
]]--
local colourMethods = {}
function colourMethods:ToColour3(): Color3
local r, g, b = self.r / math.ceil(self.r), self.g / math.ceil(self.g), self.b / math.ceil(self.b)
return Color3.new(r, g, b)
end
local function New(r, g, b)
local colourClass = setmetatable({
r = r,
g = g,
b = b
}, {__index = colourMethods, __mul = function(tbl, value)
if type(value) == "number" then
return New(tbl.R * value, tbl.G * value, tbl.B * value)
end
return New(tbl.R * value.R, tbl.G * value.G, tbl.B * value.B)
end, __add = function(tbl, value)
return New(tbl.R + value.R, tbl.G + value.G, tbl.B + value.B)
end, __div = function(tbl, value)
if type(value) == "number" then
return New(tbl.R / value, tbl.G / value, tbl.B / value)
end
return New(tbl.R / value.R, tbl.G / value.G, tbl.B / value.B)
end, __sub = function(tbl, value)
return New(tbl.R + value.R, tbl.G + value.G, tbl.B + value.B)
end, __call = function(self)
local r, g, b = self.r / math.ceil(self.r), self.g / math.ceil(self.g), self.b / math.ceil(self.b)
return Color3.new(r, g, b)
end})
return colourClass
end
local function FromColour3(colour3: Color3)
return New(colour3.R, colour3.G, colour3.B)
end
local function FromRGB(r, g, b)
return New(r / 255, g / 255, b / 255)
end
return setmetatable({New = New, FromColour3 = FromColour3, FromRGB = FromRGB}, {__index = colourMethods})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment