Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Color3 = {__type = 'Color3'};
- _G.Color3 = Color3
- function Color3.new(r, g, b)
- local self = setmetatable({}, Color3)
- self.r = r or 0
- self.g = g or 0
- self.b = b or 0
- function self:lerp(e, a)
- local function lerp(s, e, a)
- return s + (e - s) * a
- end
- return Color3.new(
- lerp(self.r, e.r, a),
- lerp(self.g, e.g, a),
- lerp(self.b, e.b, a)
- )
- end
- return self
- end
- function Color3.fromRGB(r, g, b)
- local self = setmetatable({}, Color3)
- self.r = r/255
- self.g = g/255
- self.b = b/255
- function self:lerp(c, a)
- local function lerp(s, e, a)
- return s + (e - s) * a
- end
- return Color3.new(
- lerp(self.r, c.r, a),
- lerp(self.g, c.g, a),
- lerp(self.b, c.b, a)
- )
- end
- return self
- end
- function Color3.fromHEX(hex)
- local function hex2rgb(hex)
- hex = hex:gsub("#","")
- return tonumber("0x"..hex:sub(1,2)),tonumber("0x"..hex:sub(3,4)),tonumber("0x"..hex:sub(5,6))
- end
- local r, g, b = hex2rgb(hex)
- return Color3.new(r/255, g/255, b/255)
- end
- function Color3:__tostring()
- return self.r .. ', ' .. self.g.. ', ' .. self.b
- end
- function Color3:__add(c)
- return Color3.new(
- self.r + c.r,
- self.g + c.g,
- self.b + c.b
- )
- end
- function Color3:__sub(c)
- return Color3.new(
- self.r - c.r,
- self.g - c.g,
- self.b - c.b
- )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement