Skip to content

Instantly share code, notes, and snippets.

@dvdfu
Created April 17, 2016 03:01
Show Gist options
  • Save dvdfu/b0b4f9680eccd0276108ac9a18ce9365 to your computer and use it in GitHub Desktop.
Save dvdfu/b0b4f9680eccd0276108ac9a18ce9365 to your computer and use it in GitHub Desktop.
local RGBColor = {}
local function lerp(a, b, x)
if x > 1 then x = 1 end
if x < 0 then x = 0 end
return a + (b-a) * x
end
function RGBColor.new(r, g, b)
return {
r = r,
g = g,
b = b
}
end
function RGBColor.blend(colorA, colorB, mix)
return {
r = lerp(colorA.r, colorB.r, mix),
g = lerp(colorA.g, colorB.g, mix),
b = lerp(colorA.b, colorB.b, mix)
}
end
function RGBColor.get(color)
return color.r, color.g, color.b
end
return RGBColor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment